Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] More generalindexing [3] #15679

Merged
merged 3 commits into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/markdown/GitHub/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ padding(width, twidth, a) =

function padcells!(rows, align; len = length, min = 0)
widths = colwidths(rows, len = len, min = min)
for i = 1:length(rows), j = 1:length(rows[1])
for i = 1:length(rows), j = 1:length(rows[1]) # fixme (iter): can we make indexing more general here?
cell = rows[i][j]
lpad, rpad = padding(len(cell), widths[j], align[j])
rows[i][j] = " "^lpad * cell * " "^rpad
Expand All @@ -105,7 +105,7 @@ _dash(width, align) =
function plain(io::IO, md::Table)
cells = mapmap(plaininline, md.rows)
padcells!(cells, md.align, len = length, min = 3)
for i = 1:length(cells)
for i = 1:length(cells) # fixme (iter): can we make indexing more general here?
print(io, "| ")
print_joined(io, cells[i], " | ")
println(io, " |")
Expand Down
2 changes: 1 addition & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ clamp{X,L,H}(x::X, lo::L, hi::H) =

clamp{T}(x::AbstractArray{T,1}, lo, hi) = [clamp(xx, lo, hi) for xx in x]
clamp{T}(x::AbstractArray{T,2}, lo, hi) =
[clamp(x[i,j], lo, hi) for i in 1:size(x,1), j in 1:size(x,2)]
[clamp(x[i,j], lo, hi) for i in 1:size(x,1), j in 1:size(x,2)] # fixme (iter): change to `eachindex` when #15459 is ready
clamp{T}(x::AbstractArray{T}, lo, hi) =
reshape([clamp(xx, lo, hi) for xx in x], size(x))

Expand Down
2 changes: 1 addition & 1 deletion base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ pmap(f) = f()
# as it finishes.
# example unbalanced workload:
# rsym(n) = (a=rand(n,n);a*a')
# L = {rsym(200),rsym(1000),rsym(200),rsym(1000),rsym(200),rsym(1000),rsym(200),rsym(1000)};
# L = Any[rsym(200),rsym(1000),rsym(200),rsym(1000),rsym(200),rsym(1000),rsym(200),rsym(1000)];
# pmap(eig, L);
function pmap(f, lsts...; err_retry=true, err_stop=false, pids = workers())
len = length(lsts)
Expand Down
4 changes: 2 additions & 2 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ If `dim` is specified, returns unique regions of the array `itr` along `dim`.
# Collect index of first row for each hash
uniquerow = Array(Int, size(A, dim))
firstrow = Dict{Prehashed,Int}()
for k = 1:size(A, dim)
for k = 1:size(A, dim) # fixme (iter): use `eachindex(A, dim)` after #15459 is implemented
uniquerow[k] = get!(firstrow, Prehashed(hashes[k]), k)
end
uniquerows = collect(values(firstrow))
Expand All @@ -829,7 +829,7 @@ If `dim` is specified, returns unique regions of the array `itr` along `dim`.
while any(collided)
# Collect index of first row for each collided hash
empty!(firstrow)
for j = 1:size(A, dim)
for j = 1:size(A, dim) # fixme (iter): use `eachindex(A, dim)` after #15459 is implemented
collided[j] || continue
uniquerow[j] = get!(firstrow, Prehashed(hashes[j]), j)
end
Expand Down
8 changes: 4 additions & 4 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ end
macro vectorize_1arg(S,f)
S = esc(S); f = esc(f); T = esc(:T)
quote
($f){$T<:$S}(x::AbstractArray{$T,1}) = [ ($f)(x[i]) for i=1:length(x) ]
($f){$T<:$S}(x::AbstractArray{$T,1}) = [ ($f)(elem) for elem in x ]
($f){$T<:$S}(x::AbstractArray{$T,2}) =
[ ($f)(x[i,j]) for i=1:size(x,1), j=1:size(x,2) ]
($f){$T<:$S}(x::AbstractArray{$T}) =
Expand Down Expand Up @@ -504,17 +504,17 @@ end

function ifelse(c::AbstractArray{Bool}, x::AbstractArray, y::AbstractArray)
shp = promote_shape(size(c), promote_shape(size(x), size(y)))
reshape([ifelse(c[i], x[i], y[i]) for i = 1 : length(c)], shp)
reshape([ifelse(c_elem, x_elem, y_elem) for (c_elem, x_elem, y_elem) in zip(c, x, y)], shp)
end

function ifelse(c::AbstractArray{Bool}, x::AbstractArray, y)
shp = promote_shape(size(c), size(c))
reshape([ifelse(c[i], x[i], y) for i = 1 : length(c)], shp)
reshape([ifelse(c_elem, x_elem, y) for (c_elem, x_elem) in zip(c, x)], shp)
end

function ifelse(c::AbstractArray{Bool}, x, y::AbstractArray)
shp = promote_shape(size(c), size(y))
reshape([ifelse(c[i], x, y[i]) for i = 1 : length(c)], shp)
reshape([ifelse(c_elem, x, y_elem) for (c_elem, y_elem) in zip(c, y)], shp)
end

# Pair
Expand Down
6 changes: 3 additions & 3 deletions base/quadgk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ end
# all the integration-segment endpoints
function quadgk(f, a, b, c...; kws...)
T = promote_type(typeof(float(a)), typeof(b))
for i in 1:length(c)
T = promote_type(T, typeof(c[i]))
for x in c
T = promote_type(T, typeof(x))
end
cT = T[ c[i] for i in 1:length(c) ]
cT = map(T, c)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it should be fine; you know c is a tuple, and indeed the tuple output seems like the better choice.

quadgk(f, convert(T, a), convert(T, b), cT...; kws...)
end

Expand Down
4 changes: 2 additions & 2 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ rand{T<:Union{Signed,Unsigned,BigInt,Bool}}(rng::AbstractRNG, r::UnitRange{T}) =
rand(rng::AbstractRNG, r::AbstractArray) = @inbounds return r[rand(rng, 1:length(r))]

function rand!(rng::AbstractRNG, A::AbstractArray, g::RangeGenerator)
for i = 1 : length(A)
for i in eachindex(A)
@inbounds A[i] = rand(rng, g)
end
return A
Expand All @@ -580,7 +580,7 @@ rand!{T<:Union{Signed,Unsigned,BigInt,Bool,Char}}(rng::AbstractRNG, A::AbstractA

function rand!(rng::AbstractRNG, A::AbstractArray, r::AbstractArray)
g = RangeGenerator(1:(length(r)))
for i = 1 : length(A)
for i in eachindex(A)
@inbounds A[i] = r[rand(rng, g)]
end
return A
Expand Down
8 changes: 4 additions & 4 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function _mapreducedim!{T,N}(f, op, R::AbstractArray, A::AbstractArray{T,N})
@inbounds for IA in CartesianRange(sizeA1)
IR = min(sizeR1, IA)
r = R[1,IR]
@simd for i = 1:size(A, 1)
@simd for i = 1:size(A, 1) # fixme (iter): update when #15459 is implemented (and if it does't affect @simd)
r = op(r, f(A[i, IA]))
end
R[1,IR] = r
Expand All @@ -214,7 +214,7 @@ function _mapreducedim!{T,N}(f, op, R::AbstractArray, A::AbstractArray{T,N})
sizeA1 = Base.size_skip1(size(A), A)
@inbounds for IA in CartesianRange(sizeA1)
IR = min(IA, sizeR1)
@simd for i = 1:size(A, 1)
@simd for i = 1:size(A, 1) # fixme (iter): update when #15459 is implemented (and if it does't affect @simd)
R[i,IR] = op(R[i,IR], f(A[i,IA]))
end
end
Expand Down Expand Up @@ -296,7 +296,7 @@ function findminmax!{T,N}(f, Rval, Rind, A::AbstractArray{T,N})
IR = min(sizeR1, IA)
tmpRv = Rval[1,IR]
tmpRi = Rind[1,IR]
for i = 1:size(A,1)
for i = 1:size(A,1) # fixme (iter): update when #15459 is implemented (and if it does't affect @simd)
k += 1
tmpAv = A[i,IA]
if f(tmpAv, tmpRv)
Expand All @@ -310,7 +310,7 @@ function findminmax!{T,N}(f, Rval, Rind, A::AbstractArray{T,N})
else
@inbounds for IA in CartesianRange(sizeA1)
IR = min(sizeR1, IA)
for i = 1:size(A, 1)
for i = 1:size(A, 1) # fixme (iter): update when #15459 is implemented (and if it does't affect @simd)
k += 1
tmpAv = A[i,IA]
if f(tmpAv, Rval[i,IR])
Expand Down