On Friday, 6 August 2021 at 14:13:19 UTC-7 wst...@gmail.com wrote:

>
> Possible benefits may include:
>
> - potentially much faster: for similar reasons to numpy, a mutable sage 
> vector can be much faster than a generic Python list.
>

I wonder about that. The main reason why it's fast in numpy because 
in-place modification is really *in-place*. In the generic setting, your 
entries are just going to be references to independently allocated python 
objects. Mutations would most likely involve decreffing (and often 
deleting) the old object and allocating a new one. It would also be much 
faster to have mutable mpfr reals, because those could be manipulated 
without memory allocation activity, and yet we don't have those. For 
special implementations (RDF, GF(q) matrices etc) of course we have fully 
in-place storage versions, so there it works well. But to get the speed, 
you'd probably have to kick down to cython level, where the "immutable" 
status is advisory anyway. So I'm not so sure if we're really getting so 
much speed benefit from it.

In much user code, one would definitely start out writing vector 
expressions using expression notation, in which case the vectors aren't 
getting mutated anyway. Only once you find there's a bottleneck somewhere 
would you rewrite those bits ... and then making the relevant object 
mutable explicitly would then be quite natural.

I find it quite telling that pandas by default basically always makes 
copies. It has an option to make changes in-place instead, and if you're 
working with very large data sets you'd have to, but it is surprising how 
far you can get with just working with non-mutated objects. And for them 
it's not even motivated by wanting to have tables hashable (I guess they're 
not)

- type safety: every element of a vector has the same parent ring; a list 
> can have any elements in it
>
yup 

> - length safety: you can't change the number of entries in a mutable list
>
an array would do that too.
 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/8462f71b-afd3-424a-bc11-2092778e8255n%40googlegroups.com.

Reply via email to