Skip to content
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

Accept IndexStyle in diagind, defaulting to IndexLinear #52549

Merged
merged 3 commits into from
Dec 18, 2023

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Dec 15, 2023

Partly revert and redesign #52115, with diagind now accepting an optional IndexStyle, which is IndexLinear by default. This should address the breakages reported in that PR. After this,

julia> D = Diagonal(1:4)
4×4 Diagonal{Int64, UnitRange{Int64}}:
 1      
   2    
     3  
       4

julia> diagind(D)
1:5:16

julia> diagind(D, IndexCartesian())
StepRangeLen(CartesianIndex(1, 1), CartesianIndex(1, 1), 4)

@jishnub jishnub added linear algebra Linear algebra arrays [a, r, r, a, y, s] labels Dec 15, 2023
Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all internal usages of diagind? I assume so.

stdlib/LinearAlgebra/src/dense.jl Outdated Show resolved Hide resolved
Co-authored-by: Daniel Karrasch <[email protected]>
@jishnub
Copy link
Contributor Author

jishnub commented Dec 17, 2023

I didn't think of the diagind change as internal, as other matrix types such as BandedMatrices would also benefit from a Cartesian range

@dkarrasch
Copy link
Member

I meant the callsites, not the method definition itself. Like, have you optimized all "internal" calls to diagind? But since you have done that already in very different places, I was assuming that.

@jishnub
Copy link
Contributor Author

jishnub commented Dec 17, 2023

Oh alright, yes, I've updated the internal calls. Not all of them at the moment, as this only makes a difference if the rest of the operations are also O(N). As a matter of style, though, we might decide to change it everywhere. If we decide this, I'll make further changes that aren't strictly necessary for performance.

@jishnub jishnub merged commit df5361a into master Dec 18, 2023
7 checks passed
@jishnub jishnub deleted the jishnub/diagindIndexStyle branch December 18, 2023 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants