From 2cc2894b8887511286100b58d8cb38a2e0b410fa Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Sun, 15 Jan 2017 22:03:45 +0100 Subject: [PATCH] 0.6 fixes (#171) * Do not define element-wise operators in Julia 0.6 These go though broadcast() now. * Make constructor more generic This allows accepting BitArrays, which are more frequently returned by broadcast() now. * Fix deprecations --- src/broadcast.jl | 22 ++++++++++++---------- src/constructors.jl | 4 ++-- src/typedefs.jl | 3 +-- test/reduce.jl | 19 ++++--------------- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/broadcast.jl b/src/broadcast.jl index 5345424..7684f82 100644 --- a/src/broadcast.jl +++ b/src/broadcast.jl @@ -204,15 +204,17 @@ implementation of `broadcast` in `base/broadcast.jl`. end # broadcasted ops -for (op, scalar_op) in ( - (:(@compat Base.:(.==)), :(==)), - (:(@compat Base.:.!=), :!=), - (:(@compat Base.:.<), :<), - (:(@compat Base.:.>), :>), - (:(@compat Base.:.<=), :<=), - (:(@compat Base.:.>=), :>=) -) - @eval begin - ($op)(X::NullableArray, Y::NullableArray) = broadcast($scalar_op, X, Y) +if VERSION < v"0.6.0-dev.1632" + for (op, scalar_op) in ( + (:(@compat Base.:(.==)), :(==)), + (:(@compat Base.:.!=), :!=), + (:(@compat Base.:.<), :<), + (:(@compat Base.:.>), :>), + (:(@compat Base.:.<=), :<=), + (:(@compat Base.:.>=), :>=) + ) + @eval begin + ($op)(X::NullableArray, Y::NullableArray) = broadcast($scalar_op, X, Y) + end end end diff --git a/src/constructors.jl b/src/constructors.jl index 4004980..a9a1d9b 100644 --- a/src/constructors.jl +++ b/src/constructors.jl @@ -3,9 +3,9 @@ # The following provides an outer constructor whose argument signature matches # that of the inner constructor provided in typedefs.jl: constructs a NullableArray -# from an Array of values and an Array{Bool} mask. +# from an AbstractArray of values and an AbstractArray{Bool} mask. function NullableArray{T, N}(A::AbstractArray{T, N}, - m::Array{Bool, N}) # -> NullableArray{T, N} + m::AbstractArray{Bool, N}) # -> NullableArray{T, N} return NullableArray{T, N}(A, m) end diff --git a/src/typedefs.jl b/src/typedefs.jl index 509e54a..09c0057 100644 --- a/src/typedefs.jl +++ b/src/typedefs.jl @@ -12,7 +12,6 @@ # an exception for any other type. # # TODO: Ensure that size(values) == size(isnull) using inner constructor. -# TODO: Implement outer constructor required once we add an inner constructor. """ `NullableArray{T, N}` is an efficient alternative to `Array{Nullable{T}, N}`. It allows users to easily define operations on arrays with null values by @@ -25,7 +24,7 @@ immutable NullableArray{T, N} <: AbstractArray{Nullable{T}, N} # (think mmapped file, for example) that `values` is actually derived from parent::Vector{UInt8} - function NullableArray(d::AbstractArray{T, N}, m::Array{Bool, N}, parent::Vector{UInt8}=Vector{UInt8}()) + function NullableArray(d::AbstractArray{T, N}, m::AbstractArray{Bool, N}, parent::Vector{UInt8}=Vector{UInt8}()) if size(d) != size(m) msg = "values and missingness arrays must be the same size" throw(ArgumentError(msg)) diff --git a/test/reduce.jl b/test/reduce.jl index cc13eae..493799a 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -24,13 +24,13 @@ module TestReduce @test isequal(mapreduce(f, +, X), Nullable(mapreduce(f, +, X.values))) @test isequal(mapreduce(f, +, Y), Nullable{Float64}()) v = mapreduce(f, +, Y, skipnull=true) - @test_approx_eq v.value mapreduce(f, +, B) + @test v.value ≈ mapreduce(f, +, B) @test !isnull(v) @test isequal(reduce(+, X), Nullable(reduce(+, X.values))) @test isequal(reduce(+, Y), Nullable{Float64}()) v = reduce(+, Y, skipnull=true) - @test_approx_eq v.value reduce(+, B) + @test v.value ≈ reduce(+, B) @test !isnull(v) for method in ( @@ -43,22 +43,11 @@ module TestReduce @test isequal(method(f, X), Nullable(method(f, A))) @test isequal(method(Y), Nullable{Float64}()) v = method(Y, skipnull=true) - @test_approx_eq v.value method(B) + @test v.value ≈ method(B) @test !isnull(v) @test isequal(method(f, Y), Nullable{Float64}()) v = method(f, Y, skipnull=true) - @test_approx_eq v.value method(f, B) - @test !isnull(v) - end - - for method in ( - sumabs, - sumabs2, - ) - @test isequal(method(X), Nullable(method(A))) - @test isequal(method(Y), Nullable{Float64}()) - v = method(Y, skipnull=true) - @test_approx_eq v.value method(B) + @test v.value ≈ method(f, B) @test !isnull(v) end