Skip to content

Commit

Permalink
Matrix fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thisrod committed Oct 11, 2011
1 parent 1e715ec commit e3f1d96
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ndmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ def __eq__(self, other):
def __mul__(self, other):
"""Shapes go as [i, j, ..., n, m, ...] * [n, m, ..., p, q, ...] = [i, j, ..., p, q, ...]"""

n = len(self.elements.shape)
return ndmat(tensordot(self.elements, other.elements, (range(n/2, n), range(n/2))))
if isinstance(other, ndmat):
n = len(self.elements.shape)
return ndmat(tensordot(self.elements, other.elements, (range(n/2, n), range(n/2))))
else:
return self.elements * other

# There follows a bunch of boilerplate to proxy for elements,
# because Smalltalk 80 is still in the future of Python 2010.
# because Smalltalk 80 is still in the future of Python 2011.

def __rmul__(self, other):
return other * self.elements

def __add__(self, other):
return ndmat(self.elements + other.elements)
Expand Down

0 comments on commit e3f1d96

Please sign in to comment.