Skip to content

Commit

Permalink
Tests for LinearAlgebra.powm (JuliaLang#35101)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Karrasch <[email protected]>
  • Loading branch information
kshyatt and dkarrasch authored Mar 24, 2020
1 parent e7a9474 commit 9f08f88
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ end
# 34(3), (2013) 1341–1360.
function powm!(A0::UpperTriangular{<:BlasFloat}, p::Real)
if abs(p) >= 1
ArgumentError("p must be a real number in (-1,1), got $p")
throw(ArgumentError("p must be a real number in (-1,1), got $p"))
end

normA0 = opnorm(A0, 1)
Expand Down Expand Up @@ -2239,7 +2239,7 @@ function powm!(A0::UpperTriangular{<:BlasFloat}, p::Real)
rmul!(S, normA0^p)
return S
end
powm(A::LowerTriangular, p::Real) = copy(transpose(powm(copy(transpose(A)), p::Real)))
powm(A::LowerTriangular, p::Real) = copy(transpose(powm!(copy(transpose(A)), p::Real)))

# Complex matrix logarithm for the upper triangular factor, see:
# Al-Mohy and Higham, "Improved inverse scaling and squaring algorithms for
Expand Down
10 changes: 10 additions & 0 deletions stdlib/LinearAlgebra/test/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,14 @@ end
end
end

@testset "Error condition for powm" begin
A = UpperTriangular(rand(ComplexF64, 10, 10))
@test_throws ArgumentError LinearAlgebra.powm!(A, 2.2)
A = LowerTriangular(rand(ComplexF64, 10, 10))
At = copy(transpose(A))
p = rand()
@test LinearAlgebra.powm(A, p) == transpose(LinearAlgebra.powm!(At, p))
@test_throws ArgumentError LinearAlgebra.powm(A, 2.2)
end

end # module TestTriangular

0 comments on commit 9f08f88

Please sign in to comment.