Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
pickling support
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Aug 25, 2016
1 parent 1e5754b commit becce48
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/sage/combinat/k_regular_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ def __iter__(self):
return iter(self[n] for n in count())


def _pickle_kRegularSequenceSpace(k, coefficients, category):
r"""
Pickle helper.
TESTS::
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
sage: from sage.combinat.k_regular_sequence import _pickle_kRegularSequenceSpace
sage: _pickle_kRegularSequenceSpace(
....: Seq2.k, Seq2.coefficients(), Seq2.category())
Space of 2-regular sequences over Integer Ring
"""
return kRegularSequenceSpace(k, coefficients, category=category)


class kRegularSequenceSpace(RecognizableSeriesSpace):
r"""
The space of `k`-regular Sequences over the given ``coefficients``.
Expand Down Expand Up @@ -335,6 +350,20 @@ def __init__(self, k, *args, **kwds):
super(kRegularSequenceSpace, self).__init__(*args, **kwds)


def __reduce__(self):
r"""
Pickling support.
TESTS::
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
sage: loads(dumps(Seq2)) # indirect doctest
Space of 2-regular sequences over Integer Ring
"""
return _pickle_kRegularSequenceSpace, \
(self.k, self.coefficients(), self.category())


def _repr_(self):
r"""
Return a representation string of this `k`-regular sequence space.
Expand Down
28 changes: 28 additions & 0 deletions src/sage/combinat/recognizable_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,20 @@ def hadamard_product(self, other, minimize=True):
return result


def _pickle_RecognizableSeriesSpace(coefficients, indices, category):
r"""
Pickle helper.
TESTS::
sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])
sage: from sage.combinat.recognizable_series import _pickle_RecognizableSeriesSpace
sage: _pickle_RecognizableSeriesSpace(
....: Rec.coefficients(), Rec.indices(), Rec.category())
Space of recognizable series on {0, 1} with coefficients in Integer Ring
"""
return RecognizableSeriesSpace(coefficients, indices=indices, category=category)


class RecognizableSeriesSpace(UniqueRepresentation, Parent):
r"""
Expand Down Expand Up @@ -1457,6 +1471,20 @@ def __init__(self, coefficients, indices, category):
category=category, base=coefficients)


def __reduce__(self):
r"""
Pickling support.
TESTS::
sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])
sage: loads(dumps(Rec)) # indirect doctest
Space of recognizable series on {0, 1} with coefficients in Integer Ring
"""
return _pickle_RecognizableSeriesSpace, \
(self.coefficients(), self.indices(), self.category())


def alphabet(self):
r"""
Return the alphabet of this recognizable series space.
Expand Down

0 comments on commit becce48

Please sign in to comment.