diff --git a/base/Base.jl b/base/Base.jl index c39b08b13539b2..e21ddbd901682c 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -94,6 +94,9 @@ include("refpointer.jl") include("checked.jl") using .Checked +# Lazy strings +include("strings/lazy.jl") + # array structures include("indices.jl") include("array.jl") @@ -154,6 +157,7 @@ include("dict.jl") include("abstractset.jl") include("set.jl") +# Strings include("char.jl") include("strings/basic.jl") include("strings/string.jl") diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 9f0ae669caacab..928b1b29f7d545 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -740,19 +740,21 @@ end # copy from an some iterable object into an AbstractArray function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer) if (sstart < 1) - throw(ArgumentError(string("source start offset (",sstart,") is < 1"))) + throw(ArgumentError(LazyString("source start offset (",sstart,") is < 1"))) end y = iterate(src) for j = 1:(sstart-1) if y === nothing - throw(ArgumentError(string("source has fewer elements than required, ", - "expected at least ",sstart,", got ",j-1))) + throw(ArgumentError(LazyString( + "source has fewer elements than required, ", + "expected at least ", sstart,", got ", j-1))) end y = iterate(src, y[2]) end if y === nothing - throw(ArgumentError(string("source has fewer elements than required, ", - "expected at least ",sstart,", got ",sstart-1))) + throw(ArgumentError(LazyString( + "source has fewer elements than required, ", + "expected at least ",sstart," got ", sstart-1))) end i = Int(dstart) while y !== nothing @@ -766,19 +768,22 @@ end # this method must be separate from the above since src might not have a length function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer, n::Integer) - n < 0 && throw(ArgumentError(string("tried to copy n=", n, " elements, but n should be nonnegative"))) + n < 0 && throw(ArgumentError(LazyString("tried to copy n=",n, + ", elements, but n should be nonnegative"))) n == 0 && return dest dmax = dstart + n - 1 inds = LinearIndices(dest) if (dstart ∉ inds || dmax ∉ inds) | (sstart < 1) - sstart < 1 && throw(ArgumentError(string("source start offset (",sstart,") is < 1"))) + sstart < 1 && throw(ArgumentError(LazyString("source start offset (", + sstart,") is < 1"))) throw(BoundsError(dest, dstart:dmax)) end y = iterate(src) for j = 1:(sstart-1) if y === nothing - throw(ArgumentError(string("source has fewer elements than required, ", - "expected at least ",sstart,", got ",j-1))) + throw(ArgumentError(LazyString( + "source has fewer elements than required, ", + "expected at least ",sstart,", got ",j-1))) end y = iterate(src, y[2]) end @@ -834,7 +839,8 @@ function copyto!(dest::AbstractArray, dstart::Integer, src::AbstractArray, sstart::Integer, n::Integer) n == 0 && return dest - n < 0 && throw(ArgumentError(string("tried to copy n=", n, " elements, but n should be nonnegative"))) + n < 0 && throw(ArgumentError(LazyString("tried to copy n=", + n," elements, but n should be nonnegative"))) destinds, srcinds = LinearIndices(dest), LinearIndices(src) (checkbounds(Bool, destinds, dstart) && checkbounds(Bool, destinds, dstart+n-1)) || throw(BoundsError(dest, dstart:dstart+n-1)) (checkbounds(Bool, srcinds, sstart) && checkbounds(Bool, srcinds, sstart+n-1)) || throw(BoundsError(src, sstart:sstart+n-1)) @@ -852,12 +858,12 @@ end function copyto!(B::AbstractVecOrMat{R}, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int}, A::AbstractVecOrMat{S}, ir_src::AbstractRange{Int}, jr_src::AbstractRange{Int}) where {R,S} if length(ir_dest) != length(ir_src) - throw(ArgumentError(string("source and destination must have same size (got ", - length(ir_src)," and ",length(ir_dest),")"))) + throw(ArgumentError(LazyString("source and destination must have same size (got ", + length(ir_src)," and ",length(ir_dest),")"))) end if length(jr_dest) != length(jr_src) - throw(ArgumentError(string("source and destination must have same size (got ", - length(jr_src)," and ",length(jr_dest),")"))) + throw(ArgumentError(LazyString("source and destination must have same size (got ", + length(jr_src)," and ",length(jr_dest),")"))) end @boundscheck checkbounds(B, ir_dest, jr_dest) @boundscheck checkbounds(A, ir_src, jr_src) diff --git a/base/compiler/compiler.jl b/base/compiler/compiler.jl index b44a60f23d626e..d01ff40cf6e08f 100644 --- a/base/compiler/compiler.jl +++ b/base/compiler/compiler.jl @@ -60,6 +60,8 @@ add_with_overflow(x::T, y::T) where {T<:SignedInt} = checked_sadd_int(x, y) add_with_overflow(x::T, y::T) where {T<:UnsignedInt} = checked_uadd_int(x, y) add_with_overflow(x::Bool, y::Bool) = (x+y, false) +include("strings/lazy.jl") + # core array operations include("indices.jl") include("array.jl") diff --git a/base/exports.jl b/base/exports.jl index ca0a75d3217e1f..aeda172ec840dd 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -54,6 +54,7 @@ export IOStream, LinRange, Irrational, + LazyString, Matrix, MergeSort, Missing, @@ -938,6 +939,7 @@ export @s_str, # regex substitution string @v_str, # version number @raw_str, # raw string with no interpolation/unescaping + @lazy_str, # lazy string # documentation @text_str, diff --git a/base/math.jl b/base/math.jl index c9e7397cbe30c9..3edcb63e468c13 100644 --- a/base/math.jl +++ b/base/math.jl @@ -30,13 +30,14 @@ using Core.Intrinsics: sqrt_llvm using .Base: IEEEFloat @noinline function throw_complex_domainerror(f::Symbol, x) - throw(DomainError(x, string("$f will only return a complex result if called with a ", - "complex argument. Try $f(Complex(x))."))) + throw(DomainError(x, + LazyString(f," will only return a complex result if called with a complex argument. Try ", f,"(Complex(x))."))) end @noinline function throw_exp_domainerror(x) - throw(DomainError(x, string("Exponentiation yielding a complex result requires a ", - "complex argument.\nReplace x^y with (x+0im)^y, ", - "Complex(x)^y, or similar."))) + throw(DomainError(x, LazyString( + "Exponentiation yielding a complex result requires a ", + "complex argument.\nReplace x^y with (x+0im)^y, ", + "Complex(x)^y, or similar."))) end # non-type specific math functions diff --git a/base/strings/lazy.jl b/base/strings/lazy.jl new file mode 100644 index 00000000000000..f75bc1ddb9182c --- /dev/null +++ b/base/strings/lazy.jl @@ -0,0 +1,35 @@ +""" + LazyString <: AbstractString + +A lazy representation of string interpolation. This is useful when a string +needs to be constructed in a context where performing the actual interpolation +and string construction is unnecessary or undesirable (e.g. in error paths +of of functions). + +This type is designed to be cheap to construct at runtime, trying to offload +as much work as possible to either the macro or later printing operations. +""" +struct LazyString <: AbstractString + parts::Tuple + LazyString(args...) = new(args) +end + +macro lazy_str(string) + parts = Any[] + lastidx = idx = 1 + while (idx = findnext('$', string, idx)) !== nothing + lastidx < idx && push!(parts, string[lastidx:idx-1]) + idx += 1 + expr, idx = Meta.parse(string, idx; greedy=false, raise=false) + push!(parts, esc(expr)) + lastidx = idx + end + lastidx <= lastindex(string) && push!(parts, string[lastidx:end]) + :(LazyString($(parts...))) +end + +function print(io::IO, s::LazyString) + for part in s.parts + print(io, part) + end +end diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index be1ad686cbc6b2..23e6a34cf2c60a 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -330,7 +330,7 @@ function dot(DX::Union{DenseArray{T},AbstractVector{T}}, DY::Union{DenseArray{T} require_one_based_indexing(DX, DY) n = length(DX) if n != length(DY) - throw(DimensionMismatch("dot product arguments have lengths $(length(DX)) and $(length(DY))")) + throw(DimensionMismatch(lazy"dot product arguments have lengths $(length(DX)) and $(length(DY))")) end GC.@preserve DX DY dot(n, pointer(DX), stride(DX, 1), pointer(DY), stride(DY, 1)) end @@ -338,7 +338,7 @@ function dotc(DX::Union{DenseArray{T},AbstractVector{T}}, DY::Union{DenseArray{T require_one_based_indexing(DX, DY) n = length(DX) if n != length(DY) - throw(DimensionMismatch("dot product arguments have lengths $(length(DX)) and $(length(DY))")) + throw(DimensionMismatch(lazy"dot product arguments have lengths $(length(DX)) and $(length(DY))")) end GC.@preserve DX DY dotc(n, pointer(DX), stride(DX, 1), pointer(DY), stride(DY, 1)) end @@ -346,7 +346,7 @@ function dotu(DX::Union{DenseArray{T},AbstractVector{T}}, DY::Union{DenseArray{T require_one_based_indexing(DX, DY) n = length(DX) if n != length(DY) - throw(DimensionMismatch("dot product arguments have lengths $(length(DX)) and $(length(DY))")) + throw(DimensionMismatch(lazy"dot product arguments have lengths $(length(DX)) and $(length(DY))")) end GC.@preserve DX DY dotu(n, pointer(DX), stride(DX, 1), pointer(DY), stride(DY, 1)) end @@ -461,7 +461,7 @@ for (fname, elty) in ((:daxpy_,:Float64), end function axpy!(alpha::Number, x::Union{DenseArray{T},StridedVector{T}}, y::Union{DenseArray{T},StridedVector{T}}) where T<:BlasFloat if length(x) != length(y) - throw(DimensionMismatch("x has length $(length(x)), but y has length $(length(y))")) + throw(DimensionMismatch(lazy"x has length $(length(x)), but y has length $(length(y))")) end GC.@preserve x y axpy!(length(x), convert(T,alpha), pointer(x), stride(x, 1), pointer(y), stride(y, 1)) y @@ -473,10 +473,10 @@ function axpy!(alpha::Number, x::Array{T}, rx::Union{UnitRange{Ti},AbstractRange throw(DimensionMismatch("ranges of differing lengths")) end if minimum(rx) < 1 || maximum(rx) > length(x) - throw(ArgumentError("range out of bounds for x, of length $(length(x))")) + throw(ArgumentError(lazy"range out of bounds for x, of length $(length(x))")) end if minimum(ry) < 1 || maximum(ry) > length(y) - throw(ArgumentError("range out of bounds for y, of length $(length(y))")) + throw(ArgumentError(lazy"range out of bounds for y, of length $(length(y))")) end GC.@preserve x y axpy!(length(rx), convert(T, alpha), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry)) y @@ -526,7 +526,7 @@ end function axpby!(alpha::Number, x::Union{DenseArray{T},AbstractVector{T}}, beta::Number, y::Union{DenseArray{T},AbstractVector{T}}) where T<:BlasFloat require_one_based_indexing(x, y) if length(x) != length(y) - throw(DimensionMismatch("x has length $(length(x)), but y has length $(length(y))")) + throw(DimensionMismatch(lazy"x has length $(length(x)), but y has length $(length(y))")) end GC.@preserve x y axpby!(length(x), convert(T,alpha), pointer(x), stride(x, 1), convert(T,beta), pointer(y), stride(y, 1)) y @@ -577,11 +577,11 @@ for (fname, elty) in ((:dgemv_,:Float64), require_one_based_indexing(A, X, Y) m,n = size(A,1),size(A,2) if trans == 'N' && (length(X) != n || length(Y) != m) - throw(DimensionMismatch("A has dimensions $(size(A)), X has length $(length(X)) and Y has length $(length(Y))")) + throw(DimensionMismatch(lazy"A has dimensions $(size(A)), X has length $(length(X)) and Y has length $(length(Y))")) elseif trans == 'C' && (length(X) != m || length(Y) != n) - throw(DimensionMismatch("the adjoint of A has dimensions $n, $m, X has length $(length(X)) and Y has length $(length(Y))")) + throw(DimensionMismatch(lazy"the adjoint of A has dimensions $n, $m, X has length $(length(X)) and Y has length $(length(Y))")) elseif trans == 'T' && (length(X) != m || length(Y) != n) - throw(DimensionMismatch("the transpose of A has dimensions $n, $m, X has length $(length(X)) and Y has length $(length(Y))")) + throw(DimensionMismatch(lazy"the transpose of A has dimensions $n, $m, X has length $(length(X)) and Y has length $(length(Y))")) end chkstride1(A) ccall((@blasfunc($fname), libblas), Cvoid, @@ -715,13 +715,13 @@ for (fname, elty, lib) in ((:dsymv_,:Float64,libblas), require_one_based_indexing(A, x, y) m, n = size(A) if m != n - throw(DimensionMismatch("matrix A is $m by $n but must be square")) + throw(DimensionMismatch(lazy"matrix A is $m by $n but must be square")) end if n != length(x) - throw(DimensionMismatch("A has size $(size(A)), and x has length $(length(x))")) + throw(DimensionMismatch(lazy"A has size $(size(A)), and x has length $(length(x))")) end if m != length(y) - throw(DimensionMismatch("A has size $(size(A)), and y has length $(length(y))")) + throw(DimensionMismatch(lazy"A has size $(size(A)), and y has length $(length(y))")) end chkstride1(A) ccall((@blasfunc($fname), $lib), Cvoid, @@ -767,13 +767,13 @@ for (fname, elty) in ((:zhemv_,:ComplexF64), require_one_based_indexing(A, x, y) m, n = size(A) if m != n - throw(DimensionMismatch("matrix A is $m by $n but must be square")) + throw(DimensionMismatch(lazy"matrix A is $m by $n but must be square")) end if n != length(x) - throw(DimensionMismatch("A has size $(size(A)), and x has length $(length(x))")) + throw(DimensionMismatch(lazy"A has size $(size(A)), and x has length $(length(x))")) end if m != length(y) - throw(DimensionMismatch("A has size $(size(A)), and y has length $(length(y))")) + throw(DimensionMismatch(lazy"A has size $(size(A)), and y has length $(length(y))")) end chkstride1(A) lda = max(1, stride(A, 2)) @@ -932,7 +932,7 @@ for (fname, elty) in ((:dtrmv_,:Float64), require_one_based_indexing(A, x) n = checksquare(A) if n != length(x) - throw(DimensionMismatch("A has size ($n,$n), x has length $(length(x))")) + throw(DimensionMismatch(lazy"A has size ($n,$n), x has length $(length(x))")) end chkstride1(A) ccall((@blasfunc($fname), libblas), Cvoid, @@ -986,7 +986,7 @@ for (fname, elty) in ((:dtrsv_,:Float64), require_one_based_indexing(A, x) n = checksquare(A) if n != length(x) - throw(DimensionMismatch("size of A is $n != length(x) = $(length(x))")) + throw(DimensionMismatch(lazy"size of A is $n != length(x) = $(length(x))")) end chkstride1(A) ccall((@blasfunc($fname), libblas), Cvoid, @@ -1020,7 +1020,7 @@ for (fname, elty) in ((:dger_,:Float64), require_one_based_indexing(A, x, y) m, n = size(A) if m != length(x) || n != length(y) - throw(DimensionMismatch("A has size ($m,$n), x has length $(length(x)), y has length $(length(y))")) + throw(DimensionMismatch(lazy"A has size ($m,$n), x has length $(length(x)), y has length $(length(y))")) end ccall((@blasfunc($fname), libblas), Cvoid, (Ref{BlasInt}, Ref{BlasInt}, Ref{$elty}, Ptr{$elty}, @@ -1053,7 +1053,7 @@ for (fname, elty, lib) in ((:dsyr_,:Float64,libblas), require_one_based_indexing(A, x) n = checksquare(A) if length(x) != n - throw(DimensionMismatch("A has size ($n,$n), x has length $(length(x))")) + throw(DimensionMismatch(lazy"A has size ($n,$n), x has length $(length(x))")) end ccall((@blasfunc($fname), $lib), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ref{$elty}, Ptr{$elty}, @@ -1083,7 +1083,7 @@ for (fname, elty, relty) in ((:zher_,:ComplexF64, :Float64), require_one_based_indexing(A, x) n = checksquare(A) if length(x) != n - throw(DimensionMismatch("A has size ($n,$n), x has length $(length(x))")) + throw(DimensionMismatch(lazy"A has size ($n,$n), x has length $(length(x))")) end ccall((@blasfunc($fname), libblas), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ref{$relty}, Ptr{$elty}, @@ -1133,7 +1133,7 @@ for (gemm, elty) in kb = size(B, transB == 'N' ? 1 : 2) n = size(B, transB == 'N' ? 2 : 1) if ka != kb || m != size(C,1) || n != size(C,2) - throw(DimensionMismatch("A has size ($m,$ka), B has size ($kb,$n), C has size $(size(C))")) + throw(DimensionMismatch(lazy"A has size ($m,$ka), B has size ($kb,$n), C has size $(size(C))")) end chkstride1(A) chkstride1(B) @@ -1193,10 +1193,10 @@ for (mfname, elty) in ((:dsymm_,:Float64), m, n = size(C) j = checksquare(A) if j != (side == 'L' ? m : n) - throw(DimensionMismatch("A has size $(size(A)), C has size ($m,$n)")) + throw(DimensionMismatch(lazy"A has size $(size(A)), C has size ($m,$n)")) end if size(B,2) != n - throw(DimensionMismatch("B has second dimension $(size(B,2)) but needs to match second dimension of C, $n")) + throw(DimensionMismatch(lazy"B has second dimension $(size(B,2)) but needs to match second dimension of C, $n")) end chkstride1(A) chkstride1(B) @@ -1264,10 +1264,10 @@ for (mfname, elty) in ((:zhemm_,:ComplexF64), m, n = size(C) j = checksquare(A) if j != (side == 'L' ? m : n) - throw(DimensionMismatch("A has size $(size(A)), C has size ($m,$n)")) + throw(DimensionMismatch(lazy"A has size $(size(A)), C has size ($m,$n)")) end if size(B,2) != n - throw(DimensionMismatch("B has second dimension $(size(B,2)) but needs to match second dimension of C, $n")) + throw(DimensionMismatch(lazy"B has second dimension $(size(B,2)) but needs to match second dimension of C, $n")) end chkstride1(A) chkstride1(B) @@ -1329,7 +1329,7 @@ for (fname, elty) in ((:dsyrk_,:Float64), require_one_based_indexing(A, C) n = checksquare(C) nn = size(A, trans == 'N' ? 1 : 2) - if nn != n throw(DimensionMismatch("C has size ($n,$n), corresponding dimension of A is $nn")) end + if nn != n throw(DimensionMismatch(lazy"C has size ($n,$n), corresponding dimension of A is $nn")) end k = size(A, trans == 'N' ? 2 : 1) chkstride1(A) chkstride1(C) @@ -1388,7 +1388,7 @@ for (fname, elty, relty) in ((:zherk_, :ComplexF64, :Float64), n = checksquare(C) nn = size(A, trans == 'N' ? 1 : 2) if nn != n - throw(DimensionMismatch("the matrix to update has dimension $n but the implied dimension of the update is $(size(A, trans == 'N' ? 1 : 2))")) + throw(DimensionMismatch(lazy"the matrix to update has dimension $n but the implied dimension of the update is $(size(A, trans == 'N' ? 1 : 2))")) end chkstride1(A) chkstride1(C) @@ -1431,7 +1431,7 @@ for (fname, elty) in ((:dsyr2k_,:Float64), require_one_based_indexing(A, B, C) n = checksquare(C) nn = size(A, trans == 'N' ? 1 : 2) - if nn != n throw(DimensionMismatch("C has size ($n,$n), corresponding dimension of A is $nn")) end + if nn != n throw(DimensionMismatch(lazy"C has size ($n,$n), corresponding dimension of A is $nn")) end k = size(A, trans == 'N' ? 2 : 1) chkstride1(A) chkstride1(B) @@ -1472,7 +1472,7 @@ for (fname, elty1, elty2) in ((:zher2k_,:ComplexF64,:Float64), (:cher2k_,:Comple require_one_based_indexing(A, B, C) n = checksquare(C) nn = size(A, trans == 'N' ? 1 : 2) - if nn != n throw(DimensionMismatch("C has size ($n,$n), corresponding dimension of A is $nn")) end + if nn != n throw(DimensionMismatch(lazy"C has size ($n,$n), corresponding dimension of A is $nn")) end chkstride1(A) chkstride1(B) chkstride1(C) @@ -1561,7 +1561,7 @@ for (mmname, smname, elty) in m, n = size(B) nA = checksquare(A) if nA != (side == 'L' ? m : n) - throw(DimensionMismatch("size of A, $(size(A)), doesn't match $side size of B with dims, $(size(B))")) + throw(DimensionMismatch(lazy"size of A, $(size(A)), doesn't match $side size of B with dims, $(size(B))")) end chkstride1(A) chkstride1(B) @@ -1589,7 +1589,7 @@ for (mmname, smname, elty) in m, n = size(B) k = checksquare(A) if k != (side == 'L' ? m : n) - throw(DimensionMismatch("size of A is ($k,$k), size of B is ($m,$n), side is $side, and transa='$transa'")) + throw(DimensionMismatch(lazy"size of A is ($k,$k), size of B is ($m,$n), side is $side, and transa='$transa'")) end chkstride1(A) chkstride1(B) @@ -1613,13 +1613,13 @@ end # module function copyto!(dest::Array{T}, rdest::Union{UnitRange{Ti},AbstractRange{Ti}}, src::Array{T}, rsrc::Union{UnitRange{Ti},AbstractRange{Ti}}) where {T<:BlasFloat,Ti<:Integer} if minimum(rdest) < 1 || maximum(rdest) > length(dest) - throw(ArgumentError("range out of bounds for dest, of length $(length(dest))")) + throw(ArgumentError(lazy"range out of bounds for dest, of length $(length(dest))")) end if minimum(rsrc) < 1 || maximum(rsrc) > length(src) - throw(ArgumentError("range out of bounds for src, of length $(length(src))")) + throw(ArgumentError(lazy"range out of bounds for src, of length $(length(src))")) end if length(rdest) != length(rsrc) - throw(DimensionMismatch("ranges must be of the same length")) + throw(DimensionMismatch(lazy"ranges must be of the same length")) end GC.@preserve src dest BLAS.blascopy!(length(rsrc), pointer(src) + (first(rsrc) - 1) * sizeof(T), diff --git a/stdlib/LinearAlgebra/src/matmul.jl b/stdlib/LinearAlgebra/src/matmul.jl index b36ce933100344..e96648767fa308 100644 --- a/stdlib/LinearAlgebra/src/matmul.jl +++ b/stdlib/LinearAlgebra/src/matmul.jl @@ -11,7 +11,7 @@ dot(x::Union{DenseArray{T},StridedVector{T}}, y::Union{DenseArray{T},StridedVect function dot(x::Vector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasReal,TI<:Integer} if length(rx) != length(ry) - throw(DimensionMismatch("length of rx, $(length(rx)), does not equal length of ry, $(length(ry))")) + throw(DimensionMismatch(lazy"length of rx, $(length(rx)), does not equal length of ry, $(length(ry))")) end if minimum(rx) < 1 || maximum(rx) > length(x) throw(BoundsError(x, rx)) @@ -24,7 +24,7 @@ end function dot(x::Vector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasComplex,TI<:Integer} if length(rx) != length(ry) - throw(DimensionMismatch("length of rx, $(length(rx)), does not equal length of ry, $(length(ry))")) + throw(DimensionMismatch(lazy"length of rx, $(length(rx)), does not equal length of ry, $(length(ry))")) end if minimum(rx) < 1 || maximum(rx) > length(x) throw(BoundsError(x, rx)) @@ -449,7 +449,7 @@ end A[i,j] = conjugate ? adjoint(A[j,i]) : transpose(A[j,i]) end else - throw(ArgumentError("uplo argument must be 'U' (upper) or 'L' (lower), got $uplo")) + throw(ArgumentError(lazy"uplo argument must be 'U' (upper) or 'L' (lower), got $uplo")) end A end @@ -458,10 +458,10 @@ function gemv!(y::StridedVector{T}, tA::AbstractChar, A::StridedVecOrMat{T}, x:: alpha::Union{T, Bool} = true, beta::Union{T, Bool} = false) where T<:BlasFloat mA, nA = lapack_size(tA, A) if nA != length(x) - throw(DimensionMismatch("second dimension of A, $nA, does not match length of x, $(length(x))")) + throw(DimensionMismatch(lazy"second dimension of A, $nA, does not match length of x, $(length(x))")) end if mA != length(y) - throw(DimensionMismatch("first dimension of A, $mA, does not match length of y, $(length(y))")) + throw(DimensionMismatch(lazy"first dimension of A, $mA, does not match length of y, $(length(y))")) end if mA == 0 return y @@ -486,7 +486,7 @@ function syrk_wrapper!(C::StridedMatrix{T}, tA::AbstractChar, A::StridedVecOrMat tAt = 'T' end if nC != mA - throw(DimensionMismatch("output matrix has size: $(nC), but should have size $(mA)")) + throw(DimensionMismatch(lazy"output matrix has size: $(nC), but should have size $(mA)")) end if mA == 0 || nA == 0 || iszero(_add.alpha) return _rmul_or_fill!(C, _add.beta) @@ -515,7 +515,7 @@ function herk_wrapper!(C::Union{StridedMatrix{T}, StridedMatrix{Complex{T}}}, tA tAt = 'C' end if nC != mA - throw(DimensionMismatch("output matrix has size: $(nC), but should have size $(mA)")) + throw(DimensionMismatch(lazy"output matrix has size: $(nC), but should have size $(mA)")) end if mA == 0 || nA == 0 return _rmul_or_fill!(C, _add.beta) @@ -552,7 +552,7 @@ function gemm_wrapper!(C::StridedVecOrMat{T}, tA::AbstractChar, tB::AbstractChar mB, nB = lapack_size(tB, B) if nA != mB - throw(DimensionMismatch("A has dimensions ($mA,$nA) but B has dimensions ($mB,$nB)")) + throw(DimensionMismatch(lazy"A has dimensions ($mA,$nA) but B has dimensions ($mB,$nB)")) end if C === A || B === C @@ -561,7 +561,7 @@ function gemm_wrapper!(C::StridedVecOrMat{T}, tA::AbstractChar, tB::AbstractChar if mA == 0 || nA == 0 || nB == 0 || iszero(_add.alpha) if size(C) != (mA, nB) - throw(DimensionMismatch("C has dimensions $(size(C)), should have ($mA,$nB)")) + throw(DimensionMismatch(lazy"C has dimensions $(size(C)), should have ($mA,$nB)")) end return _rmul_or_fill!(C, _add.beta) end @@ -616,10 +616,10 @@ function generic_matvecmul!(C::AbstractVector{R}, tA, A::AbstractVecOrMat, B::Ab mB = length(B) mA, nA = lapack_size(tA, A) if mB != nA - throw(DimensionMismatch("matrix A has dimensions ($mA,$nA), vector B has length $mB")) + throw(DimensionMismatch(lazy"matrix A has dimensions ($mA,$nA), vector B has length $mB")) end if mA != length(C) - throw(DimensionMismatch("result C has length $(length(C)), needs length $mA")) + throw(DimensionMismatch(lazy"result C has length $(length(C)), needs length $mA")) end Astride = size(A, 1) @@ -713,10 +713,10 @@ function _generic_matmatmul!(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVecOrMat mA, nA = lapack_size(tA, A) mB, nB = lapack_size(tB, B) if mB != nA - throw(DimensionMismatch("matrix A has dimensions ($mA,$nA), matrix B has dimensions ($mB,$nB)")) + throw(DimensionMismatch(lazy"matrix A has dimensions ($mA,$nA), matrix B has dimensions ($mB,$nB)")) end if size(C,1) != mA || size(C,2) != nB - throw(DimensionMismatch("result C has dimensions $(size(C)), needs ($mA,$nB)")) + throw(DimensionMismatch(lazy"result C has dimensions $(size(C)), needs ($mA,$nB)")) end if isempty(A) || isempty(B) return C @@ -893,7 +893,7 @@ function matmul2x2!(C::AbstractMatrix, tA, tB, A::AbstractMatrix, B::AbstractMat _add::MulAddMul = MulAddMul()) require_one_based_indexing(C, A, B) if !(size(A) == size(B) == size(C) == (2,2)) - throw(DimensionMismatch("A has size $(size(A)), B has size $(size(B)), C has size $(size(C))")) + throw(DimensionMismatch(lazy"A has size $(size(A)), B has size $(size(B)), C has size $(size(C))")) end @inbounds begin if tA == 'T' @@ -936,7 +936,7 @@ function matmul3x3!(C::AbstractMatrix, tA, tB, A::AbstractMatrix, B::AbstractMat _add::MulAddMul = MulAddMul()) require_one_based_indexing(C, A, B) if !(size(A) == size(B) == size(C) == (3,3)) - throw(DimensionMismatch("A has size $(size(A)), B has size $(size(B)), C has size $(size(C))")) + throw(DimensionMismatch(lazy"A has size $(size(A)), B has size $(size(B)), C has size $(size(C))")) end @inbounds begin if tA == 'T' diff --git a/stdlib/LinearAlgebra/src/transpose.jl b/stdlib/LinearAlgebra/src/transpose.jl index 4b4658df551343..37d43eaa9dfac6 100644 --- a/stdlib/LinearAlgebra/src/transpose.jl +++ b/stdlib/LinearAlgebra/src/transpose.jl @@ -181,11 +181,11 @@ Base.copy(A::Adjoint{<:Any,<:AbstractMatrix}) = adjoint!(similar(A.parent, rever function copy_transpose!(B::AbstractVecOrMat, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int}, A::AbstractVecOrMat, ir_src::AbstractRange{Int}, jr_src::AbstractRange{Int}) if length(ir_dest) != length(jr_src) - throw(ArgumentError(string("source and destination must have same size (got ", + throw(ArgumentError(LazyString("source and destination must have same size (got ", length(jr_src)," and ",length(ir_dest),")"))) end if length(jr_dest) != length(ir_src) - throw(ArgumentError(string("source and destination must have same size (got ", + throw(ArgumentError(LazyString("source and destination must have same size (got ", length(ir_src)," and ",length(jr_dest),")"))) end @boundscheck checkbounds(B, ir_dest, jr_dest)