Skip to content

Commit

Permalink
Merge c8e336a into ee0632f
Browse files Browse the repository at this point in the history
  • Loading branch information
mtanneau committed Apr 8, 2020
2 parents ee0632f + c8e336a commit fdc6fc9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/math/linearalgebra/support.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fdc6fc9

Please sign in to comment.