On Friday, August 6, 2021 at 11:18:30 AM UTC+9 Nils Bruin wrote:
> On Thursday, 5 August 2021 at 18:42:55 UTC-7 Kwankyu Lee wrote: > >> I didn't know that a fresh new vector is mutable. I have never used this >> feature. Why does it make sense that a new vector starts as mutable? Why a >> mutable vector is necessary? >> > It can't start out immutable and then changed to mutable since ... well > ... an immutable vector is immutable. There's a promise made that it won't > change its content in its lifetime. We can't break that promise. So once > you think mutable vectors should be an *option*, having them start out as > mutable is an easy way of making them available. > > Mutable vectors and matrices are very important for numpy-style efficient > algorithms: modifying matrices in-place (and I guess vectors as well) saves > a lot of memory allocation churn for consecutively-allocated "float" and > "int64" arrays. For our RealField and Integer/Rational based vectors this > is already much less the case, because generally basic arithmetic *already* > generates memory churn. I suspect in those cases a bit of pointer copying > may not actually be so costly in comparison, so the overhead of newly > allocating memory for results might actually not be so significant. In > numpy and Pandas (which, oddly DOES copy a lot), it can be essential to do > a lot of in-place modification, because the data structures can be huge, if > you're working with high-dimensional vectors or matrices. > I understand this for matrices; we use matrices like lists.They belong to exceptions. But I don't understand it for vectors. > In general, I am for that every output in Sage should be hashable and >> hence immutable by default, with exceptions explicitly declared as such. >> > > So ... I suspect there's a lot of code in sage where immutable vectors > wouldn't hurt, because a lot of operations will rely on the default > arithmetic, which creates new vectors for results. However, there are some > places where it would be a problem. Indeed, I think it would be quite > reasonable to ask people to construct a vector explicitly as mutable if > they need it. > I agree. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/31e886b4-666a-4fed-9f5b-524c8209871fn%40googlegroups.com.
