Using a Python list is probably the fastest way to iterate over an
array of Python objects--it's a PyObject** under the hood and Cython
uses the C API calls to get at it. Your "check" might be the
bottleneck, especially if it's a Python call.

Also, no need to write this as a while loop; just use "for a in
range(1000000)" and it'll do the right thing (a C for loop).

On Wed, Aug 21, 2013 at 12:33 PM, Daniel Krenn <kr...@aon.at> wrote:
> I need an array of Elements of RealIntervalField and I want to iterate
> (a lot of times) through it. How can I do that in a fast way in Sage's
> cython (i.e. in the notebook or in a .spyx-file)?
>
> An (minimal) example what I basically want is given below (PS).
>
> I tried the following things (and a lot more) in the Sage notebook as
> well as in a .spyx-file:
>
>
> 1. using vector
>
>   from libcpp cimport vector
>
> gives
>
>   filename.c:317:18: fatal error: vector: file or directory not found
>   compilation terminated.
>   error: command 'gcc' failed with exit status 1
>
> At least I found the file in Cython/include/...
>
>
> 2. using C arrays
>
>   cimport sage.rings.real_mpfi  # do not know whether that is needed...
>   from sage.rings.real_mpfi cimport RealIntervalFieldElement
>   cdef RealIntervalFieldElement L[10]
>
> says
>
>   cdef RealIntervalFieldElement L[10]
>                               ^
>   filename.pyx:12:31: Array element cannot be a Python object
>
> I thought that with cimport I get a C/cython object (but maybe I have
> too less understanding of it)
>
>
> 3. using some pointers
>
>   from sage.rings.real_mpfi cimport RealIntervalFieldElement
>   from sage.all import RIF
>   cdef void* L[10]
>   cdef RealIntervalFieldElement r = RIF(100)
>   L[0] = &r
>
> gives
>
>   cdef RealIntervalFieldElement r = RIF(100)
>   L[0] = &r      ^
>   filename.pyx:15:7: Cannot take address of Python variable
>
>
> I am thankful for any input.
>
> Daniel
>
>
> PS: Here is what I want faster:
>
> L = [blabla]  # a python list of length about 500
> a=0
> while a<10000000:
>     b = something(a)
>     for ell in L:
>         if check(a,b,ell):
>             print "yeah"  # or do whatever
>     a += 1
>
> L is a list of RealIntervalField elements; b is a RealIntervalElement, too.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-support+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-support@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.

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

Reply via email to