-
Notifications
You must be signed in to change notification settings - Fork 161
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
Implement CycleFromList, and fix potential crash in CYCLE_TRANS_INT #2242
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that something like this is useful to have in general.
I wonder if instead of just supporting creating cycles, it would be possible / useful to have something which takes a list-of-lists (representing disjoint cycles), and turns those into a permutation. (a simple implementation would just call your function here on each cycle, and then multiply the result together, though of course that would not detect overlaps; which might be considered either a bug or feature ;-)
Codecov Report
@@ Coverage Diff @@
## master #2242 +/- ##
==========================================
+ Coverage 69.88% 70.34% +0.45%
==========================================
Files 481 481
Lines 252990 253198 +208
==========================================
+ Hits 176813 178117 +1304
+ Misses 76177 75081 -1096
|
lib/permutat.g
Outdated
fi; | ||
|
||
set := Set(list); | ||
if not IsDenseList(list) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this check, as the next check will fail if the list is not sense (as the set will be smaller).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, maybe check Minimum is > 0
644d850
to
67f86c2
Compare
## return the <M>n</M>-cycle <M>(a_1,a_2,...,a_n)</M>. For the empty list | ||
## the trivial permutation <M>()</M> is returned. | ||
## <P/> | ||
## If the given <A>list</A> contains duplicates or holes, return <K>fail</K>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if there is a something that is not a positive integer in the list? Right now, probably various errors, depending on whether its a negative integer (gives proper error), a string or some such (will run into a method not found at some point), a rational (same, but likely in a different) spot, ...
lib/permutat.g
Outdated
min := Minimum( set ); | ||
if min <= 0 then | ||
Error("CycleFromList: List must contain only positive integers."); | ||
fi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, perhaps do if not ForAll(list, IsPosInt) then Error(...); fi;
even before computing set
?
od; | ||
images[ list[Length(list)] ] := list[1]; | ||
|
||
return PermList(images); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While manual test cases are provided, and exercise the regular parts of the function, not all failure cases are tested, e.g. CycleFromList([0])
, CycleFromList([1/2])
, CycleFromList([true])
to name a few. Perhaps add some (though perhaps to a .tst file, not the manual example)?
I'll not block the PR over this, but it is needed to maximize the test coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also no test for the empty list. All this can be seen on https://codecov.io/gh/gap-system/gap/pull/2242/diff?src=pr&el=tree#diff-bGliL3Blcm11dGF0Lmc= (link comes from the codecov report in the PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about the test directory structure of GAP. Where exactly should I put the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere into tst/testinstall/
. In this case, I'd suggest to create tst/testinstall/opers/CyclesFromList.tst
. Look at the other files in that directory to get an idea what to put in, in case you are not familiar with .tst files. And feel free to ask more questions.
67f86c2
to
1d005e0
Compare
I suspect the test failure is due to a bug in diff --git a/src/trans.c b/src/trans.c
index deb807172..f0ea6c1ea 100644
--- a/src/trans.c
+++ b/src/trans.c
@@ -3102,6 +3102,7 @@ Obj FuncCYCLE_TRANS_INT(Obj self, Obj f, Obj pt)
i = cpt;
do {
AssPlist(out, ++len, INTOBJ_INT(i + 1));
+ ptf2 = CONST_ADDR_TRANS2(f);
i = ptf2[i];
} while (i != cpt);
}
@@ -3116,6 +3117,7 @@ Obj FuncCYCLE_TRANS_INT(Obj self, Obj f, Obj pt)
i = cpt;
do {
AssPlist(out, ++len, INTOBJ_INT(i + 1));
+ ptf4 = CONST_ADDR_TRANS4(f);
i = ptf4[i];
} while (i != cpt);
} |
d09c355
to
d3af460
Compare
@@ -0,0 +1,33 @@ | |||
gap> START_TEST("CyclesFromList") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing a semicolon, hence the test fails.
You can test the .tst file locally using Test()
, just do
Test("tst/testinstall/opers/CyclesFromList.tst");
(adjust the path depending on from where you run GAP)
Add a convenient functionality to generate a cycle from a list of positive integers.
The addition of CycleFromList uncovered a bug in CYCLE_TRANS_INT. This patch by Max Horn hopefully fixes that. His failure description (abbreviated) was: The problem is that `AssPlist` can trigger a GC. The change by chance happened to fill the heap in such a way that a GC happened at that spot
d3af460
to
9645f93
Compare
Add a convenient functionality to generate a cycle from a list of
positive integers.