Skip to content

Commit c6eef37

Browse files
authored
Test mixed-type constructors. (#465)
1 parent bc499bd commit c6eef37

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/JLArrays/src/JLArrays.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,17 @@ const JLVector{T} = JLArray{T,1}
203203
const JLMatrix{T} = JLArray{T,2}
204204
const JLVecOrMat{T} = Union{JLVector{T},JLMatrix{T}}
205205

206-
# type and dimensionality specified, accepting dims as series of Ints
207-
JLArray{T,N}(::UndefInitializer, dims::Integer...) where {T,N} = JLArray{T,N}(undef, dims)
206+
# type and dimensionality specified
207+
JLArray{T,N}(::UndefInitializer, dims::NTuple{N,Integer}) where {T,N} =
208+
JLArray{T,N}(undef, convert(Tuple{Vararg{Int}}, dims))
209+
JLArray{T,N}(::UndefInitializer, dims::Vararg{Integer,N}) where {T,N} =
210+
JLArray{T,N}(undef, convert(Tuple{Vararg{Int}}, dims))
208211

209212
# type but not dimensionality specified
210-
JLArray{T}(::UndefInitializer, dims::Dims{N}) where {T,N} = JLArray{T,N}(undef, dims)
211-
JLArray{T}(::UndefInitializer, dims::Integer...) where {T} =
212-
JLArray{T}(undef, convert(Tuple{Vararg{Int}}, dims))
213+
JLArray{T}(::UndefInitializer, dims::NTuple{N,Integer}) where {T,N} =
214+
JLArray{T,N}(undef, convert(Tuple{Vararg{Int}}, dims))
215+
JLArray{T}(::UndefInitializer, dims::Vararg{Integer,N}) where {T,N} =
216+
JLArray{T,N}(undef, convert(Dims{N}, dims))
213217

214218
# empty vector constructor
215219
JLArray{T,1}() where {T} = JLArray{T,1}(undef, 0)

test/testsuite/construction.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
# compare against Array
2121
for typs in [(), (Int,), (Int,1), (Int,2), (Float32,), (Float32,1), (Float32,2)],
22-
args in [(), (1,), (1,2), ((1,),), ((1,2),),
23-
(undef,), (undef, 1,), (undef, 1,2), (undef, (1,),), (undef, (1,2),),
24-
(Int,), (Int, 1,), (Int, 1,2), (Int, (1,),), (Int, (1,2),),
22+
args in [(), (1,), (1,2), (Int32(1),Int64(2)), ((1,),), ((1,2),),
23+
((Int32(1),Int64(2)),),
24+
(undef,), (undef, 1,), (undef, 1,2), (undef, Int32(1),Int64(2)),
25+
(undef, (1,),), (undef, (1,2),), (undef, (Int32(1),Int64(2)),),
26+
(Int,), (Int, 1,), (Int, 1,2), (Int, Int32(1),Int64(2)), (Int, (1,),),
27+
(Int, (1,2),), (Int, (Int32(1),Int64(2)),),
2528
([1,2],), ([1 2],)]
2629
cpu = try
2730
Array{typs...}(args...)

0 commit comments

Comments
 (0)