Skip to content

Commit

Permalink
Create a new base class for Cython quadratic models
Browse files Browse the repository at this point in the history
  • Loading branch information
arcondello committed Oct 3, 2022
1 parent 268c65e commit 0024935
Show file tree
Hide file tree
Showing 22 changed files with 510 additions and 694 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ dimod/binary/*.cpp
dimod/binary/*.html
dimod/binary/cybqm/*.cpp
dimod/binary/cybqm/*.html
dimod/cyqmbase/*.cpp
dimod/cyqmbase/*.html
dimod/discrete/*.cpp
dimod/discrete/*.html
dimod/quadratic/cyqm/*.cpp
Expand Down
3 changes: 1 addition & 2 deletions dimod/binary/cybqm/cybqm_float32.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

cimport numpy as np

ctypedef np.float32_t bias_type
ctypedef np.int32_t index_type
from dimod.cyqmbase.cyqmbase_float32 cimport cyQMBase_float32 as cyQMBase, bias_type, index_type

__all__ = ['cyBQM_float32']

Expand Down
3 changes: 1 addition & 2 deletions dimod/binary/cybqm/cybqm_float64.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

cimport numpy as np

ctypedef np.float64_t bias_type
ctypedef np.int32_t index_type
from dimod.cyqmbase.cyqmbase_float64 cimport cyQMBase_float64 as cyQMBase, bias_type, index_type

__all__ = ['cyBQM_float64']

Expand Down
16 changes: 2 additions & 14 deletions dimod/binary/cybqm/cybqm_template.pxd.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,20 @@

cimport cython

from dimod.binary.cybqm.base cimport cyBQMBase
from dimod.cyvariables cimport cyVariables
from dimod.cyutilities cimport ConstNumeric
from dimod.libcpp.binary_quadratic_model cimport BinaryQuadraticModel as cppBinaryQuadraticModel


cdef class cyBQM_template(cyBQMBase):
cdef cppBinaryQuadraticModel[bias_type, index_type] cppbqm

cdef readonly object dtype
cdef readonly object index_dtype
cdef readonly cyVariables variables
cdef class cyBQM_template(cyQMBase):
cdef cppBinaryQuadraticModel[bias_type, index_type]* cppbqm

# developer note: we mostly use Py_ssize_t rather than size_t
# since python does not really have an unsigned integer type that it
# likes to use

cdef np.float64_t[::1] _energies(self, ConstNumeric[:, ::1] samples, cyVariables labels)
cdef Py_ssize_t _index(self, object, bint permissive=*) except -1
cpdef Py_ssize_t add_linear_from_array(self, ConstNumeric[:] linear) except -1
cpdef Py_ssize_t add_quadratic_from_dense(self, ConstNumeric[:, ::1] quadratic) except -1
cpdef Py_ssize_t change_vartype(self, object) except -1
cdef const cppBinaryQuadraticModel[bias_type, index_type]* data(self)
cpdef bint is_linear(self)
cpdef Py_ssize_t nbytes(self, bint capacity=*)
cpdef Py_ssize_t num_interactions(self)
cpdef Py_ssize_t num_variables(self)
cpdef Py_ssize_t resize(self, Py_ssize_t) except? 0
cpdef void scale(self, bias_type)
Loading

0 comments on commit 0024935

Please sign in to comment.