[c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

Giacomo Alzetta giacomo.alzetta at gmail.com
Fri Aug 10 12:51:20 EDT 2012


Il giorno venerdì 10 agosto 2012 14:21:50 UTC+2, Hans Mulder ha scritto:
> On 10/08/12 11:25:36, Giacomo Alzetta wrote:
> 
> > Il giorno venerdì 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto:
> 
> [...]
> 
> > Yes, you're right. I didn't thought the combined operator would do a Py_DECREF
> 
> > if the iadd operation was implemented, but it obviosuly makes sense.
> 
> 
> 
> The += operator cannot know if the iadd returns self or a newly created
> 
> object.  Mutable types usually do the former; non-mutable types must do
> 
> the latter.
> 
> 
> 
> Come to think of it: why are your polynomials mutable?
> 
> 
> 
> As a mathematician, I would think of polynomials as elements of
> 
> some kind of ring, and I'd expect them to be non-mutable.
> 
> 
> 
> -- HansM

Usually non-mutable types simply do not implement the iadd operation, and the interpreter tries the simple add after(see intobject.c, longobject.c etc.).

I've decided to make my polynomials mutable for efficiency.
I want to implement the AKS primality tests, and if I want to use it with big numbers the number of coefficients of a polynomial can easily go up to 1k-10k-100k and using non-mutable polynomials would mean to allocate and free that much memory for almost every operation.
Like this I have to allocate/free less frequently.

[even though I must admit that this is a premature optimization :s, since I've not profile anything, but untill I do not implement them I wont be able to see how much time I gain.]



More information about the Python-list mailing list