From cf502656f8b9a20a70a33380ffa1a577ad6c7b6e Mon Sep 17 00:00:00 2001 From: Alexander Condello Date: Mon, 20 Jun 2022 17:27:40 -0700 Subject: [PATCH] Expose C++ QuadraticModelBase::energy() to Cython level --- dimod/include/dimod/quadratic_model.h | 4 ++-- dimod/libcpp.pxd | 2 ++ releasenotes/notes/cppbqm-energy-d8bf4cd3632b2c0c.yaml | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/cppbqm-energy-d8bf4cd3632b2c0c.yaml diff --git a/dimod/include/dimod/quadratic_model.h b/dimod/include/dimod/quadratic_model.h index f76f87e65..f5ec973ab 100644 --- a/dimod/include/dimod/quadratic_model.h +++ b/dimod/include/dimod/quadratic_model.h @@ -423,7 +423,7 @@ class QuadraticModelBase { * `num_variables()` long. */ template // todo: allow different return types - bias_type energy(Iter sample_start) { + bias_type energy(Iter sample_start) const { bias_type en = offset(); for (index_type u = 0; u < static_cast(num_variables()); ++u) { @@ -451,7 +451,7 @@ class QuadraticModelBase { * `num_variables()` long. */ template - bias_type energy(const std::vector& sample) { + bias_type energy(const std::vector& sample) const { // todo: check length? return energy(sample.cbegin()); } diff --git a/dimod/libcpp.pxd b/dimod/libcpp.pxd index 44de64c37..c47d05648 100644 --- a/dimod/libcpp.pxd +++ b/dimod/libcpp.pxd @@ -88,6 +88,7 @@ cdef extern from "dimod/quadratic_model.h" namespace "dimod" nogil: const_quadratic_iterator cbegin_quadratic() const_quadratic_iterator cend_quadratic() void change_vartype(cppVartype) + bias_type energy[Iter](Iter sample_start) bint is_linear() bias_type& linear(index_type) const bias_type lower_bound(index_type) @@ -140,6 +141,7 @@ cdef extern from "dimod/quadratic_model.h" namespace "dimod" nogil: const_quadratic_iterator cbegin_quadratic() void change_vartype(cppVartype, index_type) except + const_quadratic_iterator cend_quadratic() + bias_type energy[Iter](Iter sample_start) bint is_linear() bias_type& linear(index_type) const bias_type& lower_bound(index_type) diff --git a/releasenotes/notes/cppbqm-energy-d8bf4cd3632b2c0c.yaml b/releasenotes/notes/cppbqm-energy-d8bf4cd3632b2c0c.yaml new file mode 100644 index 000000000..d4eacde1f --- /dev/null +++ b/releasenotes/notes/cppbqm-energy-d8bf4cd3632b2c0c.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``dimod::QuadraticModelBase::energy()`` method to ``dimod/libcpp.pxd`` + for Cython access.