Skip to content

Commit

Permalink
change for i in 1:length(a) to i in eachindex(a) (continuing JuliaLan…
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Aug 24, 2015
1 parent f6cde37 commit 5df7daa
Show file tree
Hide file tree
Showing 52 changed files with 164 additions and 161 deletions.
2 changes: 1 addition & 1 deletion base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function complete_symbol(sym, ffunc)
# We're now looking for a type
fields = fieldnames(t)
found = false
for i in 1:length(fields)
for i in eachindex(fields)
s == fields[i] || continue
t = t.types[i]
Base.isstructtype(t) || return UTF8String[]
Expand Down
20 changes: 10 additions & 10 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typealias RangeIndex Union{Int, Range{Int}, UnitRange{Int}, Colon}
## Basic functions ##

vect() = Array(Any, 0)
vect{T}(X::T...) = T[ X[i] for i=1:length(X) ]
vect{T}(X::T...) = T[ X[i] for i in eachindex(X) ]

const _oldstyle_array_vcat_ = true

Expand Down Expand Up @@ -44,7 +44,7 @@ if _oldstyle_array_vcat_
else
function vect(X...)
T = promote_typeof(X...)
#T[ X[i] for i=1:length(X) ]
#T[ X[i] for i in eachindex(X) ]
# TODO: this is currently much faster. should figure out why. not clear.
copy!(Array(T,length(X)), X)
end
Expand Down Expand Up @@ -703,8 +703,8 @@ hcat() = Array(Any, 0)
## cat: special cases
hcat{T}(X::T...) = T[ X[j] for i=1, j=1:length(X) ]
hcat{T<:Number}(X::T...) = T[ X[j] for i=1, j=1:length(X) ]
vcat{T}(X::T...) = T[ X[i] for i=1:length(X) ]
vcat{T<:Number}(X::T...) = T[ X[i] for i=1:length(X) ]
vcat{T}(X::T...) = T[ X[i] for i in eachindex(X) ]
vcat{T<:Number}(X::T...) = T[ X[i] for i in eachindex(X) ]

function vcat(X::Number...)
T = promote_typeof(X...)
Expand All @@ -723,7 +723,7 @@ function vcat{T}(V::AbstractVector{T}...)
end
a = similar(full(V[1]), n)
pos = 1
for k=1:length(V)
for k in eachindex(V)
Vk = V[k]
p1 = pos+length(Vk)-1
a[pos:p1] = Vk
Expand Down Expand Up @@ -800,12 +800,12 @@ function cat_t(catdims, typeC::Type, X...)
ndimsC = max(maximum(ndimsX), maximum(catdims))
catsizes = zeros(Int,(nargs,length(catdims)))
dims2cat = zeros(Int,ndimsC)
for k = 1:length(catdims)
for k in eachindex(catdims)
dims2cat[catdims[k]]=k
end

dimsC = Int[d <= ndimsX[1] ? size(X[1],d) : 1 for d=1:ndimsC]
for k = 1:length(catdims)
for k in eachindex(catdims)
catsizes[1,k] = dimsC[catdims[k]]
end
for i = 2:nargs
Expand All @@ -832,7 +832,7 @@ function cat_t(catdims, typeC::Type, X...)
cat_one = [ dims2cat[d] == 0 ? (1:dimsC[d]) : (offsets[dims2cat[d]]+(1:catsizes[i,dims2cat[d]]))
for d=1:ndimsC ]
C[cat_one...] = X[i]
for k = 1:length(catdims)
for k in eachindex(catdims)
offsets[k] += catsizes[i,k]
end
end
Expand Down Expand Up @@ -1291,7 +1291,7 @@ end
## 1 argument
map!{F}(f::F, A::AbstractArray) = map!(f, A, A)
function map!{F}(f::F, dest::AbstractArray, A::AbstractArray)
for i = 1:length(A)
for i in eachindex(A)
dest[i] = f(A[i])
end
return dest
Expand Down Expand Up @@ -1328,7 +1328,7 @@ end

## 2 argument
function map!{F}(f::F, dest::AbstractArray, A::AbstractArray, B::AbstractArray)
for i = 1:length(A)
for i in eachindex(A)
dest[i] = f(A[i], B[i])
end
return dest
Expand Down
6 changes: 3 additions & 3 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _sub(t::Tuple, ::Tuple{}) = t
_sub(t::Tuple, s::Tuple) = _sub(tail(t), tail(s))

function squeeze(A::AbstractArray, dims::Dims)
for i in 1:length(dims)
for i in eachindex(dims)
1 <= dims[i] <= ndims(A) || throw(ArgumentError("squeezed dims must be in range 1:ndims(A)"))
size(A, dims[i]) == 1 || throw(ArgumentError("squeezed dims must all be size 1"))
for j = 1:i-1
Expand Down Expand Up @@ -144,7 +144,7 @@ function cumsum_kbn{T<:AbstractFloat}(A::AbstractArray{T}, axis::Integer=1)
B = similar(A)
C = similar(A)

for i = 1:length(A)
for i in eachindex(A)
if div(i-1, axis_stride) % axis_size == 0
B[i] = A[i]
C[i] = zero(T)
Expand All @@ -167,7 +167,7 @@ end

function ipermutedims(A::AbstractArray,perm)
iperm = Array(Int,length(perm))
for i = 1:length(perm)
for i in eachindex(perm)
iperm[perm[i]] = i
end
return permutedims(A,iperm)
Expand Down
22 changes: 11 additions & 11 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function call{P<:Ptr,T}(::Type{Ref{P}}, a::Array{T}) # Ref{P<:Ptr}(a::Array)
else
ptrs = Array(P, length(a)+1)
roots = Array(Any, length(a))
for i = 1:length(a)
for i in eachindex(a)
root = cconvert(P, a[i])
ptrs[i] = unsafe_convert(P, root)::P
roots[i] = root
Expand Down Expand Up @@ -163,15 +163,15 @@ similar{T}(a::Array{T,2}, S) = Array(S, size(a,1), size(a,2))
# T[x...] constructs Array{T,1}
function getindex(T::Type, vals...)
a = Array(T,length(vals))
@inbounds for i = 1:length(vals)
@inbounds for i in eachindex(vals)
a[i] = vals[i]
end
return a
end

function getindex(::Type{Any}, vals::ANY...)
a = Array(Any,length(vals))
@inbounds for i = 1:length(vals)
@inbounds for i in eachindex(vals)
a[i] = vals[i]
end
return a
Expand Down Expand Up @@ -680,7 +680,7 @@ function hcat{T}(V::Vector{T}...)
throw(DimensionMismatch("vectors must have same lengths"))
end
end
[ V[j][i]::T for i=1:length(V[1]), j=1:length(V) ]
[ V[j][i]::T for i in eachindex(V[1]), j in eachindex(V) ]
end


Expand Down Expand Up @@ -750,7 +750,7 @@ function find(testf::Function, A::AbstractArray)
# use a dynamic-length array to store the indexes, then copy to a non-padded
# array for the return
tmpI = Array(Int, 0)
for i = 1:length(A)
for i in eachindex(A)
if testf(A[i])
push!(tmpI, i)
end
Expand All @@ -764,7 +764,7 @@ function find(A::StridedArray)
nnzA = countnz(A)
I = similar(A, Int, nnzA)
count = 1
for i=1:length(A)
for i in eachindex(A)
if A[i] != 0
I[count] = i
count += 1
Expand Down Expand Up @@ -860,7 +860,7 @@ function findin(a, b::UnitRange)
ind = Array(Int, 0)
f = first(b)
l = last(b)
for i = 1:length(a)
for i in eachindex(a)
if f <= a[i] <= l
push!(ind, i)
end
Expand All @@ -871,7 +871,7 @@ end
function findin(a, b)
ind = Array(Int, 0)
bset = Set(b)
@inbounds for i = 1:length(a)
@inbounds for i in eachindex(a)
a[i] in bset && push!(ind, i)
end
ind
Expand Down Expand Up @@ -907,7 +907,7 @@ filter(f, As::AbstractArray) = As[map(f, As)::AbstractArray{Bool}]

function filter!(f, a::Vector)
insrt = 1
for curr = 1:length(a)
for curr in eachindex(a)
if f(a[curr])
a[insrt] = a[curr]
insrt += 1
Expand All @@ -919,7 +919,7 @@ end

function filter(f, a::Vector)
r = Array(eltype(a), 0)
for i = 1:length(a)
for i in eachindex(a)
if f(a[i])
push!(r, a[i])
end
Expand All @@ -934,7 +934,7 @@ function intersect(v1, vs...)
ret = Array(eltype(v1),0)
for v_elem in v1
inall = true
for i = 1:length(vs)
for i in eachindex(vs)
if !in(v_elem, vs[i])
inall=false; break
end
Expand Down
4 changes: 2 additions & 2 deletions base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ function ctransposeblock!(B::StridedMatrix,A::StridedMatrix,m::Int,n::Int,offset
return B
end
function ccopy!(B, A)
for i = 1:length(A)
for i in eachindex(A)
B[i] = ctranspose(A[i])
end
end
Expand Down Expand Up @@ -480,7 +480,7 @@ for (f, op) = ((:cummin, :min), (:cummax, :max))

B = similar(A)

for i = 1:length(A)
for i in eachindex(A)
if div(i-1, axis_stride) % axis_size == 0
B[i] = A[i]
else
Expand Down
4 changes: 2 additions & 2 deletions base/ascii.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end

function uppercase(s::ASCIIString)
d = s.data
for i = 1:length(d)
for i in eachindex(d)
if 'a' <= Char(d[i]) <= 'z'
td = copy(d)
for j = i:length(td)
Expand All @@ -78,7 +78,7 @@ function uppercase(s::ASCIIString)
end
function lowercase(s::ASCIIString)
d = s.data
for i = 1:length(d)
for i in eachindex(d)
if 'A' <= Char(d[i]) <= 'Z'
td = copy(d)
for j = i:length(td)
Expand Down
28 changes: 14 additions & 14 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ convert{T,N}(::Type{Array{T}}, B::BitArray{N}) = convert(Array{T,N},B)
function convert{T,N}(::Type{Array{T,N}}, B::BitArray{N})
A = Array(T, size(B))
Bc = B.chunks
@inbounds for i = 1:length(A)
@inbounds for i in eachindex(A)
A[i] = unsafe_bitgetindex(Bc, i)
end
return A
Expand Down Expand Up @@ -386,11 +386,11 @@ function unsafe_setindex!(B::BitArray, x, I::BitArray)
Ic = I.chunks
length(Bc) == length(Ic) || throw_boundserror(B, I)
@inbounds if y
for i = 1:length(Bc)
for i in eachindex(Bc)
Bc[i] |= Ic[i]
end
else
for i = 1:length(Bc)
for i in eachindex(Bc)
Bc[i] &= ~Ic[i]
end
end
Expand Down Expand Up @@ -817,7 +817,7 @@ function (~)(B::BitArray)
Bc = B.chunks
if !isempty(Bc)
Cc = C.chunks
for i = 1:length(Bc)
for i in eachindex(Bc)
Cc[i] = ~Bc[i]
end
Cc[end] &= _msk_end(B)
Expand All @@ -828,7 +828,7 @@ end
function flipbits!(B::BitArray)
Bc = B.chunks
@inbounds if !isempty(Bc)
for i = 1:length(Bc)
for i in eachindex(Bc)
Bc[i] = ~Bc[i]
end
Bc[end] &= _msk_end(B)
Expand Down Expand Up @@ -901,7 +901,7 @@ function div(x::Number, B::BitArray)
all(B) || throw(DivideError())
pt = promote_array_type(IDivFun(), typeof(x), Bool)
y = div(x, true)
reshape(pt[ y for i = 1:length(B) ], size(B))
reshape(pt[ y for i in eachindex(B) ], size(B))
end

function mod(A::BitArray, B::BitArray)
Expand All @@ -922,15 +922,15 @@ function mod(x::Number, B::BitArray)
all(B) || throw(DivideError())
pt = promote_array_type(ModFun(), typeof(x), Bool)
y = mod(x, true)
reshape(pt[ y for i = 1:length(B) ], size(B))
reshape(pt[ y for i in eachindex(B) ], size(B))
end

for (f,F) in ((:div, IDivFun()),
(:mod, ModFun()))
@eval begin
function ($f)(B::BitArray, x::Number)
F = Array(promote_array_type($F, typeof(x), Bool), size(B))
for i = 1:length(F)
for i in eachindex(F)
F[i] = ($f)(B[i], x)
end
return F
Expand Down Expand Up @@ -961,7 +961,7 @@ for f in (:&, :|, :$)
Ac = A.chunks
Bc = B.chunks
(isempty(Ac) || isempty(Bc)) && return F
for i = 1:length(Fc)
for i in eachindex(Fc)
Fc[i] = ($f)(Ac[i], Bc[i])
end
Fc[end] &= _msk_end(F)
Expand All @@ -983,7 +983,7 @@ end
function (.^)(x::Number, B::BitArray)
z = x ^ false
u = x ^ true
reshape([ B[i] ? u : z for i = 1:length(B) ], size(B))
reshape([ B[i] ? u : z for i in eachindex(B) ], size(B))
end
function (.^)(B::BitArray, x::Integer)
if x == 0
Expand Down Expand Up @@ -1022,7 +1022,7 @@ function (.^){T<:Number}(B::BitArray, x::T)
t = typeof(u)
end
F = Array(t, size(B))
for i = 1:length(B)
for i in eachindex(B)
if B[i]
if uerr === nothing
F[i] = u
Expand Down Expand Up @@ -1271,7 +1271,7 @@ end
function countnz(B::BitArray)
n = 0
Bc = B.chunks
@inbounds for i = 1:length(Bc)
@inbounds for i in eachindex(Bc)
n += count_ones(Bc[i])
end
return n
Expand Down Expand Up @@ -1503,7 +1503,7 @@ function any(B::BitArray)
length(B) == 0 && return false
Bc = B.chunks
@inbounds begin
for i = 1:length(Bc)
for i in eachindex(Bc)
Bc[i] == 0 || return true
end
end
Expand Down Expand Up @@ -1669,7 +1669,7 @@ function hcat(B::BitVector...)
end
end
M = BitArray(height, length(B))
for j = 1:length(B)
for j in eachindex(B)
copy_chunks!(M.chunks, (height*(j-1))+1, B[j].chunks, 1, height)
end
return M
Expand Down
4 changes: 2 additions & 2 deletions base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function lreplace!(ex::Expr, r::LReplace)
return ex
end
end
for i in 1:length(ex.args)
for i in eachindex(ex.args)
ex.args[i] = lreplace!(ex.args[i], r)
end
ex
Expand Down Expand Up @@ -255,7 +255,7 @@ exprresolve_conditional(arg) = false, false

exprresolve(arg) = arg
function exprresolve(ex::Expr)
for i = 1:length(ex.args)
for i in eachindex(ex.args)
ex.args[i] = exprresolve(ex.args[i])
end
# Handle simple arithmetic
Expand Down
Loading

0 comments on commit 5df7daa

Please sign in to comment.