-
-
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
make I(n) behave as Diagonal
/ eye
?
#23156
Comments
What advantage does this have? Functions are pretty special (sure they are objects but they are very special ones) so I don't think functions being callable is a good arguments for this. It's a good argument for not implementing algebra or other operations on functions if anything. The syntax will also be really confusing with juxtapose multiplication when you have both
|
You can do |
As in similar places: What problem is solved by this? |
When I heard |
We currently have |
I kind of think we should double down on the whole |
|
I'm also fine with |
@StefanKarpinski "I kind of think we should double down … and make Z a binding for 0I " |
|
This issue as stated is not breaking, so doesn't belong on the milestone. However, it has been brought up previously that we may want to get rid of |
I would deprecate |
Note that |
@Sacha0 has agreed to give replacing |
To start I skimmed through all
Where Replacing
Methods for comparison against identity ( |
I'm curious, how often did you encounter calls like |
Fantastic question! In the Similarly, I found only three uses of -(+)(A::SparseMatrixCSC, J::UniformScaling) = A + J.λ * speye(A)
-(-)(A::SparseMatrixCSC, J::UniformScaling) = A - J.λ * speye(A)
-(-)(J::UniformScaling, A::SparseMatrixCSC) = J.λ * speye(A) - A
+(+)(A::SparseMatrixCSC, J::UniformScaling) = A + sparse(J, size(A)...)
+(-)(A::SparseMatrixCSC, J::UniformScaling) = A - sparse(J, size(A)...)
+(-)(J::UniformScaling, A::SparseMatrixCSC) = sparse(J, size(A)...) - A As shown, those uses are perhaps better written So perhaps deprecating I will keep this question in mind while reviewing uses of |
On second thought, with the future |
Another observation: About a third of So while most of those test could be nicely rewritten as |
Additional observations. Most
For purposes (3) and (4), |
For computations of eigen and singular vectors you'd like to be able to specify the element type. It could be |
Sounds good on this end! :) |
Alternate issue title: An I for an eye. |
With #24438 and the other pull requests linked above in, this issue should be set :). |
I think we should consider having |
I agree. (says the teacher of large linear algebra classes) |
It's a little weird that calling an instance of UniformScaling creates an instance of Matrix, but 🤷♂️. It does seem quite convenient and intuitive, so 👍. |
This keeps coming up—let's do it. |
Also useful for tensor products |
Re: implementation, how about adding a lazy non-allocating representation of (σ::UniformScaling)(n::Integer) = Diagonal(UniformVector(σ.λ, n))
|
Some comments:
My guess is that having Allocation is not always slower than a lazily evaluated object (BBN-Q/QuantumInfo.jl#3):
|
Stefan said above to do this, so I fixed the milestone. |
Since there is no PR for this yet I think it needs to be moved to the next milestone. |
It might be nice if we made
I
callable so that you can writeI(10)
and get a 10x10 Diagonal matrix object. Of course it's a bit weird to call one kind of object and get another, but we do that with functions all the time so maybe that's no problem. Possible definition:With this definition, we could potentially deprecate
eye(n)
(which is usually quite inefficient) in favor ofI(n)
when one doesn't need to mutate any off-diagonals orfull(I(n))
in the cases where one does need to mutate an off-diagonal.The text was updated successfully, but these errors were encountered: