BaseSpec __eq__() and __hash__()

Former-commit-id: da4245315207dc75a70ca6a036fb8be17e243bf9
This commit is contained in:
Marek Nečada 2020-04-07 19:32:58 +03:00
parent 3458acca16
commit ba06abe13f
3 changed files with 8 additions and 0 deletions

View File

@ -83,6 +83,12 @@ cdef class BaseSpec:
raise ValueError # If this happens, it's probably a bug, as it should have failed already at qpms_uvswfi2tmn
self.s.lMax = max(self.s.lMax, l)
def __eq__(self, BaseSpec other):
return bool(qpms_vswf_set_spec_isidentical(&self.s, &other.s))
def __hash__(self): # Very inefficient implementation, but this is not to be used very often
return hash((self.s.norm, self.s.n, tuple(self.__ilist[:self.s.n])))
def tlm(self):
cdef const qpms_uvswfi_t[:] ilist_memview = <qpms_uvswfi_t[:self.s.n]> self.s.ilist
#cdef qpms_vswf_type_t[:] t = np.empty(shape=(self.s.n,), dtype=qpms_vswf_type_t) # does not work, workaround:

View File

@ -172,6 +172,7 @@ ctypedef union qpms_incfield_planewave_params_E:
csphvec_t sph
cdef extern from "vswf.h":
bint qpms_vswf_set_spec_isidentical(const qpms_vswf_set_spec_t *a, const qpms_vswf_set_spec_t *b)
ctypedef qpms_errno_t (*qpms_incfield_t)(cdouble *target, const qpms_vswf_set_spec_t *bspec,
const cart3_t evalpoint, const void *args, bint add)
ctypedef struct qpms_incfield_planewave_params_t:

View File

@ -55,6 +55,7 @@ qpms_errno_t qpms_vswf_set_spec_append(qpms_vswf_set_spec_t *s, const qpms_uvswf
bool qpms_vswf_set_spec_isidentical(const qpms_vswf_set_spec_t *a,
const qpms_vswf_set_spec_t *b) {
if (a == b) return true;
if (a->norm != b->norm) return false;
if (a->n != b->n) return false;
for (size_t i = 0; i < a->n; ++i)
if (a->ilist[i] != b->ilist[i])