Transparent indexing for TCMatrix
Former-commit-id: 8fa13d88fa4fba4a8114fb3ffe7be1189d5d4453
This commit is contained in:
parent
b148f4a527
commit
a5924cf548
|
@ -1076,11 +1076,12 @@ cdef class CTMatrix: # N.B. there is another type called TMatrix in tmatrices.py
|
||||||
cdef qpms_tmatrix_t t
|
cdef qpms_tmatrix_t t
|
||||||
|
|
||||||
def __cinit__(CTMatrix self, BaseSpec spec, matrix):
|
def __cinit__(CTMatrix self, BaseSpec spec, matrix):
|
||||||
self.t.spec = spec.rawpointer();
|
self.spec = spec
|
||||||
|
self.t.spec = self.spec.rawpointer();
|
||||||
# The following will raise an exception if shape is wrong
|
# The following will raise an exception if shape is wrong
|
||||||
self.m = np.array(matrix, dtype=complex, copy=True, order='C').reshape((len(spec), len(spec)))
|
self.m = np.array(matrix, dtype=complex, copy=True, order='C').reshape((len(spec), len(spec)))
|
||||||
self.m.setflags(write=False) # checkme
|
#self.m.setflags(write=False) # checkme
|
||||||
cdef const cdouble[:,:] m_memview = self.m
|
cdef cdouble[:,:] m_memview = self.m
|
||||||
self.t.m = &(m_memview[0,0])
|
self.t.m = &(m_memview[0,0])
|
||||||
self.t.owns_m = False # Memory in self.t.m is "owned" by self.m, not by self.t...
|
self.t.owns_m = False # Memory in self.t.m is "owned" by self.m, not by self.t...
|
||||||
|
|
||||||
|
@ -1090,7 +1091,15 @@ cdef class CTMatrix: # N.B. there is another type called TMatrix in tmatrices.py
|
||||||
'''
|
'''
|
||||||
return &(self.t)
|
return &(self.t)
|
||||||
|
|
||||||
def as_array(CTMatrix self):
|
# Transparent access to the T-matrix elements.
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return self.m[key]
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
self.m[key] = value
|
||||||
|
|
||||||
|
def as_ndarray(CTMatrix self):
|
||||||
|
''' Returns a copy of the T-matrix as a numpy array.'''
|
||||||
|
# Maybe not totally needed after all, as np.array(T[...]) should be equivalent and not longer
|
||||||
return np.array(self.m, copy=True)
|
return np.array(self.m, copy=True)
|
||||||
|
|
||||||
cdef class FinitePointGroup:
|
cdef class FinitePointGroup:
|
||||||
|
|
Loading…
Reference in New Issue