Ejemplo n.º 1
0
    def _test_polymake_pickling(self, tester=None, other=None, **options):
        """
        Run tests to see that our polymake pickling/unpickling works.

        INPUT:

        - ``other`` -- a pickling polytope of ``self`` to be tested against

        TESTS::

            sage: polytopes.cross_polytope(3, backend='polymake')._test_polymake_pickling()  # optional - polymake
        """
        if tester is None:
            tester = self._tester(**options)

        if other is None:
            from sage.misc.persist import loads, dumps
            other = loads(dumps(self))

        tester.assertEqual(self, other)

        if not hasattr(self, '_polymake_polytope'):
            tester.assertFalse(hasattr(other, '_polymake_polytope'))
            return

        P = self._polymake_polytope
        P1 = other._polymake_polytope

        tester.assertEqual(P.F_VECTOR, P1.F_VECTOR)
        tester.assertEqual(P.VERTICES, P1.VERTICES)
        tester.assertEqual(P.LINEALITY_SPACE, P1.LINEALITY_SPACE)
        tester.assertEqual(P.FACETS, P1.FACETS)
        tester.assertEqual(P.AFFINE_HULL, P1.AFFINE_HULL)
Ejemplo n.º 2
0
        def dump_element(self, el):
            """
            Create a string representation of the element.
            The default implementation uses 'dumps' and is very inefficient.

            .. note:: the string must be unambigously determined by the element.
            """
            import base64

            return base64.b64encode(dumps(el))
Ejemplo n.º 3
0
    def __init__(self, algebra, gens, subalgebra, unstable, bbox, facade):
        self._algebra = algebra
        self._unstable = unstable
        self._amil = algebra.an_element().change_basis("milnor").parent()
        self._subalg = subalgebra
        self._prime = self._algebra.characteristic()
        self._emask = 0
        self._trunc = bbox
        self._rmask = []
        if facade is None:
            print("WARNING: you should supply a reasonable facade")
            facade = self
        if subalgebra is not None:
            assert subalgebra._truncation_type == 0
            # FIXME
            if not algebra.is_generic():
                e, r = (), subalgebra._profile
            else:
                r, e = subalgebra._profile
            msk = 1
            for i in e:
                if 2 == i:
                    self._emask = self._emask | msk
                msk = msk << 1
            self._rmask = r
        self._gens = gens
        if hasattr(gens, "dump_element"):
            self._dumpfuncs = gens.dump_element, gens.load_element
        else:
            import base64
            from sage.misc.persist import dumps, loads

            self._dumpfuncs = lambda x: base64.b64encode(dumps(
                x)), lambda x: loads(base64.b64decode(x))
        if self.is_finite():
            cat = FiniteEnumeratedSets()
            if not self._algebra.is_generic():
                emax = 0
            else:
                assert self._algebra._has_nontrivial_profile()
                rp, ep = self._profile
                emax = len(k for k in ep if k == 2)
            self._algbox = region(tmin=0,
                                  tmax=self._algebra.top_class().degree(),
                                  emin=0,
                                  emax=emax,
                                  s=0)
        else:
            cat = InfiniteEnumeratedSets()
            self._algbox = region(tmin=0, emin=0, s=0)
        Parent.__init__(self, facade=facade, category=(cat, YacopGradedSets()))
Ejemplo n.º 4
0
    def _test_pickling(self, **options):
        """
        Checks that the instance in self can be pickled and unpickled properly.

        EXAMPLES::

            sage: from sage.misc.sage_unittest import PythonObjectWithTests
            sage: PythonObjectWithTests(int(1))._test_pickling()

        .. SEEALSO::

            :func:`dumps`, :func:`loads`
        """
        tester = instance_tester(self, **options)
        from sage.misc.persist import loads, dumps
        tester.assertEqual(loads(dumps(self._instance)), self._instance)
Ejemplo n.º 5
0
    def __call__(self, x):
        """
        EXAMPLES::

            sage: a = sage0(4)
            sage: a.parent()
            Sage
            sage: a is sage0(a)
            True

        TESTS::

            sage: sage0(axiom(x^2+1)) #optional - axiom
            x^2 + 1

        """
        if isinstance(x, ExpectElement):
            if x.parent() is self:
                return x
            else:
                return self(x.sage())

        if isinstance(x, string_types):
            return SageElement(self, x)

        if self.is_local():
            with open(self._local_tmpfile(), 'wb') as fobj:
                fobj.write(cPickle.dumps(x, 2))
            code = '_sage0_load_local({!r})'.format(self._local_tmpfile())
            return SageElement(self, code)
        else:
            with open(self._local_tmpfile(), 'wb') as fobj:
                fobj.write(dumps(x))  # my dumps is compressed by default
            self._send_tmpfile_to_server()
            code = '_sage0_load_remote({!r})'.format(self._remote_tmpfile())
            return SageElement(self, code)