On Mon, Aug 6, 2012 at 3:39 PM, [email protected] <[email protected]> wrote: > Hi all, > > Recently I got to work some more with the matrices module (rref, > jordan form for the ODE solver and various coordinate related > transformations for the diffgeom module). > > The current approach to the issue of Matrix not being a Basic subclass > is to use another class called ImmutableMatrix. There is one big > drawback in this approach among all its advantages: Interaction > between matrices frequently requires rebuilding of the matrix. > > For instance, imagine a ref method that is used inside the rref method > that is used inside the particular_solution method. If they are called > on a mutable matrix they must create a copy of this matrix and work on > it and then return it. So far so good, however if they are called on > an immutable matrix at the end of each method there is an addition > rebuild operation, this time transforming the intermediate mutable > matrix into an immutable one. > > Do you think that this is appropriate and worth the cost? Now that we > have used both Mutable and ImmutableMatrix for some time, do you think > that merging them is possible? Obviously, this again brings up the > issue of mutable Basic objects, however this should not be such a big > problem if the hashes are calculated properly and if it is well > documented.
I don't think it's possible to make a mutable object hashable. There's no way to make things like dict and set recalculate the hash of an object if it changes. Perhaps a better solution would be to make ImmutableMatrix the default (i.e., Matrix would be a shortcut to ImmutableMatrix instead of MutableMatrix). Then we could make MutableMatrix truly mutable, i.e., most operations would modify the matrix in place instead of creating a new one. Of course, this would also mean removing the (to me nonsensical) unevaluatedness from ImmutableMatrix, and put that into a separate class if it is really needed. Regardless of all that, it should be possible to make converting from one type to another a very cheap operation. Aaron Meurer -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
