From 4f65a4acfd62ee3bf667a982262ef991c4afd0ac Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 8 Jul 2024 20:00:42 +0530 Subject: [PATCH] LinearAlgebra: LazyString in error messages for Diagonal/Bidiagonal --- stdlib/LinearAlgebra/src/bidiag.jl | 18 +++++++++--------- stdlib/LinearAlgebra/src/diagonal.jl | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/stdlib/LinearAlgebra/src/bidiag.jl b/stdlib/LinearAlgebra/src/bidiag.jl index f0d04f121d48f..7a51b0dbfb7c4 100644 --- a/stdlib/LinearAlgebra/src/bidiag.jl +++ b/stdlib/LinearAlgebra/src/bidiag.jl @@ -191,8 +191,8 @@ end elseif A.uplo == 'L' && (i == j + 1) @inbounds A.ev[j] = x elseif !iszero(x) - throw(ArgumentError(string("cannot set entry ($i, $j) off the ", - "$(istriu(A) ? "upper" : "lower") bidiagonal band to a nonzero value ($x)"))) + throw(ArgumentError(LazyString(lazy"cannot set entry ($i, $j) off the ", + istriu(A) ? "upper" : "lower", " bidiagonal band to a nonzero value ", x))) end return x end @@ -320,7 +320,7 @@ function _copyto_banded!(A::Bidiagonal, B::Bidiagonal) else zeroband = istriu(A) ? "lower" : "upper" uplo = A.uplo - throw(ArgumentError(string("cannot set the ", + throw(ArgumentError(LazyString("cannot set the ", zeroband, " bidiagonal band to a nonzero value for uplo=:", uplo))) end return A @@ -373,8 +373,8 @@ ishermitian(M::Bidiagonal) = isdiag(M) && all(ishermitian, M.dv) function tril!(M::Bidiagonal{T}, k::Integer=0) where T n = length(M.dv) if !(-n - 1 <= k <= n - 1) - throw(ArgumentError(string("the requested diagonal, $k, must be at least ", - "$(-n - 1) and at most $(n - 1) in an $n-by-$n matrix"))) + throw(ArgumentError(LazyString(lazy"the requested diagonal, $k, must be at least ", + lazy"$(-n - 1) and at most $(n - 1) in an $n-by-$n matrix"))) elseif M.uplo == 'U' && k < 0 fill!(M.dv, zero(T)) fill!(M.ev, zero(T)) @@ -392,8 +392,8 @@ end function triu!(M::Bidiagonal{T}, k::Integer=0) where T n = length(M.dv) if !(-n + 1 <= k <= n + 1) - throw(ArgumentError(string("the requested diagonal, $k, must be at least", - "$(-n + 1) and at most $(n + 1) in an $n-by-$n matrix"))) + throw(ArgumentError(LazyString(lazy"the requested diagonal, $k, must be at least", + lazy"$(-n + 1) and at most $(n + 1) in an $n-by-$n matrix"))) elseif M.uplo == 'L' && k > 0 fill!(M.dv, zero(T)) fill!(M.ev, zero(T)) @@ -418,8 +418,8 @@ function diag(M::Bidiagonal{T}, n::Integer=0) where T elseif -size(M,1) <= n <= size(M,1) return fill!(similar(M.dv, size(M,1)-abs(n)), zero(T)) else - throw(ArgumentError(string("requested diagonal, $n, must be at least $(-size(M, 1)) ", - "and at most $(size(M, 2)) for an $(size(M, 1))-by-$(size(M, 2)) matrix"))) + throw(ArgumentError(LazyString(lazy"requested diagonal, $n, must be at least $(-size(M, 1)) ", + lazy"and at most $(size(M, 2)) for an $(size(M, 1))-by-$(size(M, 2)) matrix"))) end end diff --git a/stdlib/LinearAlgebra/src/diagonal.jl b/stdlib/LinearAlgebra/src/diagonal.jl index 5b28432fdb520..1ff7d371043ee 100644 --- a/stdlib/LinearAlgebra/src/diagonal.jl +++ b/stdlib/LinearAlgebra/src/diagonal.jl @@ -254,8 +254,8 @@ end function tril!(D::Diagonal{T}, k::Integer=0) where T n = size(D,1) if !(-n - 1 <= k <= n - 1) - throw(ArgumentError(string("the requested diagonal, $k, must be at least ", - "$(-n - 1) and at most $(n - 1) in an $n-by-$n matrix"))) + throw(ArgumentError(LazyString(lazy"the requested diagonal, $k, must be at least ", + lazy"$(-n - 1) and at most $(n - 1) in an $n-by-$n matrix"))) elseif k < 0 fill!(D.diag, zero(T)) end