Skip to content

Commit

Permalink
Fix vecnorm for Vector{Vector{T}}
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Jul 25, 2017
1 parent 79ff734 commit 91f8539
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,15 @@ julia> vecnorm([1 2 3 4 5 6 7 8 9])
```
"""
function vecnorm(itr, p::Real=2)
isempty(itr) && return float(real(zero(eltype(itr))))
isempty(itr) && return float(norm(zero(eltype(itr))))
if p == 2
return vecnorm2(itr)
elseif p == 1
return vecnorm1(itr)
elseif p == Inf
return vecnormInf(itr)
elseif p == 0
return convert(typeof(float(real(zero(eltype(itr))))),
countnz(itr))
return typeof(float(norm(first(itr))))(count(t -> !iszero(norm(t)), itr))
elseif p == -Inf
return vecnormMinusInf(itr)
else
Expand Down
3 changes: 2 additions & 1 deletion test/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ end

# test generic vecnorm for arrays of arrays
let x = Vector{Int}[[1,2], [3,4]]
@test norm(x) sqrt(30)
@test @inferred(norm(x)) sqrt(30)
@test norm(x, 0) == length(x)
@test norm(x, 1) sqrt(5) + 5
@test norm(x, 3) cbrt(sqrt(125)+125)
end
Expand Down

0 comments on commit 91f8539

Please sign in to comment.