Skip to content

Commit

Permalink
LinearAlgebra.norm(x::Union{Transpose, Adjoint}) should default to …
Browse files Browse the repository at this point in the history
…`norm(parent(x))` (#49020)
  • Loading branch information
jondeuce authored Mar 22, 2023
1 parent 5f5d204 commit 70f6f7f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Standard library changes
`Factorization` ([#46874]).
* New functions `hermitianpart` and `hermitianpart!` for extracting the Hermitian
(real symmetric) part of a matrix ([#31836]).
* The `norm` of the adjoint or transpose of an `AbstractMatrix` now returns the norm of the
parent matrix by default, matching the current behaviour for `AbstractVector`s ([#49020]).

#### Printf
* Format specifiers now support dynamic width and precision, e.g. `%*s` and `%*.*g` ([#40105]).
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ opnorm(v::AdjointAbsVec, q::Real) = q == Inf ? norm(conj(v.parent), 1) : norm(co
opnorm(v::AdjointAbsVec) = norm(conj(v.parent))
opnorm(v::TransposeAbsVec) = norm(v.parent)

norm(v::Union{TransposeAbsVec,AdjointAbsVec}, p::Real) = norm(v.parent, p)
norm(v::AdjOrTrans, p::Real) = norm(v.parent, p)

"""
dot(x, y)
Expand Down
18 changes: 18 additions & 0 deletions stdlib/LinearAlgebra/test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ end
@test norm(x, 3) cbrt(5^3 +sqrt(5)^3)
end

@testset "norm of transpose/adjoint equals norm of parent #32739" begin
for t in (transpose, adjoint), elt in (Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat})
# Vector/matrix of scalars
for sz in ((2,), (2, 3))
A = rand(elt, sz...)
Aᵀ = t(A)
@test norm(Aᵀ) norm(Matrix(Aᵀ))
end

# Vector/matrix of vectors/matrices
for sz_outer in ((2,), (2, 3)), sz_inner in ((3,), (1, 2))
A = [rand(elt, sz_inner...) for _ in CartesianIndices(sz_outer)]
Aᵀ = t(A)
@test norm(Aᵀ) norm(Matrix(Matrix.(Aᵀ)))
end
end
end

@testset "rotate! and reflect!" begin
x = rand(ComplexF64, 10)
y = rand(ComplexF64, 10)
Expand Down

0 comments on commit 70f6f7f

Please sign in to comment.