Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct OffsetArray{T,N,AA<:AbstractArray{T,N}} <: AbstractArray{T,N}
end

function OffsetArray{T, N, AA}(parent::AA, offsets::NTuple{N, <:Integer}) where {T, N, AA<:AbstractArray{T,N}}
OffsetArray{T, N, AA}(parent, map(x -> convert(Int, x), offsets))
OffsetArray{T, N, AA}(parent, map(x -> convert(Int, x)::Int, offsets))
end

"""
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ end
@test first(rred) == first(r)
end

# used in testing the constructor
struct WeirdInteger{T} <: Integer
x :: T
end
# assume that it doesn't behave as expected
Base.convert(::Type{Int}, a::WeirdInteger) = a

@testset "Constructors" begin
@testset "Single-entry arrays in dims 0:5" begin
for n = 0:5
Expand Down Expand Up @@ -535,6 +542,9 @@ end
@test_throws TypeError OffsetArray{Float64,2,Matrix{ComplexF64}}
# ndim of an OffsetArray should match that of the parent
@test_throws TypeError OffsetArray{Float64,3,Matrix{Float64}}

# should throw a TypeError if the offsets can not be converted to Ints
@test_throws TypeError OffsetVector{Int,Vector{Int}}(zeros(Int,2), (WeirdInteger(1),))
end

@testset "custom range types" begin
Expand Down