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

Commit

Permalink
trac #10534: fix pickling
Browse files Browse the repository at this point in the history
  • Loading branch information
videlec committed Jun 15, 2014
1 parent d9637bd commit 714f266
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/sage/combinat/combination.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,28 @@ def rank(self, x):
"""
x = map(self.mset.index, x)
return rank(x, len(self.mset))


##########################################################
# Deprecations

class ChooseNK(Combinations_setk):
def __setstate__(self, state):
r"""
For unpickling old ``ChooseNK`` objects.
TESTS::
sage: loads("x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1K\xce\xc8\xcf"
....: "/N\x8d\xcf\xcb\xe6r\x06\xb3\xfc\xbc\xb9\n\x195\x1b\x0b"
....: "\x99j\x0b\x995B\x99\xe2\xf3\nY :\x8a2\xf3\xd2\x8b\xf52"
....: "\xf3JR\xd3S\x8b\xb8r\x13\xb3S\xe3a\x9cB\xd6PF\xd3\xd6\xa0"
....: "B6\xa0\xfa\xecB\xf6\x0c \xd7\x08\xc8\xe5(M\xd2\x03\x00{"
....: "\x82$\xd8")
Combinations of [0, 1, 2, 3, 4] of length 2
"""
self.__class__ = Combinations_setk
Combinations_setk.__init__(self, range(state['_n']), state['_k'])

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override("sage.combinat.choose_nk", "ChooseNK", ChooseNK)
27 changes: 27 additions & 0 deletions src/sage/combinat/set_partition_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,30 @@ def __iter__(self):
res = Word(x).standard_permutation().inverse()
res = [lset[x-1] for x in res]
yield self.element_class( self, [ Set( res[dcomp[i]+1:dcomp[i+1]+1] ) for i in range(l)] )

##########################################################
# Deprecations

class SplitNK(OrderedSetPartitions_scomp):
def __setstate__(self, state):
r"""
For unpickling old ``SplitNK`` objects.
TESTS::
sage: loads("x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1+.\xc8\xc9,"
....: "\x89\xcf\xcb\xe6\n\x061\xfc\xbcA\xccBF\xcd\xc6B\xa6\xda"
....: "Bf\x8dP\xa6\xf8\xbcB\x16\x88\x96\xa2\xcc\xbc\xf4b\xbd\xcc"
....: "\xbc\x92\xd4\xf4\xd4\"\xae\xdc\xc4\xec\xd4x\x18\xa7\x905"
....: "\x94\xd1\xb45\xa8\x90\r\xa8>\xbb\x90=\x03\xc85\x02r9J\x93"
....: "\xf4\x00\xb4\xc6%f")
Ordered set partitions of {0, 1, 2, 3, 4} into parts of size [2, 3]
"""
self.__class__ = OrderedSetPartitions_scomp
n = state['_n']
k = state['_k']
OrderedSetPartitions_scomp.__init__(self, range(state['_n']), (k,n-k))

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override("sage.combinat.split_nk", "SplitNK_nk", SplitNK)

0 comments on commit 714f266

Please sign in to comment.