Skip to content

Commit da80d63

Browse files
committed
fix ambiguity warning, small change for type stability in non-Int case
1 parent c00bdcc commit da80d63

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

base/abstractarray.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ function repmat(a::AbstractVector, m::Int)
10301030
return b
10311031
end
10321032

1033-
sub2ind(dims) = 1
1033+
sub2ind(dims::(Integer...,)) = 1
10341034
stagedfunction sub2ind{N}(dims::NTuple{N,Integer},I::Integer...)
10351035
length(I) == N || throw(ArgumentError("number of subscripts should match length of dims"))
10361036
ex=:(I[$N])
@@ -1052,24 +1052,25 @@ function sub2ind{T<:Integer}(dims::Array{T}, sub::Array{T})
10521052
return ind
10531053
end
10541054

1055-
sub2ind{T<:Integer}(dims, I::AbstractVector{T}...) =
1055+
sub2ind{T<:Integer}(dims::(Integer...,), I::AbstractVector{T}...) =
10561056
[ sub2ind(dims, map(X->X[i], I)...)::Int for i=1:length(I[1]) ]
10571057

10581058

10591059
ind2sub(dims::(), ind::Integer) = ind==1 ? () : throw(BoundsError())
1060-
stagedfunction ind2sub{N}(dims::NTuple{N,Integer}, ind::Int)
1060+
stagedfunction ind2sub{N}(dims::NTuple{N,Integer}, ind::Integer)
10611061
subsyms = [symbol("i$k") for k=1:N]
1062-
subex = Expr(:block,[:($(subsyms[k])=rem(ind,dims[$k])+1;ind=div(ind,dims[$k])) for k=1:N-1]...)
1062+
subex = Expr(:block,[:($(subsyms[k])=rem(rest,dims[$k])+1;rest=div(rest,dims[$k])) for k=1:N-1]...)
10631063
quote
1064-
ind-=1
1064+
$(Expr(:meta,:inline))
1065+
rest::Int=ind-1
10651066
$(subex)
1066-
$(subsyms[N]) = ind+1
1067+
$(subsyms[N]) = rest+1
10671068
$(Expr(:tuple,subsyms...))
10681069
end
10691070
end
1070-
ind2sub(a::AbstractArray, ind::Integer) = ind2sub(size(a), Int(ind))
1071+
ind2sub(a::AbstractArray, ind::Integer) = ind2sub(size(a), ind)
10711072

1072-
function ind2sub{T<:Integer}(dims::(Integer,Integer...), ind::AbstractVector{T})
1073+
function ind2sub{T<:Integer}(dims::(Integer...), ind::AbstractVector{T})
10731074
n = length(dims)
10741075
l = length(ind)
10751076
t = ntuple(n, x->Array(Int, l))

0 commit comments

Comments
 (0)