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 in ShortestVectors for issue #838 #839

Closed
wants to merge 1 commit into from

Conversation

dimpase
Copy link
Member

@dimpase dimpase commented Jun 25, 2016

See #838 for details and an example to check.

This is needed if "positive" is set in a call to OrthogonalEmbeddings and the last vector c.vectors[anz] produced by the function ShortestVectors happens to be not non-negative. Then the lines rejecting it:

if checkpositiv and neg then
       c.vectors[anz] := [];
       anz := anz - 1;

leave an uncleared []last entry in c.vectors, resulting in the error mentioned in the issue at hand.

@olexandr-konovalov olexandr-konovalov changed the title fix for issue #838 fix in ShortestVectors for issue #838 Jun 27, 2016
@olexandr-konovalov
Copy link
Member

olexandr-konovalov commented Jun 27, 2016

Note that Thomas suggested in the Support list that "For correcting the bug, it would be sufficient to call 'Unbind' instead of assigning an empty list [in the local function 'vschr' inside the function 'ShortestVectors']; however, it would be better to rewrite the function completely."

@dimpase
Copy link
Member Author

dimpase commented Jun 27, 2016

@alex-konovalov : calling Unbind in a loop creates a lot of work for GASMAN, and it's not necessary. My patch produces an equivalent result and does not do this.

@frankluebeck
Copy link
Member

@dimpase: How can the creation of unnecessary objects and their assignment to list entries be more efficient for the garbage collection than just unbinding that list entry?

Also, your proposed change may cause the creation of an unnecessary shallow copy of the list in .vectors, e.g. in the usual case where this function is not called with the "positive" argument.

@dimpase
Copy link
Member Author

dimpase commented Jul 2, 2016

@frankluebeck : there is at most one unnecessary object (list entry in .vectors) created in the current loop implementation, and it should stay this way.

Although I agree that my one-liner might be more efficiently implemented as conditional unbinding of the last entry of the list in .vectors. If this would be acceptable as the fix I can do this.

@markuspf
Copy link
Member

markuspf commented Jul 2, 2016

Any (supposed) performance implication can surely easily be shown to (not) exist by an appropriate test and benchmark.

I wonder though what kind of "complete rewrite" is meant.

@olexandr-konovalov olexandr-konovalov added this to the GAP 4.9.0 milestone Aug 4, 2016
@olexandr-konovalov olexandr-konovalov added the kind: bug Issues describing general bugs, and PRs fixing them label Sep 20, 2016
@olexandr-konovalov
Copy link
Member

Just to remind everyone - this is still open, and we need to review this and either approve or submit an alternative solution.

@dimpase
Copy link
Member Author

dimpase commented Nov 8, 2016

How much effort does it take to review a 1-line patch clearing out an empty last entry of a list, produced under certain conditions I explained in some detail above? I'm turning 53 today, give me a birthday present by reviewing it :-)

@ChrisJefferson
Copy link
Contributor

ChrisJefferson commented Nov 8, 2016

I don't understand why you aren't using Unbind, if you just want to get rid of a value. I can assure you, Unbind has no cost, beyond setting a pointer to 0.

@markuspf
Copy link
Member

markuspf commented Nov 8, 2016

That example in #838 takes ages to verify. Do you have a shorter running one? This needs test-cases that don't run for minutes (or hours).

In particular if anyone is going to try to "rewrite the function completely" at any point.

@dimpase
Copy link
Member Author

dimpase commented Nov 8, 2016

There is an example suggested there that takes about 5 seconds on a modern laptop:

g:=
[ [ 12, 4, 4, 4, 4, 4, 0, 0, 0, 0 ], [ 4, 8, 0, 0, 0, 0, 0, 0, 0, 0 ],
  [ 4, 0, 8, 0, 0, 0, 4, 0, 0, 0 ], [ 4, 0, 0, 8, 0, 0, 0, 4, 0, 0 ],
  [ 4, 0, 0, 0, 8, 0, 0, 0, 4, 0 ], [ 4, 0, 0, 0, 0, 8, 0, 0, 0, 4 ],
  [ 0, 0, 4, 0, 0, 0, 12, 0, 0, 0 ], [ 0, 0, 0, 4, 0, 0, 0, 12, 0, 0 ],
  [ 0, 0, 0, 0, 4, 0, 0, 0, 12, 0 ], [ 0, 0, 0, 0, 0, 4, 0, 0, 0, 12 ] ];;
m:=10;; r := OrthogonalEmbeddings((1/2)*g{[1..m]}{[1..m]}, "positive");

(and on unpatched code it finishes in no time with the error)

Please tell me where is should go in the testsuite, I'll add it there.

@markuspf markuspf mentioned this pull request Nov 8, 2016
markuspf added a commit that referenced this pull request Nov 9, 2016
* Fix an edge case in ShortestVectors when an empty list could be left when "positive" is given as a parameter to ShortestVectors.
* Add a test.

Closes: #838 #839
@markuspf markuspf closed this Nov 9, 2016
@dimpase
Copy link
Member Author

dimpase commented Nov 9, 2016

@ChrisJefferson : I prefer functional style code, that's why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Issues describing general bugs, and PRs fixing them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants