From ba8098f06cc8cf6924f43addbca18ce4998330ec Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Tue, 24 Mar 2020 09:46:47 -0400 Subject: [PATCH] Tests for LinearAlgebra.powm (#35101) Co-authored-by: Daniel Karrasch --- stdlib/LinearAlgebra/src/triangular.jl | 4 ++-- stdlib/LinearAlgebra/test/triangular.jl | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/stdlib/LinearAlgebra/src/triangular.jl b/stdlib/LinearAlgebra/src/triangular.jl index f21a4421cf6007..408dc391a89c13 100644 --- a/stdlib/LinearAlgebra/src/triangular.jl +++ b/stdlib/LinearAlgebra/src/triangular.jl @@ -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) @@ -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 diff --git a/stdlib/LinearAlgebra/test/triangular.jl b/stdlib/LinearAlgebra/test/triangular.jl index 57148ee3294589..ca76408e9711f8 100644 --- a/stdlib/LinearAlgebra/test/triangular.jl +++ b/stdlib/LinearAlgebra/test/triangular.jl @@ -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