Status: New
Owner: ----
Labels: Type-Defect Priority-Medium Matrices
New issue 4089 by [email protected]: Matrix object does not accept
being summed when inside a list and using built-in sum()
http://code.google.com/p/sympy/issues/detail?id=4089
given:
from sympy.abc import x, y
from sympy import Matrix
s = [Matrix([[x**2]]), Matrix([[x*y]]), Matrix([[x*y**2]])]
works:
sum([x**2, x*y, x*y**2])
works:
s[0] + s[1] + s[2]
does not work:
sum(s)
A workaround is:
sum(map(sum, s))
But the result will not be a "MutableDenseMatrix" object.
Is this the expected behavior?
The traceback that comes with the error is:
--------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-14-4c1cdc765951> in <module>()
----> 1 sum(s)
C:\clones\sympy\sympy\core\decorators.pyc in binary_op_wrapper(self, other)
116 else:
117 return f(self)
--> 118 return func(self, other)
119 return binary_op_wrapper
120 return priority_decorator
C:\clones\sympy\sympy\matrices\dense.pyc in __radd__(self, other)
543 @call_highest_priority('__add__')
544 def __radd__(self, other):
--> 545 return super(DenseMatrix, self).__radd__(_force_mutable(oth
er))
546
547 @call_highest_priority('__rsub__')
C:\clones\sympy\sympy\matrices\matrices.pyc in __radd__(self, other)
579
580 def __radd__(self, other):
--> 581 return self + other
582
583 def __div__(self, other):
C:\clones\sympy\sympy\core\decorators.pyc in binary_op_wrapper(self, other)
116 else:
117 return f(self)
--> 118 return func(self, other)
119 return binary_op_wrapper
120 return priority_decorator
C:\clones\sympy\sympy\matrices\dense.pyc in __add__(self, other)
539 @call_highest_priority('__radd__')
540 def __add__(self, other):
--> 541 return super(DenseMatrix, self).__add__(_force_mutable(othe
r))
542
543 @call_highest_priority('__add__')
C:\clones\sympy\sympy\matrices\matrices.pyc in __add__(self, other)
576 ret[i] = list(map(lambda j, k: j + k, alst[i], blst
[i]))
577 return classof(A, B)._new(ret)
--> 578 raise TypeError('cannot add matrix and %s' % type(other))
579
580 def __radd__(self, other):
TypeError: cannot add matrix and <type 'int'>
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy-issues.
For more options, visit https://groups.google.com/groups/opt_out.