Skip to content

Commit 26b351c

Browse files
Sacha0fredrikekre
authored andcommitted
Replace Array(shape...)-like calls in test/a*.jl. (#24740)
1 parent 2b326d3 commit 26b351c

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

test/TestHelpers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ OffsetVector{T,AA<:AbstractArray} = OffsetArray{T,1,AA}
129129
OffsetArray(A::AbstractArray{T,N}, offsets::NTuple{N,Int}) where {T,N} = OffsetArray{T,N,typeof(A)}(A, offsets)
130130
OffsetArray(A::AbstractArray{T,N}, offsets::Vararg{Int,N}) where {T,N} = OffsetArray(A, offsets)
131131

132-
OffsetArray{T,N}(inds::Indices{N}) where {T,N} = OffsetArray{T,N,Array{T,N}}(Array{T,N}(map(length, inds)), map(indsoffset, inds))
132+
OffsetArray{T,N}(inds::Indices{N}) where {T,N} = OffsetArray{T,N,Array{T,N}}(Array{T,N}(uninitialized, map(length, inds)), map(indsoffset, inds))
133133
OffsetArray{T}(inds::Indices{N}) where {T,N} = OffsetArray{T,N}(inds)
134134

135135
Base.IndexStyle(::Type{T}) where {T<:OffsetArray} = Base.IndexStyle(parenttype(T))

test/abstractarray.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ function test_primitives(::Type{T}, shape, ::Type{TestAbstractArray}) where T
447447
@test_throws DimensionMismatch reshape(B, (0, 1))
448448

449449
# copy!(dest::AbstractArray, src::AbstractArray)
450-
@test_throws BoundsError copy!(Array{Int}(10), [1:11...])
450+
@test_throws BoundsError copy!(Vector{Int}(uninitialized, 10), [1:11...])
451451

452452
# convert{T, N}(::Type{Array}, A::AbstractArray{T, N})
453453
X = [1:10...]
@@ -542,14 +542,14 @@ function test_cat(::Type{TestAbstractArray})
542542
A = T24Linear([1:24...])
543543
b_int = reshape([1:27...], 3, 3, 3)
544544
b_float = reshape(Float64[1:27...], 3, 3, 3)
545-
b2hcat = Array{Float64}(3, 6, 3)
545+
b2hcat = Array{Float64}(uninitialized, 3, 6, 3)
546546
b1 = reshape([1:9...], 3, 3)
547547
b2 = reshape([10:18...], 3, 3)
548548
b3 = reshape([19:27...], 3, 3)
549549
b2hcat[:, :, 1] = hcat(b1, b1)
550550
b2hcat[:, :, 2] = hcat(b2, b2)
551551
b2hcat[:, :, 3] = hcat(b3, b3)
552-
b3hcat = Array{Float64}(3, 9, 3)
552+
b3hcat = Array{Float64}(uninitialized, 3, 9, 3)
553553
b3hcat[:, :, 1] = hcat(b1, b1, b1)
554554
b3hcat[:, :, 2] = hcat(b2, b2, b2)
555555
b3hcat[:, :, 3] = hcat(b3, b3, b3)
@@ -674,7 +674,7 @@ function test_map(::Type{TestAbstractArray})
674674
end
675675

676676
# AbstractArray map for N-arg case
677-
A = Array{Int}(10)
677+
A = Array{Int}(uninitialized, 10)
678678
f(x, y, z) = x + y + z
679679
D = Float64[1:10...]
680680

@@ -869,7 +869,7 @@ end
869869
@testset "ImageCore #40" begin
870870
Base.convert(::Type{Array{T,n}}, a::Array{T,n}) where {T<:Number,n} = a
871871
Base.convert(::Type{Array{T,n}}, a::Array) where {T<:Number,n} =
872-
copy!(Array{T,n}(size(a)), a)
872+
copy!(Array{T,n}(uninitialized, size(a)), a)
873873
@test isa(similar(Dict(:a=>1, :b=>2.0), Pair{Union{},Union{}}), Dict{Union{}, Union{}})
874874
end
875875

test/ambiguous.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,10 @@ end
219219

220220
foo(::Type{Array{T,N}}, A::MyArray{T,N}) where {T,N} = A.data
221221
foo(::Type{Array{T,N}}, A::MyArray{T,N}) where {T<:AbstractFloat,N} = A.data
222-
foo(::Type{Array{S,N}}, A::AbstractArray{T,N}) where {S<:AbstractFloat,N,T<:AbstractFloat} = copy!(Array{S}(size(A)), A)
223-
foo(::Type{Array{S,N}}, A::MyArray{T,N}) where {S<:AbstractFloat,N,T<:AbstractFloat} = copy!(Array{S}(size(A)), A.data)
222+
foo(::Type{Array{S,N}}, A::MyArray{T,N}) where {S<:AbstractFloat,N,T<:AbstractFloat} =
223+
copy!(Array{S}(uninitialized, unsize(A)), A.data)
224+
foo(::Type{Array{S,N}}, A::AbstractArray{T,N}) where {S<:AbstractFloat,N,T<:AbstractFloat} =
225+
copy!(Array{S}(uninitialized, size(A)), A)
224226
end
225227

226228
@test isempty(detect_ambiguities(Ambig17648))

test/arrayops.jl

+28-28
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ using Main.TestHelpers.OAs
6060
a[:, [1 2]] = 2
6161
@test a == 2ones(2,2)
6262

63-
a = Array{Float64}(2, 2, 2, 2, 2)
63+
a = Array{Float64}(uninitialized, 2, 2, 2, 2, 2)
6464
a[1,1,1,1,1] = 10
6565
a[1,2,1,1,2] = 20
6666
a[1,1,2,2,1] = 30
@@ -295,19 +295,19 @@ end
295295
@test length(rt) == 1 && rt[1] == Array{Int32, 3}
296296
end
297297
@testset "construction" begin
298-
@test typeof(Vector{Int}(3)) == Vector{Int}
298+
@test typeof(Vector{Int}(uninitialized, 3)) == Vector{Int}
299299
@test typeof(Vector{Int}()) == Vector{Int}
300-
@test typeof(Vector(3)) == Vector{Any}
300+
@test typeof(Vector(uninitialized, 3)) == Vector{Any}
301301
@test typeof(Vector()) == Vector{Any}
302-
@test typeof(Matrix{Int}(2,3)) == Matrix{Int}
303-
@test typeof(Matrix(2,3)) == Matrix{Any}
302+
@test typeof(Matrix{Int}(uninitialized, 2,3)) == Matrix{Int}
303+
@test typeof(Matrix(uninitialized, 2,3)) == Matrix{Any}
304304

305-
@test size(Vector{Int}(3)) == (3,)
305+
@test size(Vector{Int}(uninitialized, 3)) == (3,)
306306
@test size(Vector{Int}()) == (0,)
307-
@test size(Vector(3)) == (3,)
307+
@test size(Vector(uninitialized, 3)) == (3,)
308308
@test size(Vector()) == (0,)
309-
@test size(Matrix{Int}(2,3)) == (2,3)
310-
@test size(Matrix(2,3)) == (2,3)
309+
@test size(Matrix{Int}(uninitialized, 2,3)) == (2,3)
310+
@test size(Matrix(uninitialized, 2,3)) == (2,3)
311311

312312
# TODO: will throw MethodError after 0.6 deprecations are deleted
313313
dw = Base.JLOptions().depwarn
@@ -399,9 +399,9 @@ end
399399
@test_throws MethodError UInt8[1:3]
400400
@test_throws MethodError UInt8[1:3,]
401401
@test_throws MethodError UInt8[1:3,4:6]
402-
a = Array{UnitRange{Int}}(1); a[1] = 1:3
402+
a = Vector{UnitRange{Int}}(uninitialized, 1); a[1] = 1:3
403403
@test _array_equiv([1:3,], a)
404-
a = Array{UnitRange{Int}}(2); a[1] = 1:3; a[2] = 4:6
404+
a = Vector{UnitRange{Int}}(uninitialized, 2); a[1] = 1:3; a[2] = 4:6
405405
@test _array_equiv([1:3,4:6], a)
406406
end
407407

@@ -815,7 +815,7 @@ end
815815
R = repeat(A, inner = (1, 1, 2), outer = (1, 1, 1))
816816
T = reshape([1:4; 1:4; 5:8; 5:8], 2, 2, 4)
817817
@test R == T
818-
A = Array{Int}(2, 2, 2)
818+
A = Array{Int}(uninitialized, 2, 2, 2)
819819
A[:, :, 1] = [1 2;
820820
3 4]
821821
A[:, :, 2] = [5 6;
@@ -1110,7 +1110,7 @@ end
11101110
end
11111111

11121112
@testset "fill" begin
1113-
@test fill!(Array{Float64}(1),-0.0)[1] === -0.0
1113+
@test fill!(Float64[1.0], -0.0)[1] === -0.0
11141114
A = ones(3,3)
11151115
S = view(A, 2, 1:3)
11161116
fill!(S, 2)
@@ -1119,7 +1119,7 @@ end
11191119
@test A == [1 1 3; 2 2 3; 1 1 1]
11201120
rt = Base.return_types(fill!, Tuple{Array{Int32, 3}, UInt8})
11211121
@test length(rt) == 1 && rt[1] == Array{Int32, 3}
1122-
A = Array{Union{UInt8,Int8}}(3)
1122+
A = Vector{Union{UInt8,Int8}}(uninitialized, 3)
11231123
fill!(A, UInt8(3))
11241124
@test A == [0x03, 0x03, 0x03]
11251125
# Issue #9964
@@ -1265,7 +1265,7 @@ end
12651265
@test isequal(flipdim(1:10, 1), 10:-1:1)
12661266
@test_throws ArgumentError flipdim(1:10, 2)
12671267
@test_throws ArgumentError flipdim(1:10, -1)
1268-
@test isequal(flipdim(Array{Int}(0,0),1), Array{Int}(0,0)) # issue #5872
1268+
@test isequal(flipdim(Matrix{Int}(uninitialized, 0,0),1), Matrix{Int}(uninitialized, 0,0)) # issue #5872
12691269

12701270
a = rand(5,3)
12711271
@test flipdim(flipdim(a,2),2) == a
@@ -1392,25 +1392,25 @@ end
13921392
@test pr8622() == [0,3,1,0]
13931393

13941394
#6828 - size of specific dimensions
1395-
let a = Array{Float64}(10)
1395+
let a = Array{Float64}(uninitialized, 10)
13961396
@test size(a) == (10,)
13971397
@test size(a, 1) == 10
13981398
@test size(a,2,1) == (1,10)
1399-
aa = Array{Float64}(2,3)
1399+
aa = Array{Float64}(uninitialized, 2,3)
14001400
@test size(aa) == (2,3)
14011401
@test size(aa,4,3,2,1) == (1,1,3,2)
14021402
@test size(aa,1,2) == (2,3)
1403-
aaa = Array{Float64}(9,8,7,6,5,4,3,2,1)
1403+
aaa = Array{Float64}(uninitialized, 9,8,7,6,5,4,3,2,1)
14041404
@test size(aaa,1,1) == (9,9)
14051405
@test size(aaa,4) == 6
14061406
@test size(aaa,9,8,7,6,5,4,3,2,19,8,7,6,5,4,3,2,1) == (1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9)
14071407

14081408
#18459 Test Array{T, N} constructor
1409-
b = Array{Float64, 1}(10)
1409+
b = Vector{Float64}(uninitialized, 10)
14101410
@test size(a) == size(b)
1411-
bb = Array{Float64, 2}(2,3)
1411+
bb = Matrix{Float64}(uninitialized, 2,3)
14121412
@test size(aa) == size(bb)
1413-
bbb = Array{Float64, 9}(9,8,7,6,5,4,3,2,1)
1413+
bbb = Array{Float64,9}(uninitialized, 9,8,7,6,5,4,3,2,1)
14141414
@test size(aaa) == size(bbb)
14151415
end
14161416

@@ -2075,21 +2075,21 @@ end # module AutoRetType
20752075
@test isa(cat((1,2), densevec, densemat), Array)
20762076
end
20772077

2078-
@testset "type constructor Array{T, N}(d...) works (especially for N>3)" begin
2079-
a = Array{Float64}(10)
2080-
b = Array{Float64, 1}(10)
2078+
@testset "type constructor Array{T, N}(uninitialized, d...) works (especially for N>3)" begin
2079+
a = Array{Float64}(uninitialized, 10)
2080+
b = Vector{Float64}(uninitialized, 10)
20812081
@test size(a) == (10,)
20822082
@test size(a, 1) == 10
20832083
@test size(a,2,1) == (1,10)
20842084
@test size(a) == size(b)
2085-
a = Array{Float64}(2,3)
2086-
b = Array{Float64, 2}(2,3)
2085+
a = Array{Float64}(uninitialized, 2,3)
2086+
b = Matrix{Float64}(uninitialized, 2,3)
20872087
@test size(a) == (2,3)
20882088
@test size(a,4,3,2,1) == (1,1,3,2)
20892089
@test size(a,1,2) == (2,3)
20902090
@test size(a) == size(b)
2091-
a = Array{Float64}(9,8,7,6,5,4,3,2,1)
2092-
b = Array{Float64, 9}(9,8,7,6,5,4,3,2,1)
2091+
a = Array{Float64}(uninitialized, 9,8,7,6,5,4,3,2,1)
2092+
b = Array{Float64,9}(uninitialized, 9,8,7,6,5,4,3,2,1)
20932093
@test size(a,1,1) == (9,9)
20942094
@test size(a,4) == 6
20952095
@test size(a,9,8,7,6,5,4,3,2,19,8,7,6,5,4,3,2,1) == (1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9)

0 commit comments

Comments
 (0)