Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Matrix fixes

  • Loading branch information...
commit e3f1d967b4b7a91d9ee21ed3e18b6f4a8630d257 1 parent 1e715ec
@thisrod authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 ndmat.py
View
12 ndmat.py
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.