Skip to content

Commit

Permalink
Merge pull request #24712 from Sacha0/reparrtlinalg
Browse files Browse the repository at this point in the history
replace Array{...}(shape...)-like calls in test/linalg
  • Loading branch information
Sacha0 authored Nov 23, 2017
2 parents 66e399b + 62f6978 commit 15a5aeb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion test/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ end
@test scale!(similar(a), [1.; 2.], a) == a.*[1; 2]
@test scale!(similar(a), [1; 2], a) == a.*[1; 2]
@test_throws DimensionMismatch scale!(similar(a), ones(3), a)
@test_throws DimensionMismatch scale!(Array{Float64}(3, 2), a, ones(3))
@test_throws DimensionMismatch scale!(Matrix{Float64}(uninitialized, 3, 2), a, ones(3))

if isa(a, Array)
@test scale!(similar(a), a, [1.; 2.; 3.]) == a.*[1 2 3]
Expand Down
30 changes: 16 additions & 14 deletions test/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ using Test
@test ones(0,0)*ones(0,4) == zeros(0,4)
@test ones(3,0)*ones(0,0) == zeros(3,0)
@test ones(0,0)*ones(0,0) == zeros(0,0)
@test Array{Float64}(5, 0) |> t -> t't == zeros(0,0)
@test Array{Float64}(5, 0) |> t -> t*t' == zeros(5,5)
@test Array{Complex128}(5, 0) |> t -> t't == zeros(0,0)
@test Array{Complex128}(5, 0) |> t -> t*t' == zeros(5,5)
@test Matrix{Float64}(uninitialized, 5, 0) |> t -> t't == zeros(0,0)
@test Matrix{Float64}(uninitialized, 5, 0) |> t -> t*t' == zeros(5,5)
@test Matrix{Complex128}(uninitialized, 5, 0) |> t -> t't == zeros(0,0)
@test Matrix{Complex128}(uninitialized, 5, 0) |> t -> t*t' == zeros(5,5)
end
@testset "2x2 matmul" begin
AA = [1 2; 3 4]
Expand Down Expand Up @@ -89,7 +89,7 @@ end
end
AA = rand(1:20, 5, 5) .- 10
BB = rand(1:20, 5, 5) .- 10
CC = Array{Int}(size(AA, 1), size(BB, 2))
CC = Matrix{Int}(uninitialized, size(AA, 1), size(BB, 2))
for A in (copy(AA), view(AA, 1:5, 1:5)), B in (copy(BB), view(BB, 1:5, 1:5)), C in (copy(CC), view(CC, 1:5, 1:5))
@test At_mul_B(A, B) == A'*B
@test A_mul_Bt(A, B) == A*B'
Expand All @@ -105,7 +105,7 @@ end
@test_throws DimensionMismatch Base.LinAlg.Ac_mul_Bt!(C,ones(Int,4,4),B)
end
vv = [1,2]
CC = Array{Int}(2, 2)
CC = Matrix{Int}(uninitialized, 2, 2)
for v in (copy(vv), view(vv, 1:2)), C in (copy(CC), view(CC, 1:2, 1:2))
@test @inferred(A_mul_Bc!(C, v, v)) == [1 2; 2 4]
end
Expand All @@ -119,12 +119,12 @@ end
@test_throws DimensionMismatch Base.LinAlg.generic_matvecmul!(B,'N',A,zeros(6))
end
vv = [1,2,3]
CC = Array{Int}(3, 3)
CC = Matrix{Int}(uninitialized, 3, 3)
for v in (copy(vv), view(vv, 1:3)), C in (copy(CC), view(CC, 1:3, 1:3))
@test A_mul_Bt!(C, v, v) == v*v'
end
vvf = map(Float64,vv)
CC = Array{Float64}(3, 3)
CC = Matrix{Float64}(uninitialized, 3, 3)
for vf in (copy(vvf), view(vvf, 1:3)), C in (copy(CC), view(CC, 1:3, 1:3))
@test A_mul_Bt!(C, vf, vf) == vf*vf'
end
Expand Down Expand Up @@ -247,12 +247,12 @@ vecdot_(x,y) = invoke(vecdot, Tuple{Any,Any}, x,y)
end

