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

Commit

Permalink
0.6 fixes (#171)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nalimilan authored and ararslan committed Jan 15, 2017
1 parent 42bb2c6 commit 2cc2894
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
22 changes: 12 additions & 10 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/typedefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
19 changes: 4 additions & 15 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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

Expand Down

0 comments on commit 2cc2894

Please sign in to comment.