-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
findprev: use zero(eltype(A)) instead of 0 #18709
Conversation
What was the issue here? |
Some types don't implement comparison/promotion with Int64, or if they do, it's not what you want, e.g.
because
(arguable that should have been an error instead) |
@@ -1111,7 +1111,7 @@ julia> findprev(A,1) | |||
""" | |||
function findprev(A, start::Integer) | |||
for i = start:-1:1 | |||
A[i] != 0 && return i | |||
A[i] != zero(eltype(A)) && return 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.
Might be worth making this zero(A[i])
in case eltype(A)=Any
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.
Fair point.
Not sure what happened here. I neither merged nor closed this. |
end | ||
return 0 | ||
end | ||
|
||
""" | ||
findlast(A) | ||
|
||
Return the linear index of the last non-zero value in `A` (determined by `A[i]!=0`). | ||
Return the linear index of the last non-zero value in `A` (determined by `A[i]!=zero(A[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.
needs a genstdlib run
If we're going to try to support these sort of things it would be good to make a formal specification of the interfaces that need to be supported. As part of my current work I've been creating yet another unitful computation package, and so I've hit a few of these issues as well. The current pattern is used in quite a few places throughout Base, as there are some cases where it is more efficient (e.g. |
x-ref #15755 |
Seems like we should define an |
Are we sure we want |
@nalimilan. Yes. |
Out of curiosity, why change |
Superseded by the find rework stuff. |
No description provided.