Skip to content

Commit

Permalink
Deprecate two-argument map! and asyncmap!.
Browse files Browse the repository at this point in the history
In anticipation of changing map! and asyncmap!'s semantics such that they are consistent with map! and asyncmap! methods accepting more than two arguments, deprecate two-argument map! and asyncmap!.
  • Loading branch information
Sacha0 authored and tkelman committed Dec 30, 2016
1 parent ab984a5 commit 7bcc730
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 38 deletions.
6 changes: 0 additions & 6 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1798,12 +1798,6 @@ promote_eltype_op(op, A, B, C, D...) = (@_inline_meta; promote_eltype_op(op, elt

## 1 argument

"""
map!(function, collection)
In-place version of [`map`](@ref).
"""
map!{F}(f::F, A::AbstractArray) = map!(f, A, A)
function map!{F}(f::F, dest::AbstractArray, A::AbstractArray)
for (i,j) in zip(eachindex(dest),eachindex(A))
dest[i] = f(A[j])
Expand Down
10 changes: 0 additions & 10 deletions base/asyncmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,6 @@ iteratorsize(itr::AsyncGenerator) = iteratorsize(itr.collector.enumerator)
size(itr::AsyncGenerator) = size(itr.collector.enumerator)
length(itr::AsyncGenerator) = length(itr.collector.enumerator)

"""
asyncmap!(f, c; ntasks=0, batch_size=nothing)
In-place version of [`asyncmap()`](@ref).
"""
function asyncmap!(f, c; ntasks=0, batch_size=nothing)
foreach(identity, AsyncCollector(f, c, c; ntasks=ntasks, batch_size=batch_size))
c
end

"""
asyncmap!(f, results, c...; ntasks=0, batch_size=nothing)
Expand Down
2 changes: 0 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1895,8 +1895,6 @@ map(::typeof(zero), A::BitArray) = fill!(similar(A), false)
map(::typeof(one), A::BitArray) = fill!(similar(A), true)
map(::typeof(identity), A::BitArray) = copy(A)

map!(f, A::BitArray) = map!(f, A, A)
map!(::typeof(identity), A::BitArray) = A
map!(::Union{typeof(~), typeof(!)}, dest::BitArray, A::BitArray) = bit_map!(~, dest, A)
map!(::typeof(zero), dest::BitArray, A::BitArray) = fill!(dest, false)
map!(::typeof(one), dest::BitArray, A::BitArray) = fill!(dest, true)
Expand Down
3 changes: 2 additions & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ end
function load_machine_file(path::AbstractString)
machines = []
for line in split(readstring(path),'\n'; keep=false)
s = map!(strip, split(line,'*'; keep=false))
s = split(line, '*'; keep = false)
map!(strip, s, s)
if length(s) > 1
cnt = isnumber(s[1]) ? parse(Int,s[1]) : Symbol(s[1])
push!(machines,(s[2], cnt))
Expand Down
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1347,4 +1347,8 @@ function quadgk(args...)
end
export quadgk

# Deprecate two-argument map! (map!(f, A)) for a cycle in anticipation of semantic change
@deprecate map!{F}(f::F, A::AbstractArray) map!(f, A, A)
@deprecate asyncmap!(f, c; ntasks=0, batch_size=nothing) asyncmap!(f, c, c; ntasks=ntasks, batch_size=batch_size)

# End deprecations scheduled for 0.6
2 changes: 1 addition & 1 deletion base/markdown/GitHub/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function parserow(stream::IO)
row = split(line, r"(?<!\\)\|")
length(row) == 1 && return
row[1] == "" && shift!(row)
map!(x -> strip(replace(x, "\\|", "|")), row)
map!(x -> strip(replace(x, "\\|", "|")), row, row)
row[end] == "" && pop!(row)
return row
end
Expand Down
17 changes: 10 additions & 7 deletions base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,15 @@ function fill!(S::SharedArray, v)
end

function rand!{T}(S::SharedArray{T})
f = S->map!(x->rand(T), S.loc_subarr_1d)
f = S->map!(x -> rand(T), S.loc_subarr_1d, S.loc_subarr_1d)
@sync for p in procs(S)
@async remotecall_wait(f, p, S)
end
return S
end

function randn!(S::SharedArray)
f = S->map!(x->randn(), S.loc_subarr_1d)
f = S->map!(x -> randn(), S.loc_subarr_1d, S.loc_subarr_1d)
@sync for p in procs(S)
@async remotecall_wait(f, p, S)
end
Expand All @@ -475,9 +475,9 @@ shmem_fill(v, I::Int...; kwargs...) = shmem_fill(v, I; kwargs...)
# rand variant with range
function shmem_rand(TR::Union{DataType, UnitRange}, dims; kwargs...)
if isa(TR, UnitRange)
SharedArray(Int, dims; init = S -> map!((x)->rand(TR), S.loc_subarr_1d), kwargs...)
SharedArray(Int, dims; init = S -> map!(x -> rand(TR), S.loc_subarr_1d, S.loc_subarr_1d), kwargs...)
else
SharedArray(TR, dims; init = S -> map!((x)->rand(TR), S.loc_subarr_1d), kwargs...)
SharedArray(TR, dims; init = S -> map!(x -> rand(TR), S.loc_subarr_1d, S.loc_subarr_1d), kwargs...)
end
end
shmem_rand(TR::Union{DataType, UnitRange}, i::Int; kwargs...) = shmem_rand(TR, (i,); kwargs...)
Expand All @@ -487,7 +487,7 @@ shmem_rand(dims; kwargs...) = shmem_rand(Float64, dims; kwargs...)
shmem_rand(I::Int...; kwargs...) = shmem_rand(I; kwargs...)

function shmem_randn(dims; kwargs...)
SharedArray(Float64, dims; init = S-> map!((x)->randn(), S.loc_subarr_1d), kwargs...)
SharedArray(Float64, dims; init = S-> map!(x -> randn(), S.loc_subarr_1d, S.loc_subarr_1d), kwargs...)
end
shmem_randn(I::Int...; kwargs...) = shmem_randn(I; kwargs...)

Expand All @@ -501,11 +501,14 @@ reduce(f, S::SharedArray) =
Any[ @spawnat p reduce(f, S.loc_subarr_1d) for p in procs(S) ])


function map!(f, S::SharedArray)
function map!(f, S::SharedArray, Q::SharedArray)
if !(S === Q) && (procs(S) != procs(Q) || localindexes(S) != localindexes(Q))
throw(ArgumentError("incompatible source and destination arguments"))
end
@sync for p in procs(S)
@spawnat p begin
for idx in localindexes(S)
S.s[idx] = f(S.s[idx])
S.s[idx] = f(Q.s[idx])
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,10 @@ function test_map(::Type{TestAbstractArray})

# In-place map
A = Float64[1:10...]
map!(x->x*x, A)
@test A == map(x->x*x, Float64[1:10...])
map!(x -> x*x, A, A)
@test A == map(x -> x*x, Float64[1:10...])
B = Float64[1:10...]
Base.asyncmap!(x->x*x, B)
Base.asyncmap!(x->x*x, B, B)
@test A == B

# Map to destination collection
Expand Down
2 changes: 1 addition & 1 deletion test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@test isequal(map((x)->"$x"[end:end], 9:11), ["9", "0", "1"])
# TODO: @test map!() much more thoroughly
let a = [1.0, 2.0]
map!(sin, a)
map!(sin, a, a)
@test isequal(a, sin.([1.0, 2.0]))
end
# map -- ranges.jl
Expand Down
2 changes: 1 addition & 1 deletion test/parallel_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ d2 = map(x->1, d)
@test reduce(+, d2) == 100

@test reduce(+, d) == ((50*id_me) + (50*id_other))
map!(x->1, d)
map!(x->1, d, d)
@test reduce(+, d) == 100

@test fill!(d, 1) == ones(10, 10)
Expand Down
6 changes: 3 additions & 3 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1330,9 +1330,9 @@ end
Aposzeros = setindex!(copy(A), 2, poszerosinds)
Anegzeros = setindex!(copy(A), -2, negzerosinds)
Abothsigns = setindex!(copy(Aposzeros), -2, negzerosinds)
map!(x -> x == 2 ? 0.0 : x, Aposzeros.nzval)
map!(x -> x == -2 ? -0.0 : x, Anegzeros.nzval)
map!(x -> x == 2 ? 0.0 : x == -2 ? -0.0 : x, Abothsigns.nzval)
map!(x -> x == 2 ? 0.0 : x, Aposzeros.nzval, Aposzeros.nzval)
map!(x -> x == -2 ? -0.0 : x, Anegzeros.nzval, Anegzeros.nzval)
map!(x -> x == 2 ? 0.0 : x == -2 ? -0.0 : x, Abothsigns.nzval, Abothsigns.nzval)
for Awithzeros in (Aposzeros, Anegzeros, Abothsigns)
# Basic functionality / dropzeros!
@test dropzeros!(copy(Awithzeros)) == A
Expand Down
6 changes: 3 additions & 3 deletions test/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1017,9 +1017,9 @@ let testdims = (10, 20, 30), nzprob = 0.4, targetnumposzeros = 5, targetnumnegze
vposzeros = setindex!(copy(v), 2, poszerosinds)
vnegzeros = setindex!(copy(v), -2, negzerosinds)
vbothsigns = setindex!(copy(vposzeros), -2, negzerosinds)
map!(x -> x == 2 ? 0.0 : x, vposzeros.nzval)
map!(x -> x == -2 ? -0.0 : x, vnegzeros.nzval)
map!(x -> x == 2 ? 0.0 : x == -2 ? -0.0 : x, vbothsigns.nzval)
map!(x -> x == 2 ? 0.0 : x, vposzeros.nzval, vposzeros.nzval)
map!(x -> x == -2 ? -0.0 : x, vnegzeros.nzval, vnegzeros.nzval)
map!(x -> x == 2 ? 0.0 : x == -2 ? -0.0 : x, vbothsigns.nzval, vbothsigns.nzval)
for vwithzeros in (vposzeros, vnegzeros, vbothsigns)
# Basic functionality / dropzeros!
@test dropzeros!(copy(vwithzeros)) == v
Expand Down

0 comments on commit 7bcc730

Please sign in to comment.