Skip to content

Commit

Permalink
re-wrote Frame as a ndarray subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenovic committed Oct 19, 2016
1 parent 30c2786 commit 70a4aab
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions clifford/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ def randomRotor(self):
def basis_vectors(self, **kw):
return basis_vectors(self, **kw)

@property
def blades(self):
return self.bases()

def bases(self,*args, **kw):
'''
Returns a dictionary mapping basis element names to their MultiVector
Expand Down Expand Up @@ -1636,44 +1640,27 @@ def meet(self, other, subspace=None):

return (self * subspace.inv()) | other

class Frame(MutableSequence):
'''
A vector frame
'''
def __init__(self, vectors):

self.vecs = vectors

def __iter__(self):
return iter(self.vecs)

def __getitem__(self,key):
return self.vecs.__getitem__(key)

def __setitem__(self,key,value):
return self.vecs.__setitem__(key,value)

def __delitem__(self,key):
return self.vecs.__delitem__(key)
class Frame(np.ndarray):

def __new__(cls, input_array):
#obj = np.asarray(input_array).view(cls)
obj = np.empty(len(input_array), dtype=object)
obj[:] = input_array
obj = obj.view(cls)
return obj

def __array_finalize__(self, obj):
if obj is None: return

def __len__(self):
return len(self.vecs)

def __repr__(self):
return self.vecs.__repr__()

def insert(self,i,x):
return self.vecs.insert(i,x)

@property
def En(self):
'''
Volume element for this frame
En = e1^e2^...^en
'''
return reduce(op,self.vecs)
return reduce(op,self)

@property
def inv(self):
'''
Expand All @@ -1683,13 +1670,13 @@ def inv(self):
---------
inv : `clifford.Frame`
'''
v = self.vecs

En = self.En
# see D&L sec 4.3
vectors = [(-1)**(k)*reduce(op,(v[:k]+v[k+1:]))*En.inv() \
vectors = [(-1)**(k)*reduce(op,np.hstack([self[:k],self[k+1:]]))*En.inv() \
for k in range(len(self))]

return Frame(vectors=vectors)
return Frame(vectors)

def is_innermorphic_to(self,other):
'''
Expand All @@ -1713,8 +1700,8 @@ def is_innermorphic_to(self,other):
pairs = list(itertools.combinations(range(len(self)), 2))
a,b = self,other
return array([(b[m]|b[n]==a[m]|a[n]) for m,n in pairs]).all()




def comb(n, k):
Expand Down

0 comments on commit 70a4aab

Please sign in to comment.