- # This is just a manual "from_vector()", but of course
- # matrix spaces aren't vector spaces in sage, so they
- # don't have a from_vector() method.
- return W.linear_combination( zip(B, self.to_vector()) )
+ if hasattr(W, 'cartesian_factors'):
+ # Aaaaand linear combinations don't work in Cartesian
+ # product spaces, even though they provide a method with
+ # that name. This is hidden behind an "if" because the
+ # _scale() function is slow.
+ pairs = zip(B, self.to_vector())
+ return W.sum( _scale(b, alpha) for (b,alpha) in pairs )
+ else:
+ # This is just a manual "from_vector()", but of course
+ # matrix spaces aren't vector spaces in sage, so they
+ # don't have a from_vector() method.
+ return W.linear_combination( zip(B, self.to_vector()) )
+