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

Commit

Permalink
Merge pull request #101 from ScottPJones/spj/fixv05
Browse files Browse the repository at this point in the history
Fix issue #100, make work again with v0.5
  • Loading branch information
davidagold committed Apr 11, 2016
2 parents 1817bfc + 09a616b commit 5de3aff
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 32 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.4-
Compat
Reexport
54 changes: 28 additions & 26 deletions src/NullableArrays.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
module NullableArrays

using Reexport
@reexport using Base.Cartesian
using Compat
using Reexport
@reexport using Base.Cartesian

export NullableArray,
NullableVector,
NullableMatrix,
export NullableArray,
NullableVector,
NullableMatrix,

# Macros
# Macros

# Methods
dropnull,
anynull,
allnull,
head,
nullify!,
padnull!,
padnull,
tail
# Methods
dropnull,
anynull,
allnull,
head,
nullify!,
padnull!,
padnull,
tail

include("typedefs.jl")
include("constructors.jl")
include("primitives.jl")
include("indexing.jl")
include("map.jl")
include("nullablevector.jl")
include("operators.jl")
include("broadcast.jl")
include("reduce.jl")
include("show.jl")
include("subarray.jl")

include("typedefs.jl")
include("constructors.jl")
include("primitives.jl")
include("indexing.jl")
include("map.jl")
include("nullablevector.jl")
include("operators.jl")
include("broadcast.jl")
include("reduce.jl")
include("show.jl")
include("subarray.jl")
end
5 changes: 2 additions & 3 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,5 @@ end
# The following method allows for the construction of zero-element
# NullableArrays by calling the parametrized type on zero arguments.
# TODO: add support for dimensions arguments?
function Base.call{T, N}(::Type{NullableArray{T, N}})
NullableArray(T, ntuple(i->0, N))
end
@compat (::Type{NullableArray{T, N}}){T, N}() = NullableArray(T, ntuple(i->0, N))

6 changes: 3 additions & 3 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ end

## Lifted functors

function Base.call{S1, S2}(::Base.MinFun, x::Nullable{S1}, y::Nullable{S2})
@compat function (::Base.MinFun){S1, S2}(x::Nullable{S1}, y::Nullable{S2})
if isbits(S1) & isbits(S2)
return Nullable(Base.scalarmin(x.value, y.value), x.isnull | y.isnull)
else
error()
end
end

function Base.call{S1, S2}(::Base.MaxFun, x::Nullable{S1}, y::Nullable{S2})
@compat function (::Base.MaxFun){S1, S2}(x::Nullable{S1}, y::Nullable{S2})
if isbits(S1) & isbits(S2)
return Nullable(Base.scalarmax(x.value, y.value), x.isnull | y.isnull)
else
error()
end
end

4 changes: 4 additions & 0 deletions src/subarray.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
if VERSION >= v"0.5.0-dev+2718"
include("subarray0_5.jl")
else
const unsafe_getindex = Base.unsafe_getindex

@generated function Base.isnull{T,N,P<:NullableArray,IV,LD}(V::SubArray{T,N,P,IV,LD}, I::Int...)
Expand Down Expand Up @@ -33,6 +36,7 @@ end
Base.getindex(V.parent.values, $(idxs...))
end
end
end

@generated function anynull{T, N, U<:NullableArray}(S::SubArray{T, N, U})
return quote
Expand Down
36 changes: 36 additions & 0 deletions src/subarray0_5.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
typealias NullableSubArray{T,N,P<:NullableArray,IV,LD} SubArray{T,N,P,IV,LD}

@inline function Base.isnull(V::NullableSubArray, I::Int...)
@boundscheck checkbounds(V, I...)
@inbounds return V.parent.isnull[Base.reindex(V, V.indexes, I)...]
end

@inline function Base.values(V::NullableSubArray, I::Int...)
@boundscheck checkbounds(V, I...)
@inbounds return V.parent.values[Base.reindex(V, V.indexes, I)...]
end

typealias FastNullableSubArray{T,N,P<:NullableArray,IV} SubArray{T,N,P,IV,true}

@inline function Base.isnull(V::FastNullableSubArray, i::Int)
@boundscheck checkbounds(V, i)
@inbounds return V.parent.isnull[V.first_index + V.stride1*i-1]
end

@inline function Base.values(V::FastNullableSubArray, i::Int)
@boundscheck checkbounds(V, i)
@inbounds return V.parent.values[V.first_index + V.stride1*i-1]
end

# We can avoid a multiplication if the first parent index is a Colon or UnitRange
typealias FastNullableContiguousSubArray{T,N,P<:NullableArray,I<:Tuple{Union{Colon, UnitRange}, Vararg{Any}}} SubArray{T,N,P,I,true}

@inline function Base.isnull(V::FastNullableContiguousSubArray, i::Int)
@boundscheck checkbounds(V, i)
@inbounds return V.parent.isnull[V.first_index + i - 1]
end

@inline function Base.values(V::FastNullableContiguousSubArray, i::Int)
@boundscheck checkbounds(V, i)
@inbounds return V.parent.values[V.first_index + i - 1]
end

0 comments on commit 5de3aff

Please sign in to comment.