Commit 75852675 authored by Joseph Weston's avatar Joseph Weston

apply 'binding' compiler directive to hamiltonian_submatrix

This means we don't need to create a dummy class that implements
__get__ just so we can use hamiltonian_submatrix as a method.
parent cf77f221
Pipeline #15416 passed with stages
in 43 minutes and 12 seconds
......@@ -253,6 +253,7 @@ def _check_parameters_match(expected_parameters, params):
raise TypeError(''.join(msg))
def hamiltonian_submatrix(self, args=(), to_sites=None, from_sites=None,
sparse=False, return_norb=False, *, params=None):
......@@ -363,13 +364,3 @@ def hamiltonian_submatrix(self, args=(), to_sites=None, from_sites=None,
mat = func(ham, args, params, self.graph, diag, from_sites,
n_by_to_site, to_norb, to_off, from_norb, from_off)
return (mat, to_norb, from_norb) if return_norb else mat
# workaround for Cython functions not having __get__ and
# Python 3 getting rid of unbound methods
cdef class HamiltonianSubmatrix:
def __get__(self, obj, objtype):
if obj is None:
return hamiltonian_submatrix
return types.MethodType(hamiltonian_submatrix, obj)
......@@ -85,7 +85,7 @@ class System(metaclass=abc.ABCMeta):
# Add a C-implemented function as an unbound method to class System.
System.hamiltonian_submatrix = _system.HamiltonianSubmatrix()
System.hamiltonian_submatrix = _system.hamiltonian_submatrix
class FiniteSystem(System, metaclass=abc.ABCMeta):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment