This repository has been archived by the owner on May 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite broadcast() and map() based on lift() (#166)
Remove the custom implementation of broadcast(), and just call the base method on the lifted method. For now, standard lifting semantics are always used, even for logical operators and isnull/get.
- Loading branch information
Showing
12 changed files
with
255 additions
and
645 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
language: julia | ||
julia: | ||
- 0.4 | ||
- 0.5 | ||
- nightly | ||
script: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
julia 0.4 | ||
Compat 0.9.4 | ||
julia 0.5 | ||
Compat 0.13.0 | ||
Reexport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
eltype_nullable(x::Nullable) = eltype(x) | ||
eltype_nullable(x) = typeof(x) | ||
eltype_nullable{T<:Nullable}(::Type{T}) = eltype(T) | ||
eltype_nullable{T}(::Type{T}) = T | ||
|
||
eltypes(x) = Tuple{eltype_nullable(x)} | ||
eltypes(x, xs...) = Tuple{eltype_nullable(x), eltypes(xs...).parameters...} | ||
|
||
""" | ||
lift(f, xs...) | ||
Lift function `f`, passing it arguments `xs...`, using standard lifting semantics: | ||
for a function call `f(xs...)`, return null if any `x` in `xs` is null; otherwise, | ||
return `f` applied to values of `xs`. | ||
""" | ||
@inline @generated function lift{F, N, T}(f::F, xs::NTuple{N, T}) | ||
args = (:(unsafe_get(xs[$i])) for i in 1:N) | ||
checknull = (:(!isnull(xs[$i])) for i in 1:N) | ||
if null_safe_op(f.instance, map(eltype_nullable, xs.parameters)...) | ||
return quote | ||
val = f($(args...)) | ||
nonull = (&)($(checknull...)) | ||
@compat Nullable(val, nonull) | ||
end | ||
else | ||
return quote | ||
U = Core.Inference.return_type(f, eltypes(xs...)) | ||
if (&)($(checknull...)) | ||
return Nullable(f($(args...))) | ||
else | ||
return isleaftype(U) ? Nullable{U}() : Nullable() | ||
end | ||
end | ||
end | ||
end | ||
|
||
lift(f) = Nullable(f()) |
Oops, something went wrong.