-
Notifications
You must be signed in to change notification settings - Fork 175
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
true_pos #568
Comments
I think it would be useful. I like the name Perhaps controversial, but consider calling this function
which is similar to
A more concise form could be
Where would this function belong? Should we introduce a module for array helper functions, e.g. |
I also like If
suffice? |
Having both might be useful indeed, it is sometimes easier to formulate the
condition in a negative way.
Op wo 17 nov. 2021 om 16:30 schreef Ivan Pribec ***@***.***>:
… I also like trueloc better than true_pos. In MATLAB the function is
called find <https://de.mathworks.com/help/matlab/ref/find.html>, and
also has an optional argument for the number of elements to find.
If trueloc were to be the name, would it make sense to have falseloc too,
or does the form:
trueloc(A > B) ! find indexes of true values
trueloc(.not. (A > B)) ! find indexes of false values
suffice?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#568 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YRZ2S5RAZQWFKL75EJ3UMPDBJANCNFSM5IFL7KEA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
A quick test with GFortran 11 shows the following difference in timings for 1200 invocations of
|
Could you provide the details of your test prog, please? I wonder how would compare something like |
I don't know the details of the program, but |
Added the timing routines in #603 as well as a comparison with Also, included a |
Actually, with the flags |
I agree that Therefore I wouldn't be too concerned with the performance penalty. For the case of "simple" assignment depending upon a condition, the specs could contain a note suggesting |
In a Fortran Discourse thread Indexing arrays by an array of logicals I mentioned a
true_pos
function I had written to simulate logical indexing, and @ivan-pi suggested that it be considered for stdlib. To deal with the case of albound /= 1
mentioned by mecej4, I have added an optionallower_bound
argument. Iftf(:)
has the same size asx(:)
, one can writex(true_pos(tf))
to refer to elements of x wheretf
is.true.
One can also writepack(x,tf)
, but that cannot appear on the LHS of an assignment. I have usedtrue_pos
hundreds of times in my codes -- maybe it would be generally useful. Since Fortran hasminloc
,maxloc
, andfindloc
, maybetrue_pos
should be renamedtrueloc
.The text was updated successfully, but these errors were encountered: