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

Commit

Permalink
src/sage/combinat/cartesian_product.py: Deprecate CartesianProduct_iters
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Aug 11, 2022
1 parent 75bf2bd commit 2d81aa8
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions src/sage/combinat/cartesian_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ class CartesianProduct_iters(EnumeratedSetFromIterator):
r"""
Cartesian product of finite sets.
This class will soon be deprecated (see :trac:`18411` and :trac:`19195`).
One should instead use the functorial construction
This class is deprecated. Instead use the functorial construction
:class:`cartesian_product <sage.categories.cartesian_product.CartesianProductFunctor>`.
The main differences in behavior are:
- construction: ``CartesianProduct`` takes as many argument as
there are factors whereas ``cartesian_product`` takes a single
- construction: ``CartesianProduct_iters`` takes as many argument as
there are factors, whereas ``cartesian_product`` takes a single
list (or iterable) of factors;
- representation of elements: elements are represented by plain
Python list for ``CartesianProduct`` versus a custom element
Python list for ``CartesianProduct_iters`` versus a custom element
class for ``cartesian_product``;
- membership testing: because of the above, plain Python lists are
Expand All @@ -54,6 +53,9 @@ class for ``cartesian_product``;
sage: F3 = Permutations(3)
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: C = CartesianProduct_iters(F1, F2, F3)
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
sage: c = cartesian_product([F1, F2, F3])
sage: type(C.an_element())
Expand All @@ -80,19 +82,31 @@ def __init__(self, *iters):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: cp = CartesianProduct_iters([1,2],[3,4]); cp
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
Cartesian product of [1, 2], [3, 4]
sage: loads(dumps(cp)) == cp
True
sage: TestSuite(cp).run(skip='_test_an_element')
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
Check that :trac:`24558` is fixed::
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator
sage: I = EnumeratedSetFromIterator(Integers)
sage: CartesianProduct_iters(I, I)
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
Cartesian product of {0, 1, -1, 2, -2, ...}, {0, 1, -1, 2, -2, ...}
"""
from sage.misc.superseded import deprecation
deprecation(19195, 'CartesianProduct_iters is deprecated; use cartesian_product instead')

self.iters = iters
self._mrange = xmrange_iter(iters)
category = EnumeratedSets()
Expand All @@ -117,6 +131,9 @@ def __contains__(self, x):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: cp = CartesianProduct_iters([1,2],[3,4])
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
sage: [1,3] in cp
True
sage: [1,2] in cp
Expand Down Expand Up @@ -153,6 +170,9 @@ def __repr__(self):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: CartesianProduct_iters(list(range(2)), list(range(3)))
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
Cartesian product of [0, 1], [0, 1, 2]
"""
return "Cartesian product of " + ", ".join(map(str, self.iters))
Expand All @@ -166,6 +186,9 @@ def cardinality(self):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: CartesianProduct_iters(range(2), range(3)).cardinality()
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
6
sage: CartesianProduct_iters(range(2), range(3)).cardinality()
6
Expand Down Expand Up @@ -199,6 +222,9 @@ def __len__(self):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: C = CartesianProduct_iters(range(3), range(4))
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
sage: len(C)
12
sage: C = CartesianProduct_iters(ZZ, QQ)
Expand All @@ -220,6 +246,9 @@ def list(self):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: CartesianProduct_iters(range(3), range(3)).list()
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
[[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
sage: CartesianProduct_iters('dog', 'cat').list()
[['d', 'c'],
Expand All @@ -246,6 +275,9 @@ def __iterate__(self):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: [e for e in CartesianProduct_iters(range(3), range(3))]
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
[[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
sage: [e for e in CartesianProduct_iters('dog', 'cat')]
[['d', 'c'],
Expand All @@ -269,6 +301,9 @@ def is_finite(self):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: CartesianProduct_iters(ZZ, []).is_finite()
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
True
sage: CartesianProduct_iters(4,4).is_finite()
Traceback (most recent call last):
Expand All @@ -294,6 +329,9 @@ def unrank(self, x):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: C = CartesianProduct_iters(range(1000), range(1000), range(1000))
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
sage: C[238792368]
[238, 792, 368]
Expand Down Expand Up @@ -329,6 +367,9 @@ def random_element(self):
sage: from sage.combinat.cartesian_product import CartesianProduct_iters
sage: c = CartesianProduct_iters('dog', 'cat').random_element()
doctest:warning...
DeprecationWarning: CartesianProduct_iters is deprecated; use cartesian_product instead
See http://trac.sagemath.org/19195 for details.
sage: c in CartesianProduct_iters('dog', 'cat')
True
"""
Expand Down

0 comments on commit 2d81aa8

Please sign in to comment.