-
Notifications
You must be signed in to change notification settings - Fork 160
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 PositionMaximum and PositionMinimum #956
Add PositionMaximum and PositionMinimum #956
Conversation
a0f8699
to
8c20e4f
Compare
Current coverage is 48.75% (diff: 100%)@@ master #956 diff @@
==========================================
Files 424 424
Lines 222125 222167 +42
Methods 3430 3430
Messages 0 0
Branches 0 0
==========================================
- Hits 108344 108315 -29
- Misses 113781 113852 +71
Partials 0 0
|
Looks sensible and fine to me. |
## <#GAPDoc Label="PositionMaximum"> | ||
## <ManSection> | ||
## <Oper Name="PositionMaximum" Arg='list [, func]'/> | ||
## <Oper Name="PositionMinimum" Arg='list [, func]'/> |
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.
It does not invalidate GAPDoc, but since both PositionMaximum
and PositionMinimum
are functions, it would be more consistent to use Func
instead of Oper
in <Oper Name="PositionMaximum" Arg='list [, func]'/>
(there is even an automated check for such things added in #538).
if Length(args) = 2 then | ||
func := args[2]; | ||
else | ||
func := x -> x; |
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.
Maybe use IdFunc
here as in the previous function?
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.
Certainly should use IdFunc here
bestindex := fail; | ||
for i in [ 1 .. Length( list ) ] do | ||
if IsBound( list[i] ) then | ||
ival := func ( list[ i ] ); |
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.
Should we be concerned about performance and treat the 1-argument case differently to avoid calling IdFunc
on each element of the list?
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.
IdFunc
is very fast. It might speed it up a little, but at the cost of twice as much, almost identical, code.
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.
Ok, then let's fix GAPDoc elements and use IdFunc
in both functions, and merge this...
8c20e4f
to
7e57162
Compare
Write below the description of changes (for the release notes)
This adds the new methods
PositionMaximum
andPositionMinimum
, which returns the index of the largest element of a list. It also can be used to find the largest element under some function.I have had this function privately for some time, and often use it myself. For example, finding the largest element of a list
l
of groups can be done byl[PositionMaximum(l, Size)]
, whereas I don't know of any other short way of doing this in GAP (if I've missed a method somewhere, please tell me).