Skip to content

Commit 38556c2

Browse files
author
Release Manager
committed
Trac #30602: Partitions_n.__iter__ creates partitions with int (instead of Integer) parts
Several iterators over partitions return partitions whose parts are of type `int` instead of `Integer`: {{{ sage: type(Partitions(3)[0][0]) <class 'int'> sage: type(Partitions(3, length=3)[0][0]) <class 'int'> sage: type(Partitions(3, max_part=3)[0][0]) <class 'sage.rings.integer.Integer'> }}} URL: https://trac.sagemath.org/30602 Reported by: mantepse Ticket author(s): Mike Hansen Reviewer(s): Travis Scrimshaw
2 parents 0580800 + 82e30dc commit 38556c2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/sage/combinat/partition.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -6655,9 +6655,15 @@ def __iter__(self):
66556655
66566656
sage: [x for x in Partitions(4)]
66576657
[[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
6658+
6659+
TESTS::
6660+
6661+
sage: all(isinstance(i, Integer) for p in Partitions(4) for i in p)
6662+
True
6663+
66586664
"""
66596665
for p in ZS1_iterator(self.n):
6660-
yield self.element_class(self, p)
6666+
yield self.element_class(self, [Integer(i) for i in p])
66616667

66626668
def subset(self, **kwargs):
66636669
r"""
@@ -6787,10 +6793,17 @@ def __iter__(self):
67876793
....: == number_of_partitions_length(n, k)
67886794
....: for n in range(9) for k in range(n+2) )
67896795
True
6796+
6797+
TESTS::
6798+
6799+
sage: partitions = Partitions(9, length=3)
6800+
sage: all(isinstance(i, Integer) for p in partitions for i in p)
6801+
True
6802+
67906803
"""
67916804
for p in ZS1_iterator_nk(self.n - self.k, self.k):
6792-
v = [i + 1 for i in p]
6793-
adds = [1] * (self.k - len(v))
6805+
v = [Integer(i + 1) for i in p]
6806+
adds = [Integer(1)] * (self.k - len(v))
67946807
yield self.element_class(self, v + adds)
67956808

67966809
def cardinality(self, algorithm='hybrid'):

0 commit comments

Comments
 (0)