Skip to content

Commit 854bf6b

Browse files
committed
Tests for norm function
1 parent f7edf16 commit 854bf6b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/math/linearalgebra/support.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function norm(v::Array{Complex{DoubleFloat{T}},N}, p::Real=2.0) where {N, T<:IEE
2424
if isinf(p)
2525
return signbit(p) ? minimum(abs.(real.(v))) : maximum(abs.(real.(v)))
2626
elseif p==2
27-
return vp = sqrt(sum(conj.(v) .* v))
27+
return vp = sqrt(real(sum(conj.(v) .* v)))
2828
else
2929
vp = sum(abs.(v).^(p))
3030
r = inv(DoubleFloat{T}(p))

test/linearalgebra.jl

+9
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@
1010
t=[Complex{Double64}(1.0,0.0) Complex{Double64}(0.0,1.0);
1111
Complex{Double64}(0.0,-1.0) Complex{Double64}(1.0,0.0)]
1212
@test ishermitian(t)
13+
14+
@test norm(Complex{Double64}[2, 2im]) norm(ComplexF64[2, 2im])
15+
@test norm(Complex{Double64}[2, 2im]) isa Double64
16+
17+
@test norm(Complex{Double64}[2, 2im], 3.0) norm(ComplexF64[2, 2im], 3.0)
18+
@test norm(Complex{Double64}[2, 2im], 3.0) isa Double64
19+
20+
@test norm(Double64[2, 1]) norm(Float64[2, 1])
21+
@test norm(Double64[2, 1], 3.0) norm(Float64[2, 1], 3.0)
1322
end

0 commit comments

Comments
 (0)