Skip to content

Commit

Permalink
Replace Array(shape...)-like calls in test/[d-p]*.jl. (#24743)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 authored and fredrikekre committed Nov 24, 2017
1 parent 28abaa2 commit af93075
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ end
###################

function test_LibcFILE(FILEp)
buf = Array{UInt8}(8)
buf = Vector{UInt8}(uninitialized, 8)
str = ccall(:fread, Csize_t, (Ptr{Void}, Csize_t, Csize_t, Ptr{Void}), buf, 1, 8, FILEp)
@test String(buf) == "Hello, w"
@test position(FILEp) == 8
Expand Down
8 changes: 4 additions & 4 deletions test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

# map over Bottom[] should return Bottom[]
# issue #6719
@test isequal(typeof(map(x -> x, Array{Union{}}(0))), Array{Union{},1})
@test isequal(typeof(map(x -> x, Vector{Union{}}(uninitialized, 0))), Vector{Union{}})

# maps of tuples (formerly in test/core.jl) -- tuple.jl
@test map((x,y)->x+y,(1,2,3),(4,5,6)) == (5,7,9)
Expand Down Expand Up @@ -81,9 +81,9 @@ let gens_dims = [((i for i = 1:5), 1),
((i for i = 1:5, j = 1:5), 2),
((i for i = 1:5, j = 1:5, k = 1:5), 3),
((i for i = Array{Int}()), 0),
((i for i = Array{Int}(1)), 1),
((i for i = Array{Int}(1, 2)), 2),
((i for i = Array{Int}(1, 2, 3)), 3)]
((i for i = Vector{Int}(uninitialized, 1)), 1),
((i for i = Matrix{Int}(uninitialized, 1, 2)), 2),
((i for i = Array{Int}(uninitialized, 1, 2, 3)), 3)]
for (gen, dim) in gens_dims
@test ndims(gen) == ndims(collect(gen)) == dim
end
Expand Down
2 changes: 1 addition & 1 deletion test/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function trimrep(buffer)
end

const bufsize = 500
buffer = Array{UInt8}(bufsize)
buffer = Vector{UInt8}(uninitialized, bufsize)
fill!(buffer,0)
bignums = [Grisu.Bignums.Bignum(),Grisu.Bignums.Bignum(),Grisu.Bignums.Bignum(),Grisu.Bignums.Bignum()]

Expand Down
2 changes: 1 addition & 1 deletion test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ test_const_return(()->sizeof(1), Tuple{}, sizeof(Int))
test_const_return(()->sizeof(DataType), Tuple{}, sizeof(DataType))
test_const_return(()->sizeof(1 < 2), Tuple{}, 1)
@eval test_const_return(()->Core.sizeof($(Array{Int}())), Tuple{}, sizeof(Int))
@eval test_const_return(()->Core.sizeof($(Matrix{Float32}(2, 2))), Tuple{}, 4 * 2 * 2)
@eval test_const_return(()->Core.sizeof($(Matrix{Float32}(uninitialized, 2, 2))), Tuple{}, 4 * 2 * 2)

# Make sure Core.sizeof with a ::DataType as inferred input type is inferred but not constant.
function sizeof_typeref(typeref)
Expand Down
6 changes: 3 additions & 3 deletions test/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let io = IOBuffer()
@test eof(io)
seek(io, 0)
@test read(io,UInt8) == convert(UInt8, 'a')
a = Array{UInt8}(2)
a = Vector{UInt8}(uninitialized, 2)
@test read!(io, a) == a
@test a == UInt8['b','c']
@test bufcontents(io) == "abc"
Expand Down Expand Up @@ -163,7 +163,7 @@ end

# issue 5453
let io = IOBuffer("abcdef"),
a = Array{UInt8}(1024)
a = Vector{UInt8}(uninitialized, 1024)
@test_throws EOFError read!(io,a)
@test eof(io)
end
Expand Down Expand Up @@ -195,7 +195,7 @@ let a,
@test read(io, Char) == 'α'
@test_throws ArgumentError write(io,"!")
@test_throws ArgumentError write(io,'β')
a = Array{UInt8}(10)
a = Vector{UInt8}(uninitialized, 10)
@test read!(io, a) === a
@test String(a) == "helloworld"
@test read(io, Char) == 'ω'
Expand Down
2 changes: 1 addition & 1 deletion test/mod2pi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function testModPi()
numTestCases = size(testCases,1)
modFns = [mod2pi]
xDivisors = [2pi]
errsNew, errsOld = Array{Float64}(0), Array{Float64}(0)
errsNew, errsOld = Vector{Float64}(), Vector{Float64}()
for rowIdx in 1:numTestCases
xExact = testCases[rowIdx,1]
for colIdx in 1:1
Expand Down
2 changes: 1 addition & 1 deletion test/netload/memtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct RUsage
end

