Skip to content

Commit

Permalink
More tests for blas, including axpy
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Jun 2, 2015
1 parent 7546101 commit da52cbf
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,35 @@ for elty in [Float32, Float64, Complex64, Complex128]
x1 = convert(Vector{elty}, randn(10))
x2 = convert(Vector{elty}, randn(10))
@test_approx_eq BLAS.dot(x1,x2) sum(x1.*x2)
@test_throws DimensionMismatch BLAS.dot(x1,rand(elty,11))
else
z1 = convert(Vector{elty}, complex(randn(10),randn(10)))
z2 = convert(Vector{elty}, complex(randn(10),randn(10)))
@test_approx_eq BLAS.dotc(z1,z2) sum(conj(z1).*z2)
@test_approx_eq BLAS.dotu(z1,z2) sum(z1.*z2)
@test_throws DimensionMismatch BLAS.dotc(z1,rand(elty,11))
@test_throws DimensionMismatch BLAS.dotu(z1,rand(elty,11))
end

# axpy
if elty <: Real
x1 = convert(Vector{elty}, randn(10))
x2 = convert(Vector{elty}, randn(10))
α = rand(elty)
@test_approx_eq BLAS.axpy!(α,copy(x1),copy(x2)) x2 + α*x1
@test_throws DimensionMismatch BLAS.axpy!(α,copy(x1),rand(elty,11))
@test_throws DimensionMismatch BLAS.axpy!(α,copy(x1),1:5,copy(x2),1:6)
@test_throws BoundsError BLAS.axpy!(α,copy(x1),0:5,copy(x2),1:6)
@test_throws BoundsError BLAS.axpy!(α,copy(x1),1:7,copy(x2),0:6)
else
z1 = convert(Vector{elty}, complex(randn(10),randn(10)))
z2 = convert(Vector{elty}, complex(randn(10),randn(10)))
α = rand(elty)
@test_approx_eq BLAS.axpy!(α,copy(z1),copy(z2)) z2 + α*z1
@test_throws DimensionMismatch BLAS.axpy!(α,copy(z1),rand(elty,11))
@test_throws DimensionMismatch BLAS.axpy!(α,copy(z1),1:5,copy(z2),1:6)
@test_throws BoundsError BLAS.axpy!(α,copy(z1),0:5,copy(z2),1:6)
@test_throws BoundsError BLAS.axpy!(α,copy(z1),1:7,copy(z2),0:6)
end

# gemv
Expand All @@ -38,6 +62,7 @@ for elty in [Float32, Float64, Complex64, Complex128]
@test_throws DimensionMismatch BLAS.gemv('N',I43,o4)
o4cp = copy(o4)
@test_throws DimensionMismatch BLAS.gemv!('T',one(elty),I43,o4,one(elty),o4cp)
@test_throws DimensionMismatch BLAS.gemv!('C',one(elty),I43,o4,one(elty),o4cp)
@test all(BLAS.gemv!('N', one(elty), I4, o4, elm1, o4cp) .== z4)
@test all(o4cp .== z4)
o4cp[:] = o4
Expand Down Expand Up @@ -69,6 +94,7 @@ for elty in [Float32, Float64, Complex64, Complex128]
@test all(I4cp .== Z4)
@test all(BLAS.gemm('N', 'N', I4, U4) .== U4)
@test all(BLAS.gemm('N', 'T', I4, U4) .== L4)
@test_throws DimensionMismatch BLAS.gemm!('N','N', one(elty), I4, I4, elm1, eye(elty,5))

# gemm compared to (sy)(he)rk
if iseltype(elm1,Complex)
Expand All @@ -83,6 +109,7 @@ for elty in [Float32, Float64, Complex64, Complex128]
ans = similar(L4)
@test all(tril(BLAS.herk('L','C', L4)) .== tril(BLAS.herk!('L', 'C', real(one(elty)), L4, real(zero(elty)), ans)))
@test all(Base.LinAlg.copytri!(ans, 'L') .== LinAlg.BLAS.gemm('T', 'N', L4, L4))
@test_throws DimensionMismatch BLAS.herk!('L','N',real(one(elty)),eye(elty,5),real(one(elty)),eye(elty,6))
else
@test all(triu(BLAS.syrk('U', 'N', U4)) .== triu(BLAS.gemm('N', 'T', U4, U4)))
@test all(tril(BLAS.syrk('L', 'N', U4)) .== tril(BLAS.gemm('N', 'T', U4, U4)))
Expand All @@ -95,5 +122,6 @@ for elty in [Float32, Float64, Complex64, Complex128]
ans = similar(L4)
@test all(tril(BLAS.syrk('L','T', L4)) .== tril(BLAS.syrk!('L', 'T', one(elty), L4, zero(elty), ans)))
@test all(Base.LinAlg.copytri!(ans, 'L') .== BLAS.gemm('T', 'N', L4, L4))
@test_throws DimensionMismatch BLAS.syrk!('L','N',one(elty),eye(elty,5),one(elty),eye(elty,6))
end
end

0 comments on commit da52cbf

Please sign in to comment.