John
2008/11/3 eduardo <eoca...@gmail.com>:
Hi there,
AFAIK there is no documentation as such but plenty of examples. Note, that
Sage integers are basically mpz_t.
See sage.rings.integer.pyx for details. In particular there are C functions to
get/set mpz_ts from/for Integers.
Cheers,
Martin
--
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_www: http://www.informatik.uni-bremen.de/~malb
_jab: martinr...@jabber.ccc.de
Written in what? C?
John
No idea what your constants are like, but 2^63 nanoseconds is
something like 290 years, so on face value that seems prohibitively
expensive without some massive parallelization of some sort (which
would probably require a complete rewrite of your algorithm.)
However, if I remember correctly the runtime depended on the
factorization of D, not just the size of D itself.
What I would suggest is keeping the long-long version, as that is
probably the most useful useful case, and the speed improvements are
huge. One could also have the mpz version as well, only called when
needed.
> * Is it safe to use long long? Is it 64-bit on all platforms? Does
> Cython care about that?
long long always has at least 64 bits, and is required on all
platforms we target for Sage, so it is safe to use that.
> * We can perhaps use mpz_t (from GMP) instead of long long. Then we
> need to know how can we input/ouput a variable of this type in
> Cython. Is there some documentation about that?
Here is how you would do it (the easy way):
from sage.rings.integer cimport Integer
def add_via_gmp(Integer a, Integer b):
cdef Integer z = PY_NEW(Integer)
mpz_add(z.value, a.value, b.value)
return z
There is also the issue of memory management (if one needs temporary
mpz_t values) and the code is much harder to read/debug. Of course,
99% of the savings would be accomplished by just moving the inner
loop or two to use the mpz_* functions directly, so writing the whole
function this way would be overkill. The speed of this implementation
would almost certainly be closer to the speed of the Python version
than to the speed of the long-long version, as mpz_t arithmetic is
many, many times slower than manipulating long-longs.
- Robert
I've just posted a patch integrating Eduardo's and Andrey's code into
Sage quadratic fields, at
http://trac.sagemath.org/sage_trac/ticket/4990
Best,
Alex
--
Alex Ghitza -- Lecturer in Mathematics -- The University of Melbourne
-- Australia -- http://www.ms.unimelb.edu.au/~aghitza/