diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 81f373aa75144..6cbdd4a8c56fc 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -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]) diff --git a/base/asyncmap.jl b/base/asyncmap.jl index 8c5c97b155d40..112f30663b112 100644 --- a/base/asyncmap.jl +++ b/base/asyncmap.jl @@ -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) diff --git a/base/bitarray.jl b/base/bitarray.jl index 3ec78b56003d2..d44feffd9d923 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -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) diff --git a/base/client.jl b/base/client.jl index 583f61db75426..55d92f96fcf03 100644 --- a/base/client.jl +++ b/base/client.jl @@ -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)) diff --git a/base/deprecated.jl b/base/deprecated.jl index 661c16353b0dc..7f4f271e29e37 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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 diff --git a/base/markdown/GitHub/table.jl b/base/markdown/GitHub/table.jl index 7aa34c6698b39..b310742c94068 100644 --- a/base/markdown/GitHub/table.jl +++ b/base/markdown/GitHub/table.jl @@ -11,7 +11,7 @@ function parserow(stream::IO) row = split(line, r"(? strip(replace(x, "\\|", "|")), row) + map!(x -> strip(replace(x, "\\|", "|")), row, row) row[end] == "" && pop!(row) return row end diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 1ec665d67d633..297f5838cf63f 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -451,7 +451,7 @@ 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 @@ -459,7 +459,7 @@ function rand!{T}(S::SharedArray{T}) 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 @@ -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...) @@ -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...) @@ -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 diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 4cf385e470f73..2beb33da6895b 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -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 diff --git a/test/functional.jl b/test/functional.jl index 170ebb84c4d7c..155d20eb8968b 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -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 diff --git a/test/parallel_exec.jl b/test/parallel_exec.jl index c724b236c3eac..a3dbb43ac7e14 100644 --- a/test/parallel_exec.jl +++ b/test/parallel_exec.jl @@ -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) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index 07171c22a5acf..43be4d9cd5527 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -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 diff --git a/test/sparse/sparsevector.jl b/test/sparse/sparsevector.jl index 82c378fde39e8..0860b25dbd4cf 100644 --- a/test/sparse/sparsevector.jl +++ b/test/sparse/sparsevector.jl @@ -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