@@ -1030,7 +1030,7 @@ function repmat(a::AbstractVector, m::Int)
1030
1030
return b
1031
1031
end
1032
1032
1033
- sub2ind (dims) = 1
1033
+ sub2ind (dims:: (Integer...,) ) = 1
1034
1034
stagedfunction sub2ind {N} (dims:: NTuple{N,Integer} ,I:: Integer... )
1035
1035
length (I) == N || throw (ArgumentError (" number of subscripts should match length of dims" ))
1036
1036
ex= :(I[$ N])
@@ -1052,24 +1052,25 @@ function sub2ind{T<:Integer}(dims::Array{T}, sub::Array{T})
1052
1052
return ind
1053
1053
end
1054
1054
1055
- sub2ind {T<:Integer} (dims, I:: AbstractVector{T} ...) =
1055
+ sub2ind {T<:Integer} (dims:: (Integer...,) , I:: AbstractVector{T} ...) =
1056
1056
[ sub2ind (dims, map (X-> X[i], I)... ):: Int for i= 1 : length (I[1 ]) ]
1057
1057
1058
1058
1059
1059
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 )
1061
1061
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 ]. .. )
1063
1063
quote
1064
- ind-= 1
1064
+ $ (Expr (:meta ,:inline ))
1065
+ rest:: Int = ind- 1
1065
1066
$ (subex)
1066
- $ (subsyms[N]) = ind + 1
1067
+ $ (subsyms[N]) = rest + 1
1067
1068
$ (Expr (:tuple ,subsyms... ))
1068
1069
end
1069
1070
end
1070
- ind2sub (a:: AbstractArray , ind:: Integer ) = ind2sub (size (a), Int ( ind) )
1071
+ ind2sub (a:: AbstractArray , ind:: Integer ) = ind2sub (size (a), ind)
1071
1072
1072
- function ind2sub {T<:Integer} (dims:: (Integer,Integer ...) , ind:: AbstractVector{T} )
1073
+ function ind2sub {T<:Integer} (dims:: (Integer...) , ind:: AbstractVector{T} )
1073
1074
n = length (dims)
1074
1075
l = length (ind)
1075
1076
t = ntuple (n, x-> Array (Int, l))
0 commit comments