On Sunday, September 29, 2013 9:21:03 AM UTC+1, Dima Pasechnik wrote:

> in the loop: 
>  cdef Integer accumulator = Integer(0) 
>  cdef vector[int].iterator i = self.data.begin() 
>  while i != self.data.end(): 
>      mpz_add_ui(accumulator.value, accumulator.value, <int>(i[0])) 
>      i += 1 
>
> which is not clear to me: 
> 1) why can't one just use '+' instead? Is it a cython limitation? 
>

Using + means calling accumulator.__add__() which will expect a python 
object as argument. So you would have to wrap the increment *i first in a 
Sage Integer. This can be done, of course, but is slightly slower. 
 

> 2) why i[0] ? 
>

In Cython, dereference is expressed using [0] and not with unary *

In other words C/C++

    int *pointer = ...;
    int x = *pointer;

becomes

    cdef int *pointer = ...
    cdef int x = pointer[0]

in Cython.

-- 
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 post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to