Skip to content

Commit 11ec2b2

Browse files
authored
support specifying dimensions with non-Int integers (#47)
`Array` supports the same for their `undef` constructor (although `Memory` doesn't), so `FixedSizeArray` probably should, too.
1 parent 43de14c commit 11ec2b2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/FixedSizeArrays.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ const FixedSizeMatrix{T} = FixedSizeArray{T,2}
2323
function FixedSizeArray{T,N}(::UndefInitializer, size::NTuple{N,Int}) where {T,N}
2424
FixedSizeArray{T,N}(Internal(), Memory{T}(undef, checked_dims(size)), size)
2525
end
26-
function FixedSizeArray{T,N}(::UndefInitializer, size::Vararg{Int,N}) where {T,N}
26+
function FixedSizeArray{T,N}(::UndefInitializer, size::NTuple{N,Integer}) where {T,N}
27+
ints = map(Int, size)::NTuple{N,Int} # prevent infinite recursion
28+
FixedSizeArray{T,N}(undef, ints)
29+
end
30+
function FixedSizeArray{T,N}(::UndefInitializer, size::Vararg{Integer,N}) where {T,N}
2731
FixedSizeArray{T,N}(undef, size)
2832
end
29-
function FixedSizeArray{T}(::UndefInitializer, size::Vararg{Int,N}) where {T,N}
33+
function FixedSizeArray{T}(::UndefInitializer, size::Vararg{Integer,N}) where {T,N}
3034
FixedSizeArray{T,N}(undef, size)
3135
end
32-
function FixedSizeArray{T}(::UndefInitializer, size::NTuple{N,Int}) where {T,N}
36+
function FixedSizeArray{T}(::UndefInitializer, size::NTuple{N,Integer}) where {T,N}
3337
FixedSizeArray{T,N}(undef, size)
3438
end
3539

test/runtests.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ end
4747
siz = ntuple(Returns(2), dim_count)
4848
T = FixedSizeArray{Float64}
4949
R = FixedSizeArray{Float64,dim_count}
50-
for args ((undef, siz), (undef, siz...))
51-
test_inferred( R, args)
52-
test_inferred(T, R, args)
50+
for sz (siz, map(BigInt, siz))
51+
for args ((undef, sz), (undef, sz...))
52+
test_inferred( R, args)
53+
test_inferred(T, R, args)
54+
end
5355
end
5456
end
5557
for offset (-1, 0, 2, 3)

0 commit comments

Comments
 (0)