Skip to content

Commit

Permalink
Expose C++ QuadraticModelBase::energy() to Cython level
Browse files Browse the repository at this point in the history
  • Loading branch information
arcondello committed Jun 21, 2022
1 parent 6ee9013 commit cf50265
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dimod/include/dimod/quadratic_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class QuadraticModelBase {
* `num_variables()` long.
*/
template <class Iter> // 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<index_type>(num_variables()); ++u) {
Expand Down Expand Up @@ -451,7 +451,7 @@ class QuadraticModelBase {
* `num_variables()` long.
*/
template <class T>
bias_type energy(const std::vector<T>& sample) {
bias_type energy(const std::vector<T>& sample) const {
// todo: check length?
return energy(sample.cbegin());
}
Expand Down
2 changes: 2 additions & 0 deletions dimod/libcpp.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/cppbqm-energy-d8bf4cd3632b2c0c.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
Add ``dimod::QuadraticModelBase::energy()`` method to ``dimod/libcpp.pxd``
for Cython access.

0 comments on commit cf50265

Please sign in to comment.