Skip to content

Commit

Permalink
gh-35862: gap: revise make_gap_list, make_gap_matrix
Browse files Browse the repository at this point in the history
    
Contains PR #35761, once that is merged I'll rebase here.
    
URL: #35862
Reported by: Max Horn
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager committed Aug 5, 2023
2 parents d229f45 + ecf7d96 commit a1a27b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
49 changes: 32 additions & 17 deletions src/sage/libs/gap/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,23 @@ cdef Obj make_gap_list(sage_list) except NULL:
The list of the elements in ``a`` as a Gap ``Obj``.
"""
cdef GapElement l = libgap.eval('[]')
cdef Obj l
cdef GapElement elem
for x in sage_list:
if not isinstance(x, GapElement):
elem = <GapElement>libgap(x)
else:
elem = <GapElement>x
cdef int i
try:
GAP_Enter()
l = GAP_NewPlist(0)

AddList(l.value, elem.value)
return l.value
for i, x in enumerate(sage_list):
if not isinstance(x, GapElement):
elem = <GapElement>libgap(x)
else:
elem = <GapElement>x

GAP_AssList(l, i + 1, elem.value)
return l
finally:
GAP_Leave()


cdef Obj make_gap_matrix(sage_list, gap_ring) except NULL:
Expand All @@ -77,22 +84,30 @@ cdef Obj make_gap_matrix(sage_list, gap_ring) except NULL:
The list of the elements in ``sage_list`` as a Gap ``Obj``.
"""
cdef GapElement l = libgap.eval('[]')
cdef Obj l
cdef GapElement elem
cdef GapElement one
cdef int i
if gap_ring is not None:
one = <GapElement>gap_ring.One()
else:
one = <GapElement>libgap(1)
for x in sage_list:
if not isinstance(x, GapElement):
elem = <GapElement>libgap(x)
elem = elem * one
else:
elem = <GapElement>x

AddList(l.value, elem.value)
return l.value
try:
GAP_Enter()
l = GAP_NewPlist(0)

for i, x in enumerate(sage_list):
if not isinstance(x, GapElement):
elem = <GapElement>libgap(x)
elem = elem * one
else:
elem = <GapElement>x

GAP_AssList(l, i + 1, elem.value)
return l
finally:
GAP_Leave()


cdef char *capture_stdout(Obj func, Obj obj):
Expand Down
4 changes: 0 additions & 4 deletions src/sage/libs/gap/gap_includes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ cdef extern from "gap/lists.h" nogil:
Obj ELM_LIST(Obj lst, int pos)


cdef extern from "gap/listfunc.h" nogil:
void AddList(Obj list, Obj obj)


cdef extern from "gap/objects.h" nogil:
bint IS_MUTABLE_OBJ(Obj obj)
Obj SHALLOW_COPY_OBJ(Obj obj)
Expand Down

0 comments on commit a1a27b1

Please sign in to comment.