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

changed the definition of Randomize #3619

Merged
merged 2 commits into from
Aug 23, 2019

Conversation

ThomasBreuer
Copy link
Contributor

@ThomasBreuer ThomasBreuer commented Aug 22, 2019

As proposed in lib/matobj2.gd:
For a random source rs,
document Randomize( rs, obj ) instead of Randomize( obj, rs ),
and then use InstallMethodWithRandomSource to install methods.

The release notes should mention this change mainly because Randomize is used in a few packages.
Another aspect is that after the change, results of Randomize from older GAP sessions may not be reproducible because former calls of the form Random( C ) are now executed as Random( GlobalMersenneTwister, C ).

Details:

  • added an <Oper Name="Random" .../> declaration for
    random source and collection, to be used in cross-references;
    note that the DeclareOperation calls had covered this already.

  • added Randomize to the documented operations for which
    the function InstallMethodWithRandomSource is intended

  • used InstallMethodWithRandomSource in order to replace
    two method installations by just one (as was proposed in
    matobj2.gd) for all installations of Randomize methods
    in the GAP library

  • make sure that all Randomize methods return the changed object

  • adjusted outputs of the testfile
    testinstall/MatrixObj/Randomize.tst
    (one instance of the changed outputs mentioned above)

Resolves #2018

As proposed in `lib/matobj2.gd`:
For a random source `rs`,
document `Randomize( rs, obj )` instead of `Randomize( obj, rs )`,
and then use `InstallMethodWithRandomSource` to install methods.

Note that after these changes,
results of `Randomize` from older GAP sessions may not be
reproducible because former calls of the form `Random( C )`
are now executed as `Random( GlobalMersenneTwister, C )`.

- added an `<Oper Name="Random" .../>` declaration for
  random source and collection, to be used in cross-references;
  note that the `DeclareOperation` calls had covered this already.

- added `Randomize` to the documented operations for which
  the function `InstallMethodWithRandomSource` is intended

- used `InstallMethodWithRandomSource` in order to replace
  two method installations by just one (as was proposed in
  `matobj2.gd`) for all installations of `Randomize` methods
  in the GAP library

- make sure that all `Randomize` methods return the changed object

- adjusted outputs of the testfile
  `testinstall/MatrixObj/Randomize.tst`
  (one instance of the changed outputs mentioned above)
@ThomasBreuer ThomasBreuer added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: library release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes gapsingular2019 Issues and PRs that arose at https://opendreamkit.org/meetings/2019-04-02-GAPSingularMeeting labels Aug 22, 2019
@codecov
Copy link

codecov bot commented Aug 22, 2019

Codecov Report

Merging #3619 into master will decrease coverage by 12.36%.
The diff coverage is 72.91%.

@@             Coverage Diff             @@
##           master    #3619       +/-   ##
===========================================
- Coverage   84.64%   72.27%   -12.37%     
===========================================
  Files         698      635       -63     
  Lines      345549   308785    -36764     
===========================================
- Hits       292482   223173    -69309     
- Misses      53067    85612    +32545
Impacted Files Coverage Δ
lib/random.gd 91.3% <ø> (-8.7%) ⬇️
lib/matobj2.gd 100% <100%> (ø) ⬆️
lib/matobj.gi 65.49% <50%> (-1.02%) ⬇️
lib/matobjplist.gi 50.47% <80%> (+0.11%) ⬆️
lib/vec8bit.gi 78.15% <85.71%> (-1.8%) ⬇️
lib/vecmat.gi 83.56% <85.71%> (-2.8%) ⬇️
lib/teachm2.g 15.38% <0%> (-84.62%) ⬇️
lib/ctblauto.gi 5.98% <0%> (-83.67%) ⬇️
lib/helpt2t.gi 0.23% <0%> (-83.14%) ⬇️
lib/proto.gi 1.03% <0%> (-82.48%) ⬇️
... and 385 more

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks fine, some minor remarks / questions.

InstallMethodWithRandomSource( Randomize,
"for a random source and a mutable gf2 vector",
[ IsRandomSource, IsGF2VectorRep and IsMutable ],
function( rs, v )
local i;
MultVector(v,0);
for i in [1..Length(v)] do
if Random(rs,0,1) = 1 then v[i] := Z(2); fi;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant for this PR, but: this is something which probably would be several orders of magnitudes faster if done in C, as we could just generate random data in larger chunks (e.g. 64 bits at a time) and initialize the memory with it as needed, instead of iterating over each bit.

vec[ i ] := Random( rs, basedomain );
InstallMethodWithRandomSource( Randomize,
"for a random source and a matrix object",
[ IsRandomSource, IsMatrixObj and IsMutable ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code this replaces was using IsVectorObj, and now here is IsMatrixObj? Am I missing something? Aha, perhaps this is simply a new function that was not present before, and the diff is therefore misleading? In that case, it would be nice if the commit message / PR description explicitly mentioned this new functionality (but it's not super important either, it's just a suggestion).

lib/matobj.gi Outdated
basedomain := BaseDomain( mat );
for i in [ 1 .. NrRows( mat ) ] do
for j in [ 1 .. NrCols( mat ) ] do
mat[i][j]:= Random( rs, basedomain );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mat[i][j]:= Random( rs, basedomain );
mat[i,j]:= Random( rs, basedomain );

InstallOtherMethod( Randomize,
"backwards compatibility: swap arguments",
[ IsObject and IsMutable, IsRandomSource ],
{ obj, rs } -> Randomize( rs, obj ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This compatibility method ensures that existing code using Randomize will keep working, and can thus be adapted incrementally -- very good. However, existing implementations will need to be adapted, else they won't get called... I don't see a good alternative to this, anyway (other than installing another method which swaps the arguments in another order, and then perhaps also a horrible hack which prevents us from doing an infinite recursion in case no specialized method is provided). Luckily, only three packages provide such methods: cvec and recog (which I'll both adapt now, and make releases), and also meataxe64, but that's not yet deposited and I am sure @stevelinton will be happy to adapt it, resp. we can provide a PR. (And by adapting, I mean I'll install methods for both argument orders, this way the packages will work with both old and new GAP versions).

## Replaces every entry in the mutable vector object <A>v</A>
## or matrix object <A>m</A>, respectively, with
## a random one from the base domain of <A>v</A> or <A>m</A>,
## respectively, and returns the argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the documentation in orb says that nothing is returned. I prefer your variant, though, it is useful in some situations. However, this is one more thing that needs to be adapted in recog, cvec and meataxe64. (I'll look into doing that right now).

and fixed some `[i][j]` occurrences
@ThomasBreuer ThomasBreuer merged commit b468080 into gap-system:master Aug 23, 2019
@coveralls
Copy link

coveralls commented Aug 24, 2019

Coverage Status

Coverage increased (+0.004%) to 84.398% when pulling db97a1f on ThomasBreuer:TB_Randomize into f5dfccf on gap-system:master.

@dimpase dimpase added release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Feb 4, 2020
@olexandr-konovalov olexandr-konovalov added this to the GAP 4.11.0 milestone Feb 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gapsingular2019 Issues and PRs that arose at https://opendreamkit.org/meetings/2019-04-02-GAPSingularMeeting kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: added PRs introducing changes that have since been mentioned in the release notes topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Randomize is declared and implemented in the GAP library, but documentation is in orb package
5 participants