Improve isassigned implementation#49827
Merged
vtjnash merged 5 commits intoJuliaLang:masterfrom May 20, 2023
Merged
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.
Contributor
Author
|
Looks like updating the branch fixed the test |
vtjnash
reviewed
May 20, 2023
|
|
||
| ## indexing | ||
|
|
||
| isassigned(r::AbstractRange, i::Int) = firstindex(r) <= i <= lastindex(r) |
Member
There was a problem hiding this comment.
Is this true for StepRange? I think it might only be true for Unit ranges
Contributor
Author
There was a problem hiding this comment.
I'm not aware of an instance where it could produce an undefined variable
Member
There was a problem hiding this comment.
oh, right, I was thinking of values, not index
longemen3000
reviewed
Jul 5, 2023
| end | ||
|
|
||
| @inline function Base.isassigned(A::Tridiagonal, i::Int, j::Int) | ||
| @boundscheck checkbounds(A, i, j) |
Contributor
There was a problem hiding this comment.
is this ok? in all other isassigned implementations, this returns false if the bound check fails, but this throws an error?
Contributor
Author
There was a problem hiding this comment.
You're right. That should be fixed
vtjnash
pushed a commit
that referenced
this pull request
Jul 10, 2023
KristofferC
pushed a commit
that referenced
this pull request
Jul 11, 2023
…50488) See #49827 (comment) (cherry picked from commit e2e34f6)
KristofferC
pushed a commit
to JuliaLang/LinearAlgebra.jl
that referenced
this pull request
Nov 14, 2024
KristofferC
pushed a commit
to JuliaLang/LinearAlgebra.jl
that referenced
this pull request
Dec 2, 2024
…(#50488) See JuliaLang/julia#49827 (comment) (cherry picked from commit e2e34f6987d93ed5b80259c2af5a33c888180043) (cherry picked from commit d6eaa7c095b576433fb482bfbf23934b1683583f)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unless
isassignedis called onArraywithInts, it uses a try catch, which makesisassignedpretty slow (#44720). This PR provides changes the default implementation ofisassignedto coerce the indices provided toInts and converts to linear or cartesian indices, depending on the arraysIndexStyle. This also overloadsisassignedfor many of the array types defined in Base.