-
-
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
LinearAlgebra.norm(x::Union{Transpose, Adjoint})
should default to norm(parent(x))
#49020
Conversation
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
Is there any risk that this might be too generic? @andreasnoack @stevengj |
Needs a test? |
Added some tests for vectors and matrices of common element types, as well as for nested vectors/matrices. Let me know if checking |
I would check |
Done 👍 |
Looks like tests sometimes fail when using |
Perhaps a short note in the NEWS file to say that |
Great, NEWS file is updated now. |
One failing test is clearly unrelated, the other one (a segmentation fault) occurs in |
LinearAlgebra.norm(x::Union{Transpose, Adjoint})
should default to norm(parent(x))
for matricesLinearAlgebra.norm(x::Union{Transpose, Adjoint})
should default to norm(parent(x))
Regarding the CUDA issue in the original post, do you have any advice on how to incorporate a patch in the meantime? @maleadt and I were discussing a patch to if VERSION < CUTOFF
for trtype in (:Transpose, :Adjoint)
@eval LinearAlgebra.norm(x::$trtype{<:Any, <:AbstractGPUArray}, p::Real = 2) = norm(parent(v), p)
end
end But I'm not sure what an appropriate cutoff version would be. For example, is there any chance this patch makes it into 1.9? |
As this isn't really a bugfix, I think, backporting it to 1.9 is unlikely at this point. To find out the exact cutoff, you can use the |
…`norm(parent(x))` (JuliaLang#49020)
Currently, if
x
is theadjoint
ortranspose
of anAbstractVector
, thennorm(x)
will default tonorm(parent(x))
. This PR extends this behaviour to includeAbstractMatrix
s, as well.I don't think this should be consider breaking. It is true by the definition of
norm
- which is invariant to permutation and/or conjugation of the underlying array elements - thatnorm(x) == norm(parent(x))
should hold.For reference, I ran into this issue in the wild. When
x
is anadjoint
of aCuMatrix
,norm(x)
falls back to the generic implementation and throws an error. While this could easily be patched inCUDA.jl
, I think it is more correct and convenient to have this fallback inBase
. Currently, it is not possible to fix this in one's own code without type piracy.