Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Unpickling methods
Python saves objects by providing a pair ``(f, data)`` such that ``f(data)`` reconstructs the object. This module collects the loading (_unpickling_ in Python terminology) functions for Sage's matroids.
.. NOTE::
The reason this code was separated out from the classes was to make it play nice with lazy importing of the ``Matroid()`` and ``matroids`` keywords.
AUTHORS:
- Rudi Pendavingh, Stefan van Zwam (2013-07-01): initial version """ #***************************************************************************** # Copyright (C) 2013 Rudi Pendavingh <rudi.pendavingh@gmail.com> # Copyright (C) 2013 Stefan van Zwam <stefanvanzwam@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import
include 'sage/data_structures/bitset.pxi' from .circuit_closures_matroid cimport CircuitClosuresMatroid from .basis_matroid cimport BasisMatroid from .linear_matroid cimport LinearMatroid, RegularMatroid, BinaryMatroid, TernaryMatroid, QuaternaryMatroid from .lean_matrix cimport GenericMatrix, BinaryMatrix, TernaryMatrix, QuaternaryMatrix, IntegerMatrix
############################################################################# # BasisMatroid #############################################################################
""" Unpickle a BasisMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer, expected to be 0 - ``data`` -- a tuple ``(E, R, name, BB)`` in which ``E`` is the groundset of the matroid, ``R`` is the rank, ``name`` is a custom name, and ``BB`` is the bitpacked list of bases, as pickled by Sage's ``bitset_pickle``.
OUTPUT:
A matroid.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: from sage.matroids.advanced import * sage: M = BasisMatroid(matroids.named_matroids.Vamos()) sage: M == loads(dumps(M)) # indirect doctest True
""" cdef BasisMatroid M raise TypeError("object was created with newer version of Sage. Please upgrade.")
############################################################################# # CircuitClosuresMatroid #############################################################################
""" Unpickle a CircuitClosuresMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer, expected to be 0 - ``data`` -- a tuple ``(E, CC, name)`` in which ``E`` is the groundset of the matroid, ``CC`` is the dictionary of circuit closures, and ``name`` is a custom name.
OUTPUT:
A matroid.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: M = matroids.named_matroids.Vamos() sage: M == loads(dumps(M)) # indirect doctest True """ cdef CircuitClosuresMatroid M raise TypeError("object was created with newer version of Sage. Please upgrade.")
############################################################################# # DualMatroid #############################################################################
""" Unpickle a DualMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer, expected to be 0 - ``data`` -- a tuple ``(M, name)`` in which ``M`` is the internal matroid, and ``name`` is a custom name.
OUTPUT:
A matroid.
.. WARNING::
Users should not call this function directly. Instead, use load/save.
EXAMPLES::
sage: M = matroids.named_matroids.Vamos().dual() sage: M == loads(dumps(M)) # indirect doctest True """ raise TypeError("object was created with newer version of Sage. Please upgrade.") M.rename(data[1])
############################################################################# # LeanMatrix subclasses #############################################################################
""" Reconstruct a ``GenericMatrix`` object (internal Sage data structure).
.. WARNING::
Users should not call this method directly.
EXAMPLES::
sage: from sage.matroids.lean_matrix import * sage: A = GenericMatrix(2, 5, ring=QQ) sage: A == loads(dumps(A)) # indirect doctest True """ raise TypeError("object was created with newer version of Sage. Please upgrade.")
""" Reconstruct a ``BinaryMatrix`` object (internal Sage data structure).
.. WARNING::
Users should not call this method directly.
EXAMPLES::
sage: from sage.matroids.lean_matrix import * sage: A = BinaryMatrix(2, 5) sage: A == loads(dumps(A)) # indirect doctest True sage: C = BinaryMatrix(2, 2, Matrix(GF(2), [[1, 1], [0, 1]])) sage: C == loads(dumps(C)) True """ cdef BinaryMatrix A cdef long i raise TypeError("object was created with newer version of Sage. Please upgrade.")
""" Reconstruct a ``TernaryMatrix`` object (internal Sage data structure).
.. WARNING::
Users should not call this method directly.
EXAMPLES::
sage: from sage.matroids.lean_matrix import * sage: A = TernaryMatrix(2, 5) sage: A == loads(dumps(A)) # indirect doctest True sage: C = TernaryMatrix(2, 2, Matrix(GF(3), [[1, 1], [0, 1]])) sage: C == loads(dumps(C)) True """ cdef TernaryMatrix A cdef long i raise TypeError("object was created with newer version of Sage. Please upgrade.")
""" Reconstruct a ``QuaternaryMatrix`` object (internal Sage data structure).
.. WARNING::
Users should not call this method directly.
EXAMPLES::
sage: from sage.matroids.lean_matrix import * sage: A = QuaternaryMatrix(2, 5, ring=GF(4, 'x')) sage: A == loads(dumps(A)) # indirect doctest True sage: C = QuaternaryMatrix(2, 2, Matrix(GF(4, 'x'), [[1, 1], [0, 1]])) sage: C == loads(dumps(C)) True """ cdef QuaternaryMatrix A cdef long i raise TypeError("object was created with newer version of Sage. Please upgrade.")
""" Reconstruct an ``IntegerMatrix`` object (internal Sage data structure).
.. WARNING::
Users should not call this method directly.
EXAMPLES::
sage: from sage.matroids.lean_matrix import * sage: A = IntegerMatrix(2, 5) sage: A == loads(dumps(A)) # indirect doctest True """ raise TypeError("object was created with newer version of Sage. Please upgrade.") cdef long i
############################################################################# # LinearMatroid and subclasses #############################################################################
""" Unpickle a LinearMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer (currently 0). - ``data`` -- a tuple ``(A, E, reduced, name)`` where ``A`` is the representation matrix, ``E`` is the groundset of the matroid, ``reduced`` is a boolean indicating whether ``A`` is a reduced matrix, and ``name`` is a custom name.
OUTPUT:
A :class:`LinearMatroid` instance.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 1, 1, 1, 3]])) sage: M == loads(dumps(M)) # indirect doctest True sage: M.rename("U35") sage: loads(dumps(M)) U35 """ raise TypeError("object was created with newer version of Sage. Please upgrade.") else: M = LinearMatroid(groundset=gs, reduced_matrix=A)
""" Unpickle a BinaryMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer (currently 0). - ``data`` -- a tuple ``(A, E, B, name)`` where ``A`` is the representation matrix, ``E`` is the groundset of the matroid, ``B`` is the currently displayed basis, and ``name`` is a custom name.
OUTPUT:
A :class:`BinaryMatroid` instance.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1], [0, 1, 0, 1], ....: [0, 0, 1, 1]])) sage: M == loads(dumps(M)) # indirect doctest True sage: M.rename("U34") sage: loads(dumps(M)) U34 """ raise TypeError("object was created with newer version of Sage. Please upgrade.") else: M = BinaryMatroid(groundset=gs, matrix=A, basis=basis)
""" Unpickle a TernaryMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer (currently 0). - ``data`` -- a tuple ``(A, E, B, name)`` where ``A`` is the representation matrix, ``E`` is the groundset of the matroid, ``B`` is the currently displayed basis, and ``name`` is a custom name.
OUTPUT:
A :class:`TernaryMatroid` instance.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: from sage.matroids.advanced import * sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], ....: [0, 0, 1, 1]])) sage: M == loads(dumps(M)) # indirect doctest True sage: M.rename("U34") sage: loads(dumps(M)) U34 """ raise TypeError("object was created with newer version of Sage. Please upgrade.") else: M = TernaryMatroid(groundset=gs, matrix=A, basis=basis)
""" Unpickle a QuaternaryMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer (currently 0). - ``data`` -- a tuple ``(A, E, B, name)`` where ``A`` is the representation matrix, ``E`` is the groundset of the matroid, ``B`` is the currently displayed basis, and ``name`` is a custom name.
OUTPUT:
A :class:`TernaryMatroid` instance.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: from sage.matroids.advanced import * sage: M = QuaternaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], ....: [0, 0, 1, 1]])) sage: M == loads(dumps(M)) # indirect doctest True sage: M.rename("U34") sage: loads(dumps(M)) U34 sage: M = QuaternaryMatroid(Matrix(GF(4, 'x'), [[1, 0, 1], ....: [1, 0, 1]])) sage: loads(dumps(M)).representation() [1 0 1] [1 0 1] """ raise TypeError("object was created with newer version of Sage. Please upgrade.") else: M = QuaternaryMatroid(groundset=gs, matrix=A, basis=basis)
""" Unpickle a RegularMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer (currently 0). - ``data`` -- a tuple ``(A, E, reduced, name)`` where ``A`` is the representation matrix, ``E`` is the groundset of the matroid, ``reduced`` is a boolean indicating whether ``A`` is a reduced matrix, and ``name`` is a custom name.
OUTPUT:
A :class:`RegularMatroid` instance.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: M = matroids.named_matroids.R10() sage: M == loads(dumps(M)) # indirect doctest True sage: M.rename("R_{10}") sage: loads(dumps(M)) R_{10} """ raise TypeError("object was created with newer version of Sage. Please upgrade.") else: M = RegularMatroid(groundset=gs, reduced_matrix=A)
############################################################################# # Minor matroids #############################################################################
""" Unpickle a MinorMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer, currently `0`. - ``data`` -- a tuple ``(M, C, D, name)``, where ``M`` is the original matroid of which the output is a minor, ``C`` is the set of contractions, ``D`` is the set of deletions, and ``name`` is a custom name.
OUTPUT:
A :class:`MinorMatroid` instance.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: M = matroids.named_matroids.Vamos().minor('abc', 'g') sage: M == loads(dumps(M)) # indirect doctest True """ raise TypeError("object was created with newer version of Sage. Please upgrade.") M.rename(data[3])
############################################################################# # Graphic Matroids #############################################################################
""" Unpickle a GraphicMatroid.
*Pickling* is Python's term for the loading and saving of objects. Functions like these serve to reconstruct a saved object. This all happens transparently through the ``load`` and ``save`` commands, and you should never have to call this function directly.
INPUT:
- ``version`` -- an integer (currently 0). - ``data`` -- a tuple consisting of a SageMath graph and a name.
OUTPUT:
A :class:`GraphicMatroid` instance.
.. WARNING::
Users should never call this function directly.
EXAMPLES::
sage: M = Matroid(graphs.DiamondGraph()) sage: M == loads(dumps(M)) True """ raise TypeError("object was created with newer version of Sage. Please upgrade.") M.rename(name) |