Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
doctest fixes + __len__ modification for giac 1.5.0.87 behavior with …
Browse files Browse the repository at this point in the history
…emptylist seq[]
  • Loading branch information
Frederic HAN committed Aug 14, 2020
1 parent 1fbe528 commit 0ad89d8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/sage/libs/giac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
EXAMPLES::
sage: from sage.libs.giac import groebner_basis as gb_giac
sage: from sage.libs.giac import groebner_basis as gb_giac # random
sage: P = PolynomialRing(QQ, 6, 'x')
sage: I = sage.rings.ideal.Cyclic(P)
sage: B = gb_giac(I.gens()) # random
Expand Down
2 changes: 2 additions & 0 deletions src/sage/libs/giac/giac.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cdef extern from "giac/giac.h" namespace "giac":
vecteur(int)
vecteur()
void push_back(gen &)
int size()
cdef struct ref_vecteur:
pass
cdef struct ref_sparse_poly1:
Expand Down Expand Up @@ -73,6 +74,7 @@ cdef extern from "giac/giac.h" namespace "giac":

mpz_t * ref_ZINTptr() except +
gen * ref_MODptr() except +
vecteur * ref_VECTptr() except +

#
unsigned char type
Expand Down
37 changes: 24 additions & 13 deletions src/sage/libs/giac/giac.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ in giac, but the mathematical computation is not done. This class is mainly
for cython users. Here A is a Pygen element, and it is ready for any giac
function.::
sage: from sage.libs.giac.giac import *
sage: from sage.libs.giac.giac import * # random
//...
sage: A = Pygen('2+2')
sage: A
2+2
Expand Down Expand Up @@ -937,17 +938,28 @@ cdef class Pygen:
return result
def __len__(self):
#if (self.gptr != NULL):
try:
sig_on()
rep=GIAC_size(self.gptr[0],context_ptr).val
sig_off()
#GIAC_size return a gen. we take the int: val
return rep
except:
raise RuntimeError
#else:
# raise MemoryError,"This Pygen is not associated to a giac gen"
"""
TESTS::
sage: from sage.libs.giac.giac import libgiac
sage: l=libgiac("seq[]");len(l) # 29552 comment28
0
"""
if (self._type == 7):
sig_on()
rep=(self.gptr.ref_VECTptr()).size()
sig_off()
return rep
else:
try:
sig_on()
rep=GIAC_size(self.gptr[0],context_ptr).val
sig_off()
#GIAC_size return a gen. we take the int: val
return rep
except:
raise RuntimeError
def __getitem__(self,i): #TODO?: add gen support for indexes
Expand Down Expand Up @@ -979,7 +991,6 @@ cdef class Pygen:
sage: l=Pygen()
sage: l[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
IndexError: list index 0 out of range
"""
Expand Down

0 comments on commit 0ad89d8

Please sign in to comment.