Skip to content

Commit 35833ca

Browse files
committed
Origin accepts Numbers
1 parent c205797 commit 35833ca

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/origin.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ struct Origin{T<:Union{Tuple{Vararg{Int}}, Int}}
2727
index::T
2828
end
2929
Origin(I::Tuple{Vararg{Int}}) = Origin{typeof(I)}(I)
30-
Origin(I::Tuple{Vararg{Integer}}) = Origin(map(Int, I))
30+
Origin(I::Tuple{Vararg{Number}}) = Origin(map(Int, I))
3131
Origin(I::CartesianIndex) = Origin(Tuple(I))
32-
Origin(I::Integer...) = Origin(I)
32+
Origin(I::Number...) = Origin(I)
3333
# Origin(0) != Origin((0, )) but they work the same with broadcasting
34-
Origin(n::Integer) = Origin{Int}(Int(n))
34+
Origin(n::Number) = Origin{Int}(Int(n))
3535

3636
(o::Origin)(A::AbstractArray) = o.index .- first.(axes(A))
3737

test/origin.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ using OffsetArrays: Origin
66
@test Origin(CartesianIndex(1, 2)) === Origin((1, 2)) === Origin(1, 2)
77

88
@test Origin(Int32.((1,2))) == Origin(Int64.((1,2)))
9-
@test Origin(Int32.((1,2))...) == Origin(Int64.((1,2))...)
10-
@test Origin(Int32(1)) == Origin(Int64(1))
9+
@test Origin(Int32.((1,2))...) == Origin(Int64.((1,2))...) == Origin((1.0, 2.0))
10+
@test Origin(Int32(1)) == Origin(Int64(1)) == Origin(1.0)
11+
@test_throws Exception Origin(1.5)
1112

1213
# 0d
1314
A = OffsetArray(zeros())

0 commit comments

Comments
 (0)