I have been able to get ~1.7x with this somewhat ugly hack:
%cython
from sage.all import *
def permutationMatrices(n):
import numpy
cdef int deg = SymmetricGroup(n).degree()
cdef int i_max = SymmetricGroup(n).order()
cdef int chunk = 10000
cdef int i = 0
step = range(0,i_max+1, chunk)
step.append(i_max)
libgap.eval("e := Enumerator(SymmetricGroup({0}))".format(n))
while i < len(step)-1:
libgap.eval("l:=[]")
evalStr = "for i in [{0}..{1}] do Add(l,PermutationMat(e[i],{2}));
od;".format(step[i]+1, step[i+1],deg)
libgap.eval(evalStr);
i = i + 1
result = eval(str(libgap.eval("l")))
for x in result:
yield numpy.mat(x)
It abuses the fact that GAP's matrix output can directly be evaluated as
lists. The chunk variable is control the number of "API" calls. Not
*strictly* the same though, here I am busy numpy matrices. Sufficient for
my purposes though.
On Monday, March 3, 2014 9:49:44 AM UTC+2, Karl Möller wrote:
>
> Hi
>
> I am using SAGE to interface with GAP. (I don't really know GAP, just
> playing with the SAGE interface to it).
>
> My problem is that I am trying to efficiently enumerate the group elements
> (and get their matrix representations) of various permutation groups. Now,
> of course this problem quickly blows up due to the factorial growth of
> group elements, but I am trying to see how far I can go. At the moment this
> is my current toy solution:
>
> def symmetricGroupElements(n):
> i_max = SymmetricGroup(n).order()
> libgap.eval("G := Iterator(Enumerator(SymmetricGroup({0})))".format(n))
> nxtStr = "NextIterator(G)"
> for x in xrange(1,i_max+1):
> yield libgap.eval(nxtStr).sage().matrix()
>
>
> This produces a generator that returns a matrix representation of an
> element of the group S_n. The reason I am not using the list() function on
> a group is because GAP builds up an entire list, blowing through all my (or
> the known universe?) memory. On my current modern'ish Xeon machine, I can
> run through that entire generator for S_10 in about 2 hours. My question is:
>
> Can I do better? Memory and/or computation time wise. Should I rather be
> interacting with libGAP on a more low level? I would imagine a lot of type
> casting is going on between libGAP wrapper objects and the underlying C
> code. I only need the matrices one at a time for further manipulation with
> SAGE.
>
> (My GAP knowledge is very limited, it might just be that I am doing this
> in a really stupid way...)
>
> Karl
>
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.