Skip to content

Commit

Permalink
setup recursive broadcast overloads #10
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Nov 26, 2017
1 parent a4cd668 commit 0a598dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ Base.Broadcast.broadcast_indices(::Type{<:AMSA}, A) = indices(A)
broadcast!(f, similar(A), A, Bs...)
end

@inline function Base.Broadcast.broadcast_c(f, ::Type{S}, A::AMSA, Bs::AMSA...) where S<:AMSA
new_A = similar(A)
broadcast!(f,new_A,A,Bs...)
new_A
end

@inline function Base.Broadcast.broadcast_c!(f, ::Type{S}, ::Type, A::AbstractMultiScaleArrayLeaf, Bs::AbstractMultiScaleArrayLeaf...) where S<:AbstractMultiScaleArrayLeaf
broadcast!(f, A.values, (B.values for B in Bs)...)
A
end

@inline function Base.Broadcast.broadcast_c!(f, ::Type{S}, ::Type, A::AMSA, Bs::AMSA...) where S<:AMSA
for i in eachindex(A.nodes)
broadcast!(f, A.nodes[i], (B.nodes[i] for B in Bs)...)
end
broadcast!(f, A.values, (B.values for B in Bs)...)
A
end

+(m::AbstractMultiScaleArray, y::AbstractMultiScaleArray) = m .+ y
+(m::AbstractMultiScaleArray, y::Number) = m .+ y
+(y::Number, m::AbstractMultiScaleArray) = m .+ y
Expand Down
2 changes: 0 additions & 2 deletions test/indexing_and_creation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ end

### Test math

#broadcast_getindex(cell1, 1)

g = (x, y) -> x*y
@test g.(cell1, 2) == [2.; 4; 6]
# cell1 .= g.(cell1, 2) How to broadcast right???
Expand Down

0 comments on commit 0a598dc

Please sign in to comment.