diff --git a/src/math/linearalgebra/support.jl b/src/math/linearalgebra/support.jl index 102565a9..b1600b71 100644 --- a/src/math/linearalgebra/support.jl +++ b/src/math/linearalgebra/support.jl @@ -9,6 +9,8 @@ end end function norm(v::Array{DoubleFloat{T},N}, p::Real=2.0) where {N, T<:IEEEFloat} + isempty(v) && return zero(DoubleFloat{T}) + if isinf(p) return signbit(p) ? minimum(abs.(v)) : maximum(abs.(v)) elseif p==2 @@ -21,6 +23,8 @@ function norm(v::Array{DoubleFloat{T},N}, p::Real=2.0) where {N, T<:IEEEFloat} end function norm(v::Array{Complex{DoubleFloat{T}},N}, p::Real=2.0) where {N, T<:IEEEFloat} + isempty(v) && return zero(DoubleFloat{T}) + if isinf(p) return signbit(p) ? minimum(abs.(real.(v))) : maximum(abs.(real.(v))) elseif p==2 diff --git a/test/linearalgebra.jl b/test/linearalgebra.jl index 32b579ff..52157820 100644 --- a/test/linearalgebra.jl +++ b/test/linearalgebra.jl @@ -19,4 +19,15 @@ @test norm(Double64[2, 1]) ≈ norm(Float64[2, 1]) @test norm(Double64[2, 1], 3.0) ≈ norm(Float64[2, 1], 3.0) + + # issue #105 + for T in [Double16, Double32, Double64] + for p in [0, 1.0, 2.0, Inf, -Inf] + @test norm(T[], p) == zero(T) + @test norm(Complex{T}[], p) == zero(T) + + @test normalize(T[]) == T[] + @test normalize(Complex{T}[]) == Complex{T}[] + end + end end