Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Fix map! and broadcast! ambiguities on 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed May 13, 2016
1 parent 91c6c93 commit 3bcd9cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/broadcast.jl
Expand Up @@ -191,7 +191,17 @@ datype_int(A_1::DataArray, As...) = (@compat(UInt64(1)) | (datype_int(As...) <<
datype_int(A_1, As...) = (datype_int(As...) << 2)
datype_int() = @compat UInt64(0)

for bsig in (DataArray, PooledDataArray), asig in (Union{Array,BitArray,Number},DataArray, PooledDataArray)
# The following four methods are to avoid ambiguity warnings on 0.4
Base.map!(f::Base.Callable, B::DataArray) =
invoke(map!, Tuple{Base.Callable, AbstractArray}, f, B)
Base.map!(f::Base.Callable, B::PooledDataArray) =
invoke(map!, Tuple{Base.Callable, AbstractArray}, f, B)
Base.broadcast!(f::Base.Function, B::DataArray) =
invoke(map!, Tuple{Base.Callable, AbstractArray}, f, B)
Base.broadcast!(f::Base.Function, B::PooledDataArray) =
invoke(map!, Tuple{Base.Callable, AbstractArray}, f, B)

for bsig in (DataArray, PooledDataArray), asig in (Union{Array,BitArray,Number},DataArray, PooledDataArray,)
@eval let cache = Dict{Function,Dict{UInt64,Dict{Int,Function}}}()
function Base.map!(f::Base.Callable, B::$bsig, As::$asig...)
nd = ndims(B)
Expand Down
2 changes: 2 additions & 0 deletions test/broadcast.jl
Expand Up @@ -20,6 +20,7 @@ rb = 1:5
@test broadcast!(+, DataArray(Int, 2, 2), [1, 0], [1 4]) == [2 5; 1 4]
@test broadcast!(+, DataArray(Int, 2), [1, 0], [1, 4]) == [2, 4]
@test broadcast!(+, DataArray(Int, 2), [1, 0], 2) == [3, 2]
@test broadcast!(abs, @data([-1, -2])) == @data([1, 2])
for arr in (identity, as_dataarray, as_pda, as_dataarray_bigfloat, as_pda_bigfloat)
@test broadcast(+, arr(eye(2)), arr([1, 4])) == [2 1; 4 5]
@test broadcast(+, arr(eye(2)), arr([1 4])) == [2 4; 1 5]
Expand Down Expand Up @@ -127,6 +128,7 @@ rt = Base.return_types(broadcast!, (Function, DataArray{Float64, 3}, Array{Float
# Test map!
@test_throws DimensionMismatch map!(+, DataArray(Float64, 2, 2), @data([1, 2]), @data([1 2]))
@test map!(+, DataArray(Float64, 2), @data([1, 2]), @data([1, 2])) == @data([2, 4])
@test map!(abs, @data([-1, -2])) == @data([1, 2])
@test isequal(map!(+, DataArray(Float64, 3), @data([1, NA, 3]), @data([NA, 2, 3])), @data([NA, NA, 6]))
@test map!(isequal, DataArray(Float64, 3), @data([1, NA, NA]), @data([1, NA, 3])) == @data([true, true, false])
end

0 comments on commit 3bcd9cc

Please sign in to comment.