I would like to use libgap in PermutationGroup_generic.random_element, 
because of the following:

sage: G = PermutationGroup([[(1,2,3),(4,5)], [(1,2)]])
sage: %timeit G(G._libgap_().Random(), check=False)
9.83 µs ± 24.8 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: %timeit G(G._gap_().Random(), check=False)
6.73 ms ± 97 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

I think that's a factor of about 700.

However, I am running into a problem with randstate.pyx.

The code for random_element is:
```
    def random_element(self):
...
        current_randstate().set_seed_gap()
        return self(self._gap_().Random(), check=False)
```
If I change the last line to use libgap, `set_seed_gap` does not achieve 
its goal anymore, because it uses the gap interface:

```
        global _gap_seed_randstate
        if _gap_seed_randstate is not self:
            from sage.interfaces.gap import gap

            if self._gap_saved_seed is not None:
                mersenne_seed, classic_seed = self._gap_saved_seed
            else:
                from sage.rings.integer_ring import ZZ
                seed = ZZ.random_element(1<<128)
                classic_seed = seed
                mersenne_seed = seed

            prev_mersenne_seed = gap.Reset(gap.GlobalMersenneTwister, 
mersenne_seed)
            prev_classic_seed = gap.Reset(gap.GlobalRandomSource, 
classic_seed)

            if _gap_seed_randstate is not None:
                _gap_seed_randstate._gap_saved_seed = \
                    prev_mersenne_seed, prev_classic_seed

            _gap_seed_randstate = self
```
I'm currently trying to simply duplicate that function, replacing gap with 
libgap , but I would rather have only one that synchronizes the two.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/sage-devel/e9fd0263-3660-4996-a5a6-243e3559ac0fn%40googlegroups.com.

Reply via email to