Skip to content

Commit

Permalink
Change CartesianIndex to use Integer, consistent with #10458
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Mar 17, 2015
1 parent 8787420 commit 705efdc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ linearindexing{A<:BitArray}(::Type{A}) = LinearFast()
# CartesianIndex
abstract CartesianIndex{N}

stagedfunction Base.call{N}(::Type{CartesianIndex},index::NTuple{N,Real})
stagedfunction Base.call{N}(::Type{CartesianIndex},index::NTuple{N,Integer})
indextype = gen_cartesian(N)
return Expr(:call,indextype,[:(to_index(index[$i])) for i=1:N]...)
end
stagedfunction Base.call{N}(::Type{CartesianIndex{N}},index::Real...)
stagedfunction Base.call{N}(::Type{CartesianIndex{N}},index::Integer...)
length(index) == N && return :(CartesianIndex(index))
length(index) > N && throw(DimensionMismatch("Cannot create CartesianIndex{$N} from $(length(index)) indexes"))
args = [i <= length(index) ? :(index[$i]) : 1 for i = 1:N]
:(CartesianIndex(tuple($(args...))))
end
Base.call{M,N}(::Type{CartesianIndex{N}},index::NTuple{M,Real}) = CartesianIndex{N}(index...)
Base.call{M,N}(::Type{CartesianIndex{N}},index::NTuple{M,Integer}) = CartesianIndex{N}(index...)

let implemented = IntSet()
global gen_cartesian
Expand All @@ -36,7 +36,7 @@ let implemented = IntSet()
fields = [Expr(:(::), fnames[i], :Int) for i = 1:N]
extype = Expr(:type, false, Expr(:(<:), indextype, Expr(:curly, :CartesianIndex, N)), Expr(:block, fields...))
eval(extype)
argsleft = [Expr(:(::), fnames[i], :Real) for i = 1:N]
argsleft = [Expr(:(::), fnames[i], :Integer) for i = 1:N]
argsright = [Expr(:call,:to_index,fnames[i]) for i=1:N]
exconstructor = Expr(:(=),Expr(:call,:(Base.call),:(::Type{CartesianIndex{$N}}),argsleft...),Expr(:call,indextype,argsright...))
eval(exconstructor)
Expand Down

0 comments on commit 705efdc

Please sign in to comment.