Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gap: revise make_gap_list, make_gap_matrix #35862

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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