On Fri, Oct 23, 2015 at 5:04 AM, Nathann Cohen <nathann.co...@gmail.com> wrote:
> Hello everybody,
>
> When calling .row() on an immutable matrix, one gets mutable vectors.
> I can easily avoid it for the code I am writing, but do you think we
> should do something about it?

m.row() returns a new (copy) of the row of the matrix, so making that
immutable would be inconsistent with how copy works for matrices.

sage: m = matrix.ones(10)
sage: m.set_immutable()
sage: copy(m).is_immutable()
False

The set_immutable method on matrices solves exactly *one* problem,
which is it makes it possible to create matrices and then efficiently
cache them without having to worry about some other code breaking
them.  For example, it would be very bad indeed if the matrix T below
were mutable (like it was for a few years of Sage...):

sage: M = ModularSymbols(11)
sage: T2 = M.hecke_matrix(2); T2
sage: T2.is_immutable()
True

There are a **TON** of interesting programming problems that the idea
of "immutable data structures" can solve.  Designing and implementing
immutable data structure that actually solve these problems is
interesting and highly nontrivial.  It's not done in Sage to much
extent.

A good example in the Javascript world of a systematic library for
immutable data structures, which really solves some interesting
problems is

   https://facebook.github.io/immutable-js/

It provides immutable versions of all standard Javascript data
structures, but very efficiently builds them on top of mutable data
structures, minimizing wasted space.   It would be interesting to have
something similar in Sage, at least for matrices/vectors, but don't
think that we do now.  What's in Sage is really trivial by comparison.
   For starters, we might create a new immutable vector type in Sage
that is a reference to a row in an immutable matrix, etc., etc.  It's
a lot of work to design and implement something like this.

At least you can do "v = m.row(0); v.set_immutable()".

 -- William


>
>     sage: m = matrix.ones(10)
>     sage: m.set_immutable()
>     sage: hash(m.row(0))
>     ...
>     TypeError: mutable vectors are unhashable
>
> Nathann
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.



-- 
William (http://wstein.org)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to