Permalink
Browse files

Matrix fixes

  • Loading branch information...
1 parent 1e715ec commit e3f1d967b4b7a91d9ee21ed3e18b6f4a8630d257 @thisrod committed Oct 11, 2011
Showing with 9 additions and 3 deletions.
  1. +9 −3 ndmat.py
View
@@ -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)

0 comments on commit e3f1d96

Please sign in to comment.