Skip to content

Commit

Permalink
Faster (I think) approach to make_gap_list.
Browse files Browse the repository at this point in the history
  • Loading branch information
embray committed Jan 12, 2021
1 parent 1e78f80 commit 20edea8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
21 changes: 13 additions & 8 deletions gappy/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,21 @@ cdef Obj make_gap_list(parent, lst) except NULL:
The list of the elements in ``a`` as a GAP ``Obj``.
"""
cdef GapObj l = parent.eval('[]')
cdef Obj l
cdef GapObj elem
for x in lst:
if not isinstance(x, GapObj):
elem = <GapObj>parent(x)
else:
elem = <GapObj>x
try:
GAP_Enter()
l = GAP_NewPlist(len(lst))
for idx, x in enumerate(lst):
if not isinstance(x, GapObj):
elem = <GapObj>parent(x)
else:
elem = <GapObj>x

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


cdef Obj make_gap_matrix(parent, lst, gap_ring) except NULL:
Expand Down
1 change: 1 addition & 0 deletions gappy/gap_includes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ cdef extern from "gap/libgap-api.h" nogil:
Obj GAP_ElmList(Obj, UInt)
UInt GAP_LenList(Obj)
int GAP_IsList(Obj)
Obj GAP_NewPlist(Int)



Expand Down

0 comments on commit 20edea8

Please sign in to comment.