@testset "Issue 11978" begin
A = Array{Matrix{Float64}}(2, 2)
A = Matrix{Matrix{Float64}}(uninitialized, 2, 2)
A[1,1] = Matrix(1.0I, 3, 3)
A[2,2] = Matrix(1.0I, 2, 2)
A[1,2] = Matrix(1.0I, 3, 2)
A[2,1] = Matrix(1.0I, 2, 3)
b = Array{Vector{Float64}}(2)
b = Vector{Vector{Float64}}(uninitialized, 2)
b[1] = ones(3)
b[2] = ones(2)
@test A*b == Vector{Float64}[[2,2,1], [2,2]]
Expand All @@ -266,10 +266,12 @@ end
@test Base.LinAlg.gemv!(ones(elty,0),'N',rand(elty,0,0),rand(elty,0)) == ones(elty,0)
@test Base.LinAlg.gemv!(ones(elty,10), 'N',ones(elty,10,0),ones(elty,0)) == zeros(elty,10)

I10 = Matrix{elty}(I, 10, 10)
@test Base.LinAlg.gemm_wrapper('N','N', I10, I10) == I10
@test_throws DimensionMismatch Base.LinAlg.gemm_wrapper!(I10,'N','N', Matrix{elty}(I, 10, 11), I10)
@test_throws DimensionMismatch Base.LinAlg.gemm_wrapper!(I10,'N','N', Matrix{elty}(0, 0), Matrix{elty}(0, 0))
I0x0 = Matrix{elty}(I, 0, 0)
I10x10 = Matrix{elty}(I, 10, 10)
I10x11 = Matrix{elty}(I, 10, 11)
@test Base.LinAlg.gemm_wrapper('N','N', I10x10, I10x10) == I10x10
@test_throws DimensionMismatch Base.LinAlg.gemm_wrapper!(I10x10,'N','N', I10x11, I10x10)
@test_throws DimensionMismatch Base.LinAlg.gemm_wrapper!(I10x10,'N','N', I0x0, I0x0)

A = rand(elty,3,3)
@test Base.LinAlg.matmul3x3('T','N',A, Matrix{elty}(I, 3, 3)) == A.'
Expand Down
8 changes: 4 additions & 4 deletions test/linalg/pinv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using Test
srand(12345)

function hilb(T::Type, n::Integer)
a=Array{T}(n,n)
a = Matrix{T}(uninitialized, n, n)
for i=1:n
for j=1:n
a[j,i]=one(T)/(i+j-one(T))
Expand All @@ -20,7 +20,7 @@ end
hilb(n::Integer) = hilb(Float64,n)

function hilb(T::Type, m::Integer, n::Integer)
a=Array{T}(m,n)
a = Matrix{T}(uninitialized, m, n)
for i=1:n
for j=1:m
a[j,i]=one(T)/(i+j-one(T))
Expand Down Expand Up @@ -67,7 +67,7 @@ tridiag(m::Integer, n::Integer) = tridiag(Float64, m::Integer, n::Integer)

function randn_float64(m::Integer, n::Integer)
a=randn(m,n)
b=Array{Float64}(m,n)
b = Matrix{Float64}(uninitialized, m, n)
for i=1:n
for j=1:m
b[j,i]=convert(Float64,a[j,i])
Expand All @@ -78,7 +78,7 @@ end

function randn_float32(m::Integer, n::Integer)
a=randn(m,n)
b=Array{Float32}(m,n)
b = Matrix{Float32}(uninitialized, m, n)
for i=1:n
for j=1:m
b[j,i]=convert(Float32,a[j,i])
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
@test A1'A2' Matrix(A1)'Matrix(A2)'
@test A1/A2 Matrix(A1)/Matrix(A2)
@test A1\A2 Matrix(A1)\Matrix(A2)
offsizeA = Matrix{Float64}(n+1, n+1)
offsizeA = Matrix{Float64}(I, n+1, n+1)
@test_throws DimensionMismatch offsizeA / A2
@test_throws DimensionMismatch offsizeA / A2.'
@test_throws DimensionMismatch offsizeA / A2'
Expand Down

0 comments on commit 15a5aeb

Please sign in to comment.