Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ShallowCopy for IteratorOfCartesianProduct #2829

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/combinat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ BindGlobal( "NextIterator_Cartesian",

BindGlobal( "ShallowCopy_Cartesian",
iter -> rec(
sets := iter!.sets,
sizes := iter!.sizes,
n := iter!.n,
next := ShallowCopy( iter!.next ) ) );
Expand All @@ -820,9 +821,8 @@ BindGlobal( "IteratorOfCartesianProduct2",
NextIterator := NextIterator_Cartesian,
ShallowCopy := ShallowCopy_Cartesian,
sets := s, # list of sets
sizes := List( s, Size ), # sizes of sets
sizes := MakeImmutable( List( s, Size ) ),
n := n, # number of sets
nextelts := List( s, x -> x[1] ), # list of 1st elements
next := 0 * [ 1 .. n ] + 1 ) ); # list of 1's
end);

Expand Down
20 changes: 20 additions & 0 deletions tst/testinstall/combinat.tst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ gap> Print(List( [0..3], k -> NrTuples( [1..3], k ) ),"\n");
gap> NrTuples( [1..8], 4 );
4096

#
# IteratorOfCartesianProduct
#

# empty cartesian product
gap> it:=IteratorOfCartesianProduct([[1,2],[]]);;
gap> IsDoneIterator(it);
true
gap> List(it);
[ ]

# non-empty cartesian product
gap> it:=IteratorOfCartesianProduct([1,2], [3,4]);;
gap> IsDoneIterator(it);
false
gap> List(it);
[ [ 1, 3 ], [ 1, 4 ], [ 2, 3 ], [ 2, 4 ] ]
gap> List(it); # do it again, to verify the original iterator was not modified
[ [ 1, 3 ], [ 1, 4 ], [ 2, 3 ], [ 2, 4 ] ]

#F PermutationsList( <mset> ) . . . . . . set of permutations of a multiset
gap> PermutationsList( [] );
[ [ ] ]
Expand Down