-
-
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
Improve isassigned
implementation
#49827
Conversation
Unless `isassigned` is called on `Array` with `Int`s, it uses a try catch, which is notoriously slow. This PR provides changes the default implementation of `isassigned` to coerce the indices provided to `Int`s and converts to linear or cartesian indices, depending on the arrays `IndexStyle`. This also overloads `isassigned` for many of the array types defined in Base.
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.
SGTM
Looks like updating the branch fixed the test |
@@ -901,6 +901,8 @@ end | |||
|
|||
## indexing | |||
|
|||
isassigned(r::AbstractRange, i::Int) = firstindex(r) <= i <= lastindex(r) |
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.
Is this true for StepRange? I think it might only be true for Unit ranges
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'm not aware of an instance where it could produce an undefined variable
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.
oh, right, I was thinking of values, not index
@@ -604,6 +617,19 @@ function diag(M::Tridiagonal{T}, n::Integer=0) where T | |||
end | |||
end | |||
|
|||
@inline function Base.isassigned(A::Tridiagonal, i::Int, j::Int) | |||
@boundscheck checkbounds(A, i, j) |
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.
is this ok? in all other isassigned
implementations, this returns false if the bound check fails, but this throws an error?
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.
You're right. That should be fixed
…50488) See #49827 (comment) (cherry picked from commit e2e34f6)
…(#50488) See JuliaLang/julia#49827 (comment) (cherry picked from commit e2e34f6987d93ed5b80259c2af5a33c888180043) (cherry picked from commit d6eaa7c095b576433fb482bfbf23934b1683583f)
Unless
isassigned
is called onArray
withInt
s, it uses a try catch, which makesisassigned
pretty slow (#44720). This PR provides changes the default implementation ofisassigned
to coerce the indices provided toInt
s and converts to linear or cartesian indices, depending on the arraysIndexStyle
. This also overloadsisassigned
for many of the array types defined in Base.