Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose C++ QuadraticModelBase::energy() to Cython level #1210

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.