-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename to NullBroadcasts + NullBroadcasted
- Loading branch information
1 parent
d35d52a
commit 0a21cc8
Showing
9 changed files
with
113 additions
and
107 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,4 +1,4 @@ | ||
AbsentTypes.jl Release Notes | ||
NullBroadcasts.jl Release Notes | ||
============================ | ||
|
||
Main | ||
|
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# AbsentTypes.jl | ||
A small package for defining absent (i.e., null) types and behaviors | ||
# NullBroadcasts.jl | ||
|
||
A small package for defining null broadcasted types and behaviors |
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,4 +1,4 @@ | ||
[deps] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244" | ||
AbsentTypes = "0d71be07-595a-4f89-9529-4065a4ab43a6" | ||
NullBroadcasts = "0d71be07-595a-4f89-9529-4065a4ab43a6" |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# AbsentTypes.jl | ||
# NullBroadcasts.jl | ||
|
This file was deleted.
Oops, something went wrong.
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,81 @@ | ||
module NullBroadcasts | ||
|
||
""" | ||
NullBroadcasted() | ||
A `Base.AbstractBroadcasted` that represents arithmetic object. | ||
An `NullBroadcasted()` can be added to, subtracted from, or multiplied by any value in a | ||
broadcast expression without incurring a runtime performance penalty. | ||
For example, the following rules hold when broadcasting instances of `NullBroadcasted`: | ||
``` | ||
1 + NullBroadcasted() == 1 | ||
NullBroadcasted() + 1 == 1 | ||
1 - NullBroadcasted() == 1 | ||
1 * NullBroadcasted() == NullBroadcasted() | ||
1 / NullBroadcasted() == NullBroadcasted() | ||
``` | ||
""" | ||
struct NullBroadcasted <: Base.AbstractBroadcasted end | ||
Base.broadcastable(x::NullBroadcasted) = x | ||
|
||
struct NullBroadcastedStyle <: Base.BroadcastStyle end | ||
Base.BroadcastStyle(::Type{<:NullBroadcasted}) = NullBroadcasted() | ||
|
||
# Specialize on AbstractArrayStyle to avoid ambiguities with AbstractBroadcasted. | ||
Base.BroadcastStyle(::NullBroadcasted, ::Base.Broadcast.AbstractArrayStyle) = | ||
NullBroadcasted() | ||
Base.BroadcastStyle(::Base.Broadcast.AbstractArrayStyle, ::NullBroadcasted) = | ||
NullBroadcasted() | ||
|
||
# Add another method to avoid ambiguity between the previous two. | ||
Base.BroadcastStyle(::NullBroadcasted, ::NullBroadcasted) = NullBroadcasted() | ||
|
||
broadcasted_sum(args) = | ||
if isempty(args) | ||
NullBroadcasted() | ||
elseif length(args) == 1 | ||
args[1] | ||
else | ||
Base.broadcasted(+, args...) | ||
end | ||
Base.broadcasted(::NullBroadcasted, ::typeof(+), args...) = | ||
broadcasted_sum(filter(arg -> !(arg isa NullBroadcasted), args)) | ||
|
||
Base.broadcasted(op::typeof(-), ::NullBroadcasted, arg) = Base.broadcasted(op, arg) | ||
Base.broadcasted(op::typeof(-), arg, ::NullBroadcasted) = | ||
Base.broadcasted(Base.identity, arg) | ||
Base.broadcasted(op::typeof(-), a::NullBroadcasted) = NullBroadcasted() | ||
Base.broadcasted(op::typeof(-), a::NullBroadcasted, ::NullBroadcasted) = | ||
Base.broadcasted(op, a) | ||
|
||
Base.broadcasted(op::typeof(+), ::NullBroadcasted, args...) = Base.broadcasted(op, args...) | ||
Base.broadcasted(op::typeof(+), arg, ::NullBroadcasted) = Base.broadcasted(op, arg) | ||
Base.broadcasted(op::typeof(+), a::NullBroadcasted, ::NullBroadcasted) = | ||
Base.broadcasted(op, a) | ||
|
||
Base.broadcasted(op::typeof(*), ::NullBroadcasted, args...) = NullBroadcasted() | ||
Base.broadcasted(op::typeof(*), arg, ::NullBroadcasted) = NullBroadcasted() | ||
Base.broadcasted(op::typeof(*), ::NullBroadcasted, ::NullBroadcasted) = NullBroadcasted() | ||
Base.broadcasted(op::typeof(/), ::NullBroadcasted, args...) = NullBroadcasted() | ||
Base.broadcasted(op::typeof(/), arg, ::NullBroadcasted) = NullBroadcasted() | ||
Base.broadcasted(op::typeof(/), ::NullBroadcasted, ::NullBroadcasted) = NullBroadcasted() | ||
|
||
function skip_materialize(dest, bc::Base.Broadcast.Broadcasted) | ||
if typeof(bc.f) <: typeof(+) || typeof(bc.f) <: typeof(-) | ||
if length(bc.args) == 2 && | ||
bc.args[1] === dest && | ||
bc.args[2] === Base.Broadcast.Broadcasted(NullBroadcasted, ()) | ||
return true | ||
else | ||
return false | ||
end | ||
else | ||
return false | ||
end | ||
end | ||
|
||
Base.Broadcast.instantiate(bc::Base.Broadcast.Broadcasted{NullBroadcastedStyle}) = x | ||
|
||
end # module NullBroadcasts |
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