#12029: Fast conversion of ClonableIntArray to list
------------------------------------------+---------------------------------
Reporter: SimonKing | Owner: sage-combinat
Type: enhancement | Status: positive_review
Priority: major | Milestone: sage-4.8
Component: combinatorics | Keywords:
Work_issues: | Upstream: N/A
Reviewer: Florent Hivert, Simon King | Author: Simon King,
Florent Hivert
Merged: | Dependencies:
------------------------------------------+---------------------------------
Changes (by newvalueoldvalue):
* status: needs_review => positive_review
* reviewer: => Florent Hivert, Simon King
* author: Simon King => Simon King, Florent Hivert
Old description:
> I think the following is too slow:
> {{{
> sage: from sage.structure.list_clone import IncreasingIntArrays
> sage: I = IncreasingIntArrays()(range(1000))
> sage: timeit("L = list(I)", number=10000)
> 10000 loops, best of 3: 41.8 µs per loop
> }}}
>
> My patch adds a method `.list()` (I hope this is the fastest way of
> converting a C-int array into a Python list - Cython experts are welcome
> to find something better), and it adds an `__iter__()` method that relies
> on the `.list()` method.
>
> Note that I tried to have an `__iter__` method that does not call
> `list()` but works on the C-array (this is now possible with the new
> Cython version), but it turned out to be not faster.
>
> Here are the timings with my patch
> {{{
> sage: from sage.structure.list_clone import IncreasingIntArrays
> sage: I = IncreasingIntArrays()(range(1000))
> sage: timeit("L = I.list()", number=10000)
> 10000 loops, best of 3: 19.4 µs per loop
> sage: timeit("L = list(I)", number=10000)
> 10000 loops, best of 3: 32.9 µs per loop
> }}}
New description:
I think the following is too slow:
{{{
sage: from sage.structure.list_clone import IncreasingIntArrays
sage: I = IncreasingIntArrays()(range(1000))
sage: timeit("L = list(I)", number=10000)
10000 loops, best of 3: 41.8 µs per loop
}}}
My patch adds a method `.list()` (I hope this is the fastest way of
converting a C-int array into a Python list - Cython experts are welcome
to find something better), and it adds an `__iter__()` method that relies
on the `.list()` method.
Note that I tried to have an `__iter__` method that does not call `list()`
but works on the C-array (this is now possible with the new Cython
version), but it turned out to be not faster.
Here are the timings with my patch
{{{
sage: from sage.structure.list_clone import IncreasingIntArrays
sage: I = IncreasingIntArrays()(range(1000))
sage: timeit("L = I.list()", number=10000)
10000 loops, best of 3: 19.4 µs per loop
sage: timeit("L = list(I)", number=10000)
10000 loops, best of 3: 32.9 µs per loop
}}}
__Apply__
[attachment:trac12029_clonable_int_array_2_list.patch]
--
Comment:
I folded Florent's patch and posted the combined patch under the original
name of my patch. I hope you don't mind.
I can confirm that using the C-Api gives an additional speed-up. The new
doctest from Florent's patch tests against a case that was critical during
development (it would result in a segfault without Florent's
`PyInt_FromLong`).
All doctests pass, even when using the new Cython version. Therefore, I
can give Florent's patch a positive review. He gave my patch a positive
review as well. So, that's done.
Apply trac12029_clonable_int_array_2_list.patch
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12029#comment:13>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" 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/sage-trac?hl=en.