Skip to content

Commit 70f6f7f

Browse files
authored
LinearAlgebra.norm(x::Union{Transpose, Adjoint}) should default to norm(parent(x)) (#49020)
1 parent 5f5d204 commit 70f6f7f

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Standard library changes
6969
`Factorization` ([#46874]).
7070
* New functions `hermitianpart` and `hermitianpart!` for extracting the Hermitian
7171
(real symmetric) part of a matrix ([#31836]).
72+
* The `norm` of the adjoint or transpose of an `AbstractMatrix` now returns the norm of the
73+
parent matrix by default, matching the current behaviour for `AbstractVector`s ([#49020]).
7274

7375
#### Printf
7476
* Format specifiers now support dynamic width and precision, e.g. `%*s` and `%*.*g` ([#40105]).

stdlib/LinearAlgebra/src/generic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ opnorm(v::AdjointAbsVec, q::Real) = q == Inf ? norm(conj(v.parent), 1) : norm(co
805805
opnorm(v::AdjointAbsVec) = norm(conj(v.parent))
806806
opnorm(v::TransposeAbsVec) = norm(v.parent)
807807

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

810810
"""
811811
dot(x, y)

stdlib/LinearAlgebra/test/generic.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ end
269269
@test norm(x, 3) cbrt(5^3 +sqrt(5)^3)
270270
end
271271

272+
@testset "norm of transpose/adjoint equals norm of parent #32739" begin
273+
for t in (transpose, adjoint), elt in (Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat})
274+
# Vector/matrix of scalars
275+
for sz in ((2,), (2, 3))
276+
A = rand(elt, sz...)
277+
Aᵀ = t(A)
278+
@test norm(Aᵀ) norm(Matrix(Aᵀ))
279+
end
280+
281+
# Vector/matrix of vectors/matrices
282+
for sz_outer in ((2,), (2, 3)), sz_inner in ((3,), (1, 2))
283+
A = [rand(elt, sz_inner...) for _ in CartesianIndices(sz_outer)]
284+
Aᵀ = t(A)
285+
@test norm(Aᵀ) norm(Matrix(Matrix.(Aᵀ)))
286+
end
287+
end
288+
end
289+
272290
@testset "rotate! and reflect!" begin
273291
x = rand(ComplexF64, 10)
274292
y = rand(ComplexF64, 10)

0 commit comments

Comments
 (0)