-
-
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
Add range indexing to UniformScaling #24359
Conversation
It's kind of unsatisfying to have this type-unstable Maybe just always return |
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.
Just a few minor changes. 👍
Interestingly, this should also work for negative indices. At first I thought about requesting a bounds check there, but given that |
@mbauman Thanks for the review! ❤️ That it works for negative indices was intentional, since integer indexing works that way. Any other infinite-dimensional abstract matrix could also allow arbitrary integer indexing, so I see no good argument for enforcing strictly positive indexing. |
Do we want to resurrect this at some point? It occurred to me recently that it might be nice to have the related syntax |
@stevengj I updated the PR to include the indexing you suggested. I also had to change the behaviour of range indexing to return a dense array, since the separation of LinearAlgebra and SparseArrays meant that sparse functions were not available in the scope. I think it's better not to make LinearAlgebra depend on SparseArrays for this functionality? The implementation right now is about twice as fast as first instancing a diagonal identity matrix through |
Needs a NEWS item? |
@mbauman It is not entirely clear to me where to add the compat annotation. There are no existing docstrings for |
Ah, very good question. I agree about it not really belonging in julia/stdlib/LinearAlgebra/src/uniformscaling.jl Lines 9 to 10 in 147d5b1
It could be nice to say something about it acting somewhat matrix-like with some indexing supported but without an explicit |
Thanks! Not sure if I worded it right, but I added a docstring example that should give some idea about the kind of indexing that is supported. |
Looks great to me, thank you! |
Codecov Report
@@ Coverage Diff @@
## master JuliaLang/julia#24359 +/- ##
==========================================
+ Coverage 86.12% 86.14% +0.02%
==========================================
Files 348 348
Lines 64939 64971 +32
==========================================
+ Hits 55928 55970 +42
+ Misses 9011 9001 -10
Continue to review full report at Codecov.
|
* Add range indexing to UniformScaling * Add tests * Return sparse matrix when indexing UniformScaling * start -> first * Correctly handle non-integer steps * Make getindex(::UniformScaling, ranges...) return a dense array * Remove unneccessary (and slower) branch * Add (range, integer) indexing to UniformScaling * Update tests * Fix unbound param * Add NEWS item * Update docstring and add compat annotation Co-authored-by: Evey Dee <[email protected]>
Should we make |
Seems like the only sane definition to me, so 👍 |
Ref: JuliaLang/LinearAlgebra.jl#454. I thought this might be a usable alternative to
eye
and having callableUniformScaling
.