-
Notifications
You must be signed in to change notification settings - Fork 175
Introduce MakeIsPlistVectorRep helper #5333
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
Introduce MakeIsPlistVectorRep helper #5333
Conversation
ThomasBreuer
left a comment
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.
Thanks, this fixes the problem which type is taken for the results, and simplifies further improvements.
I have added a few comments.
I think this pull request should be merged soon, afterwards we can address the open questions about caching, the mutability of results, and necessary consistency checks.
|
Wouldn't MakePlistVectorRep be a possibly better name? |
|
@james-d-mitchell concerning |
lib/matobjplist.gi
Outdated
| res := Objectify(TypeObj(v),[v![BDPOS],ShallowCopy(v![ELSPOS])]); | ||
| if not IsMutable(v) then SetFilterObj(res,IsMutable); fi; | ||
| return res; | ||
| return MakeIsPlistVectorRep(v![BDPOS], true, ShallowCopy(v![ELSPOS])); |
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.
Doesn't ShallowCopy return v when v is immutable, and only return a copy when v is mutable?
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.
If v is in the filter IsCopyable then ShallowCopy( v ) returns always a new object which is mutable.
If v is not in the filter IsCopyable then ShallowCopy( v ) returns v.
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.
Thanks @ThomasBreuer I didn't know this!
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.
see https://docs.gap-system.org/doc/ref/chap12_mj.html#X846BC7107C352031
(IsCopyable seems to be a not well-known concept in GAP. Perhaps the documentation should better explicitly mention IsCopyable instead of talking about "copyable objects" or "objects that support a mutable form".)
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.
Yeah, I've been working on GAP for years but only realized in 2022 (when Thomas told me) what it really does; I somehow never had read its documentation entry. It really means IsAbleToMakeMutableInstances or CanHaveMutableInstances so (I am not proposing a renaming, just sayin')
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've removed the mutable argument for MakeIsPlistVectorRep which should take care of this and other issues.
84415a4 to
d5d4390
Compare
|
Addressed comments, added benchmarks, added caching. Benchmark results before the changes in this PR (beware, these timings can fluctuate quite a bit): After the changes in this PR (so with caching): So the case were an "example" vector was given still is a bit slower. On the upside, the case were no example vector was given got faster. I am going to experiment a bit with using an operation to determine where to store the cache and for initializing it, so that it becomes easier to extend this for other cases, but this might be too expensive, we'll see. But first I have to teach now :-) |
|
BTW, I used |
|
Re |
... based on old MatrixObj benchmarks I wrote years ago. I think it's useful to also have the benchmarks (including the old ones) permanently in the repo, so that we can measure for regressions and also create new benchmarks more easily.
18e734c to
300d4a4
Compare
|
I've cleaned this up, rebased it, and marked it as "ready for review": while we still should do a similar changes for the |
This centralizes the creation of IsPlistVectorRep instances, reducing code duplication, and enabling future refactoring. It also fixes bugs caused by incorrect reusing of the TypeObj of a vector to create another vector; this introduces bugs because the type can store things like the value of `IsZero` which must not be carelessly copied over to a new vector with different content.
300d4a4 to
b6ec63b
Compare
This centralizes the creation of
IsPlistVectorRepinstances, reducing code duplication, and enabling future refactoring.It also fixes bugs caused by incorrect reusing of the TypeObj of a vector to create another vector; this introduces bugs because the type can store things like the value of
IsZerowhich must not be carelessly copied over to a new vector with different content.Resolves #5330
TODO:
IsPlistMatrixRepIsZmodnZVectorRepIsZmodnZMatrixRepIdeally for each of the four types, only a single place calling
Objectifyfor them would be left. This would then make further refactoring of their internal layout easy (for PR #5217)