On Thu, Jul 11, 2013 at 3:51 AM, F. B. <[email protected]> wrote:

> I noticed some methods of BasicMatrix use a trick to create a zero matrix,
> then compiling its values and returning it, e.g.
>
>         newmat = self.zeros(self.rows, self.cols + rhs.cols)
>
>         newmat[:, :self.cols] = self
>
>         newmat[:, self.cols:] = rhs
>
>         return newmat
>
> This works well for MutableMatrix, unfortunately self.zeros called on an
> instance of ImmutableMatrix returns and ImmutableMatrix of zeros which is
> immutable, raising an error on assignment.
>
> A workaround would be to replace self.zeros( ... ) with
> MutableMatrix.zeros( ... ) and then replace return newmat with return
> type(self)(newmat).
>

That would be the easiest way to fix this.


> Otherwise one could devise a way to allow __setitem__ to work on
> ImmutableMatrix as well, maybe returning a new matrix instead of modifying
> it.
>

You probably could make it return a new object, but that would be *very*
confusing. __setitem__ should not look like it works unless it really does.
It isn't like __iadd__ where you don't necessarily expect it to act
in-place.

Or maybe a better idea would be to use some .replace_somewhat( ... )
> method, acting the same way as __setitem__, but returning a new matrix
> instead of modifying the current matrix.
>

Yes, that also sounds like a good idea. Probably whatever method you need
already exists. If it doesn't, it should.

We could also split these out, so that we can keep the efficient mutable
variant on the mutable matrix, but make it work for immutable matrix.

Aaron Meurer

What do you think?
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" 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.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to