function get_vmsize()
ru = Array{RUsage}(1)
ru = Vector{RUsage}(uninitialized, 1)
ccall(:getrusage, Cint, (Cint, Ptr{Void}), 0, ru)
return ru[1].ru_maxrss
end
Expand Down
4 changes: 3 additions & 1 deletion test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,9 @@ end
f20065(B, i) = UInt8(B[i])
@testset "issue 20065" begin
# f20065 must be called from global scope to exhibit the buggy behavior
for B in (Array{Bool}(10), Array{Bool}(10,10), reinterpret(Bool, rand(UInt8, 10)))
for B in (Vector{Bool}(uninitialized, 10),
Matrix{Bool}(uninitialized, 10,10),
reinterpret(Bool, rand(UInt8, 10)))
@test all(x-> x <= 1, (f20065(B, i) for i in eachindex(B)))
for i in 1:length(B)
@test (@eval f20065($B, $i) <= 1)
Expand Down
6 changes: 3 additions & 3 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ S4 = OffsetArray(view(reshape(collect(1:4*3*2), 4, 3, 2), 1:3, 1:2, :), (-1,-2,1
@test A[1, [4,3]] == S[1, [4,3]] == [4,2]
@test A[:, :] == S[:, :] == A

A_3_3 = OffsetArray(Array{Int}(3,3), (-2,-1))
A_3_3 = OffsetArray(Matrix{Int}(uninitialized, 3,3), (-2,-1))
A_3_3[:, :] = reshape(1:9, 3, 3)
for i = 1:9 @test A_3_3[i] == i end
A_3_3[-1:1, 0:2] = reshape(1:9, 3, 3)
Expand Down Expand Up @@ -425,7 +425,7 @@ v = OffsetArray(rand(8), (-2,))
@test circshift(A, (-1,2)) == OffsetArray(circshift(parent(A), (-1,2)), A.offsets)

src = reshape(collect(1:16), (4,4))
dest = OffsetArray(Array{Int}(4,4), (-1,1))
dest = OffsetArray(Matrix{Int}(uninitialized, 4,4), (-1,1))
circcopy!(dest, src)
@test parent(dest) == [8 12 16 4; 5 9 13 1; 6 10 14 2; 7 11 15 3]
@test dest[1:3,2:4] == src[1:3,2:4]
Expand All @@ -442,7 +442,7 @@ module SimilarUR
stop::Int
end
ur = MyURange(1,3)
a = Array{Int}(2)
a = Vector{Int}(uninitialized, 2)
@test_throws MethodError similar(a, ur)
@test_throws MethodError similar(a, Float64, ur)
@test_throws MethodError similar(a, Float64, (ur,))
Expand Down
8 changes: 4 additions & 4 deletions test/perf/cat/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function cat2d_perf2(n, iter)
a = rand(n,n)
b = rand(n,n)
for i=1:iter
c = Array{Float64}(2n,2n)
c = Matrix{Float64}(uninitialized, 2n,2n)
c[ 1:n, 1:n] = a
c[ 1:n, n+1:end] = b
c[n+1:end,1:n] = b
Expand All @@ -35,7 +35,7 @@ function hcat_perf2(n, iter)
a = rand(n,n)
b = rand(n,n)
for i=1:iter
c = Array{Float64}(n, 4n)
c = Matrix{Float64}(uninitialized, n, 4n)
c[:, 1: n] = a
c[:, n+1: 2n] = b
c[:, 2n+1: 3n] = b
Expand All @@ -55,7 +55,7 @@ function vcat_perf2(n, iter)
a = rand(n,n)
b = rand(n,n)
for i=1:iter
c = Array{Float64}(4n, n)
c = Matrix{Float64}(uninitialized, 4n, n)
c[ 1: n, :] = a
c[ n+1:2n, :] = b
c[2n+1:3n, :] = b
Expand All @@ -75,7 +75,7 @@ function catnd_perf2(n, iter)
a = rand(1,n,n,1)
b = rand(1,n,n)
for i = 1:iter
c = Array{Float64}(1, n, 4n, 1)
c = Array{Float64}(uninitialized, 1, n, 4n, 1)
c[1,:, 1: n,1] = a
c[1,:, n+1:2n,1] = b
c[1,:,2n+1:3n,1] = b
Expand Down
2 changes: 1 addition & 1 deletion test/perf/kernel/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gc()

# issue #1211
include("ziggurat.jl")
a = Array{Float64}(1000000)
a = Vector{Float64}(uninitialized, 1000000)
@timeit randn_zig!(a) "randn_zig" "Ziggurat gaussian number generator"

# issue #950
Expand Down
2 changes: 1 addition & 1 deletion test/perf/perfutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
function maxrss(name)
# FIXME: call uv_getrusage instead here
@static if Sys.islinux()
rus = Array{Int64}(div(144,8))
rus = Vector{Int64}(uninitialized, div(144,8))
fill!(rus, 0x0)
res = ccall(:getrusage, Int32, (Int32, Ptr{Void}), 0, rus)
if res == 0
Expand Down
2 changes: 1 addition & 1 deletion test/perf/shootout/fannkuch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Based on the Javascript program
#
function fannkuch(n)
p = Array{Int32}(n)
p = Vector{Int32}(uninitialized, n)
for i = 1:n
p[i] = i
end
Expand Down
2 changes: 1 addition & 1 deletion test/perf/shootout/fasta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function choose_char(cs)
end
function random_fasta(symb, pr, n)
cs = cumsum(pr)
line = Array{UInt8}(line_width)
line = Vector{UInt8}(uninitialized, line_width)
k = n
while k > 0
m = min(k, line_width)
Expand Down
2 changes: 1 addition & 1 deletion test/perf/shootout/k_nucleotide.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function isless(x::KNuc, y::KNuc)
end

function sorted_array(m::Dict{AbstractString, Int})
kn = Array{KNuc}(length(m))
kn = Vector{KNuc}(uninitialized, length(m))
i = 1
for elem in m
kn[i] = KNuc(elem...)
Expand Down
2 changes: 1 addition & 1 deletion test/perf/shootout/meteor_contest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const pieces = (

const solutions = Any[]
const masks = zeros(UInt64, 10)
const masksAtCell = Array{Any}(width*height, height)
const masksAtCell = Matrix{Any}(uninitialized, width*height, height)

valid(x, y) = (0 <= x < width) && (0 <= y < height)
legal(mask::UInt64, board::UInt64) = (mask & board) == 0
Expand Down
8 changes: 4 additions & 4 deletions test/perf/sort/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if codespeed
for size in [2^6,2^16]
for s in sorts
if s == InsertionSort && size != 2^6; continue; end
data = Array{T}(size)
data = Vector{T}(uninitialized, size)
gc()

## Random
Expand All @@ -29,7 +29,7 @@ if codespeed

name = "$(typename)_$(size)_$(string(s)[1:end-5])_append"
desc = "$(string(s)) run on $(size) $(typename) elements pre-sorted 10 random elements appended"
@timeit_init(sort!(data, alg=s), begin data[end-9:end]=randfn!(Array{T}(10)) end, name, "")
@timeit_init(sort!(data, alg=s), begin data[end-9:end]=randfn!(Vector{T}(uninitialized, 10)) end, name, "")
end
end
end
Expand All @@ -44,7 +44,7 @@ else
if s == RadixSort && T == AbstractString continue end #Radix sort not implemented
if s == InsertionSort && logsize >=14 continue end #Too slow
println(s, s==RadixSort, s, typename, typename==AbstractString, logsize)
data = Array{T}(size)
data = Vector{T}(uninitialized, size)
gc()

## Random
Expand Down Expand Up @@ -73,7 +73,7 @@ else

## Sorted with 10 unsorted values appended
name = "$(typename)_$(logsize)_$(string(s)[1:end-5])_append"
@timeit_init(sort!(data, alg=s), begin data[end-9:end]=randfn!(Array{T}(10)) end, name, "")
@timeit_init(sort!(data, alg=s), begin data[end-9:end]=randfn!(Vector{T}(uninitialized, 10)) end, name, "")

## Random data with 4 unique values
name = "$(typename)_$(logsize)_$(string(s)[1:end-5])_4unique"
Expand Down
8 changes: 4 additions & 4 deletions test/perf/threads/laplace3d/laplace3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ end

## initialize and run
function laplace3d(nx=290, ny=290, nz=290; iters=1000, verify=false)
u1 = Array{Float32}(nx, ny, nz)
u3 = Array{Float32}(nx, ny, nz)
u1 = Array{Float32}(uninitialized, nx, ny, nz)
u3 = Array{Float32}(uninitialized, nx, ny, nz)
@nloops 3 k u1 begin
if @nany 3 d->(k_d == 1 || k_d == size(u1, d))
(@nref 3 u3 k) = (@nref 3 u1 k) = 1.0
Expand All @@ -106,8 +106,8 @@ function laplace3d(nx=290, ny=290, nz=290; iters=1000, verify=false)
u3 = foo
end
if verify
u1_orig = Array{Float32}(nx, ny, nz)
u3_orig = Array{Float32}(nx, ny, nz)
u1_orig = Array{Float32}(uninitialized, nx, ny, nz)
u3_orig = Array{Float32}(uninitialized, nx, ny, nz)
@nloops 3 k u1_orig begin
if @nany 3 d->(k_d == 1 || k_d == size(u1_orig, d))
(@nref 3 u3_orig k) = (@nref 3 u1_orig k) = 1.0
Expand Down
20 changes: 10 additions & 10 deletions test/perf/threads/lbm3d/lbm3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function relax!(F, UX, UY, UZ, nx, ny, nz, deltaU, t1D, t2D, t3D, sSQU, chunkid,
for l = 1:size(F,4)
density = density + F[i,j,k,l]
end
fs = Array{Float64}(6)
fs = Vector{Float64}(uninitialized, 6)
for l = 1:6
fs[l] = 0.0
for m = 1:5
Expand Down Expand Up @@ -139,7 +139,7 @@ function lbm3d(n)

CI = [0:matsize:matsize*19;]'

BOUND = Array{Float64}(nx,ny,nz)
BOUND = Array{Float64}(uninitialized, nx,ny,nz)

for i=1:nx, j=1:ny, k=1:nz
BOUND[i,j,k] = ((i-5)^2 + (j-6)^2 + (k-7)^2) < 6
Expand All @@ -153,14 +153,14 @@ function lbm3d(n)
TO_REFLECT = [ON+CI[2] ON+CI[3] ON+CI[4] ON+CI[5] ON+CI[6] ON+CI[7] ON+CI[8] ON+CI[9] ON+CI[10] ON+CI[11] ON+CI[12] ON+CI[13] ON+CI[14] ON+CI[15] ON+CI[16] ON+CI[17] ON+CI[18] ON+CI[19]]
REFLECTED = [ON+CI[3] ON+CI[2] ON+CI[5] ON+CI[4] ON+CI[7] ON+CI[6] ON+CI[11] ON+CI[10] ON+CI[9] ON+CI[8] ON+CI[15] ON+CI[14] ON+CI[13] ON+CI[12] ON+CI[19] ON+CI[18] ON+CI[17] ON+CI[16]]

UX = Array{Float64}(nx,ny,nz)
UY = Array{Float64}(nx,ny,nz)
UZ = Array{Float64}(nx,ny,nz)
U = Array{Float64}(12,nchunk)
t1D = Array{Float64}(nx,ny,nz)
t2D = Array{Float64}(nx,ny,nz)
t3D = Array{Float64}(nx,ny,nz)
sSQU = Array{Float64}(nx,ny,nz)
UX = Array{Float64}(uninitialized, nx,ny,nz)
UY = Array{Float64}(uninitialized, nx,ny,nz)
UZ = Array{Float64}(uninitialized, nx,ny,nz)
U = Array{Float64}(uninitialized, 12,nchunk)
t1D = Array{Float64}(uninitialized, nx,ny,nz)
t2D = Array{Float64}(uninitialized, nx,ny,nz)
t3D = Array{Float64}(uninitialized, nx,ny,nz)
sSQU = Array{Float64}(uninitialized, nx,ny,nz)

avu = 1
prevavu = 1
Expand Down
4 changes: 2 additions & 2 deletions test/perf/threads/stockcorr/pstockcorr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ function pstockcorr(n)
# Optimization: pre-allocate these for performance
# NOTE: the new GC will hopefully fix this, but currently GC time
# kills performance if we don't do in-place computations
Wiener = Array{Float64}(T-1, 2)
CorrWiener = Array{Float64}(T-1, 2)
Wiener = Matrix{Float64}(uninitialized, T-1, 2)
CorrWiener = Matrix{Float64}(uninitialized, T-1, 2)

# Runtime requirement: need per-thread RNG since it stores state
rngs = [MersenneTwister(777+x) for x in 1:nthreads()]
Expand Down

0 comments on commit af93075

Please sign in to comment.