-
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
Add much faster IsOne
method for matrices
#5342
Add much faster IsOne
method for matrices
#5342
Conversation
Also add similar IsOne and IsZero methods for rowlist matobj
|
||
ncols:= NrCols( mat ); | ||
for row in mat do | ||
if PositionNonZero( row ) <= ncols 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 was going to suggest that this might be clearer if it was:
if PositionNonZero( row ) <= ncols then | |
if PositionNonZero( row ) <> fail then |
only to discover that PositionNonZero
returns Length(row) + 1
if no non-zero is located. Is this intentional, it seems to be at odds with Position
.
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.
The documentation says that PositionNonZero
is a special case of PositionNot
, and PositionNot
treats unbound entries as "not the element which shall be avoided".
if PositionNonZero( row ) <> i or not IsOne( row[i] ) then | ||
return false; | ||
fi; | ||
if PositionNonZero( row, i ) <= ncols 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.
Think you might have copy pasted lines 1408 to 1410 from IsZero
here, this can't be right.
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.
Sorry my mistake.
if PositionNonZero( row, i ) <= ncols then | ||
return false; | ||
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.
if PositionNonZero( row, i ) <= ncols then | |
return false; | |
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.
Same copy paste error as above.
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.
Sorry I'm mistaken, this is correct, thanks to @ThomasBreuer for pointing this out.
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.
Looks good apart from the copy paste errors indicated. with no changes!
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.
Good.
(I will change the available IsOne
method in matobjplist.gi
accordingly, in an update of my pull request #5340.)
as in pull request gap-system#5342 for other `IsOne` methods
as in pull request #5342 for other `IsOne` methods
IsOne
method for matrices
Also add similar IsOne and IsZero methods for rowlist matobj
Resolves #5341 by @hulpke
Example (before these took veery long... I didn't time it, but let's say closer to minutes than to milliseconds):