Path: blob/master/src/sage/groups/matrix_gps/pickling_overrides.py
8815 views
"""1Overrides to unpickle old matrix groups2"""34from sage.structure.sage_object import SageObject, register_unpickle_override56from sage.groups.matrix_gps.finitely_generated import FinitelyGeneratedMatrixGroup_gap7from sage.groups.matrix_gps.group_element import MatrixGroupElement_gap8from sage.groups.matrix_gps.linear import GL, LinearMatrixGroup_generic9101112class LegacyMatrixGroup(FinitelyGeneratedMatrixGroup_gap):1314def __setstate__(self, state):15"""16Restore from old pickle.1718EXAMPLES::1920sage: from sage.groups.matrix_gps.pickling_overrides import *21sage: state = dict()22sage: state['_MatrixGroup_gap__n'] = 223sage: state['_MatrixGroup_gap__R'] = GF(3)24sage: state['_gensG'] = [ matrix(GF(3), [[1,2],[0,1]]) ]25sage: M = LegacyMatrixGroup.__new__(LegacyMatrixGroup)26sage: M.__setstate__(state)27sage: M28Matrix group over Finite Field of size 3 with 1 generators (29[1 2]30[0 1]31)32"""33matrix_gens = state['_gensG']34ring = state['_MatrixGroup_gap__R']35degree = state['_MatrixGroup_gap__n']36from sage.libs.all import libgap37libgap_group = libgap.Group(libgap(matrix_gens))38self.__init__(degree, ring, libgap_group)394041register_unpickle_override(42'sage.groups.matrix_gps.matrix_group', 'MatrixGroup_gens_finite_field',43LegacyMatrixGroup)444546class LegacyMatrixGroupElement(MatrixGroupElement_gap):4748def __setstate__(self, state):49"""50Restore from old pickle.5152EXAMPLES::5354sage: from sage.groups.matrix_gps.pickling_overrides import *55sage: state = dict()56sage: state['_MatrixGroup_gap__n'] = 257sage: state['_MatrixGroup_gap__R'] = GF(3)58sage: state['_gensG'] = [ matrix(GF(3), [[1,2],[0,1]]) ]59sage: M = LegacyMatrixGroup.__new__(LegacyMatrixGroup)60sage: M.__setstate__(state)61sage: M62Matrix group over Finite Field of size 3 with 1 generators (63[1 2]64[0 1]65)66sage: state = [ M, {'_MatrixGroupElement__mat':matrix(GF(3), [[1,2],[0,1]])} ]67sage: m = LegacyMatrixGroupElement.__new__(LegacyMatrixGroupElement)68sage: m.__setstate__(state)69sage: m70[1 2]71[0 1]72"""73parent = state[0]74m = state[1]['_MatrixGroupElement__mat']75m = parent.matrix_space()(m)76self.__init__(parent, m, check=False)777879register_unpickle_override(80'sage.groups.matrix_gps.matrix_group_element', 'MatrixGroupElement',81LegacyMatrixGroupElement)828384class LegacyGeneralLinearGroup(LinearMatrixGroup_generic):8586def __setstate__(self, state):87"""88Restore from old pickle.8990EXAMPLES::9192sage: from sage.groups.group import Group93sage: from sage.groups.matrix_gps.pickling_overrides import *94sage: state = dict()95sage: state['_MatrixGroup_gap__n'] = 296sage: state['_MatrixGroup_gap__R'] = ZZ97sage: M = Group.__new__(LegacyGeneralLinearGroup)98sage: M.__setstate__(state)99sage: M100General Linear Group of degree 2 over Integer Ring101"""102ring = state['_MatrixGroup_gap__R']103n = state['_MatrixGroup_gap__n']104G = GL(n, ring)105self.__init__(G.degree(), G.base_ring(), G._special, G._name_string, G._latex_string)106107108register_unpickle_override(109'sage.groups.matrix_gps.general_linear', 'GeneralLinearGroup_finite_field',110LegacyGeneralLinearGroup)111112113