-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,248 additions
and
70 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
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,84 @@ | ||
abstract type AbstractLazyOperator end | ||
|
||
abstract type AbstractLazyOperatorStyle <: Base.Broadcast.BroadcastStyle end | ||
struct LazyOperatorStyle <: AbstractLazyOperatorStyle end | ||
struct LazyOperatorStyleWithSpaceAvailable <: AbstractLazyOperatorStyle end | ||
|
||
Base.Broadcast.broadcastable(lazy_op::AbstractLazyOperator) = lazy_op | ||
|
||
Base.Broadcast.BroadcastStyle(::Type{<:AbstractLazyOperator}) = | ||
LazyOperatorStyle() | ||
|
||
# Broadcasting over an AbstractLazyOperator and either a Ref or a Tuple | ||
Base.Broadcast.BroadcastStyle( | ||
style::AbstractLazyOperatorStyle, | ||
::Union{Base.Broadcast.AbstractArrayStyle{0}, Base.Broadcast.Style{Tuple}}, | ||
) = style | ||
|
||
# Broadcasting over an AbstractLazyOperator and at least one Field | ||
Base.Broadcast.BroadcastStyle( | ||
::AbstractLazyOperatorStyle, | ||
::Fields.AbstractFieldStyle, | ||
) = LazyOperatorStyleWithSpaceAvailable() | ||
|
||
# Broadcasting over more than one AbstractLazyOperator | ||
Base.Broadcast.BroadcastStyle( | ||
::LazyOperatorStyle, | ||
::LazyOperatorStyleWithSpaceAvailable, | ||
) = LazyOperatorStyleWithSpaceAvailable() | ||
|
||
Base.Broadcast.materialize(::Base.Broadcast.Broadcasted{LazyOperatorStyle}) = | ||
error("Cannot materialize lazy operator broadcast because it does not \ | ||
contain any Fields with spatial information") | ||
|
||
Base.Broadcast.materialize( | ||
bc::Base.Broadcast.Broadcasted{LazyOperatorStyleWithSpaceAvailable}, | ||
) = Base.Broadcast.materialize(remove_lazy_operators(largest_space(bc), bc)) | ||
|
||
Base.Broadcast.materialize!( | ||
::AbstractLazyOperatorStyle, | ||
dest::Fields.Field, | ||
bc::Base.Broadcast.Broadcasted, | ||
) = Base.Broadcast.materialize!(dest, remove_lazy_operators(axes(dest), bc)) | ||
|
||
remove_lazy_operators(_, arg) = arg | ||
remove_lazy_operators(space, bc::Base.Broadcast.Broadcasted) = | ||
Base.Broadcast.broadcasted( | ||
bc.f, | ||
map(arg -> remove_lazy_operators(space, arg), bc.args)..., | ||
# remove_lazy_operators_args(space, bc.args...)..., | ||
) | ||
remove_lazy_operators(_, lazy_op::AbstractLazyOperator) = | ||
error("Missing method: remove_lazy_operators(space, ::$(typeof(lazy_op)))") | ||
|
||
# remove_lazy_operators_args(_) = () | ||
# remove_lazy_operators_args(space, arg, args...) = ( | ||
# remove_lazy_operators(space, arg), | ||
# remove_lazy_operators_args(space, args...)..., | ||
# ) | ||
|
||
largest_space(_) = nothing | ||
largest_space(field::Fields.Field) = axes(field) | ||
largest_space(bc::Base.Broadcast.Broadcasted) = largest_space(bc.args...) | ||
largest_space(arg, args...) = | ||
larger_space(largest_space(arg), largest_space(args...)) | ||
|
||
larger_space(space1, ::Nothing) = space1 | ||
larger_space(::Nothing, space2) = space2 | ||
larger_space(space1::S, ::S) where {S} = space1 # Neither space is larger. | ||
larger_space( | ||
space1::Spaces.ExtrudedFiniteDifferenceSpace, | ||
::Spaces.ExtrudedFiniteDifferenceSpace, | ||
) = space1 # The staggering does not matter here, so neither space is larger. | ||
larger_space( | ||
space1::Spaces.FiniteDifferenceSpace, | ||
::Spaces.FiniteDifferenceSpace, | ||
) = space1 # The staggering does not matter here, so neither space is larger. | ||
larger_space( | ||
space1::Spaces.ExtrudedFiniteDifferenceSpace, | ||
::Spaces.AbstractSpectralElementSpace, | ||
) = space1 # The types indicate that space2 is a subspace of space1. | ||
larger_space( | ||
::Spaces.AbstractSpectralElementSpace, | ||
space2::Spaces.ExtrudedFiniteDifferenceSpace, | ||
) = space2 # The types indicate that space1 is a subspace of space2. |
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
Oops, something went wrong.