Skip to content

Commit

Permalink
bugfix broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Feb 9, 2020
1 parent 1773c39 commit d6c7ad8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/array.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
"""
Probably backed by an array, but might not be. Not good for broadcasting.

These arrays should be fixed with a dependency on DiskArrays.jl
"""
abstract type AbstractDimensionalArray{T,N,D<:Tuple,A} <: AbstractArray{T,N} end

const AbDimArray = AbstractDimensionalArray
Expand Down
5 changes: 1 addition & 4 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ end


Base.BroadcastStyle(::DimensionalStyle{A}, ::DimensionalStyle{B}) where {A, B} = DimensionalStyle(A(), B())
Base.BroadcastStyle(::DimensionalStyle{A}, b::BroadcastStyle) where {A, B} = DimensionalStyle(A(), b)
Base.BroadcastStyle(::DimensionalStyle{A}, b::B) where {A, B} = DimensionalStyle(A(), b)
Base.BroadcastStyle(a::A, ::DimensionalStyle{B}) where {A, B} = DimensionalStyle(a, B())
Base.BroadcastStyle(::DimensionalStyle{A}, b::DefaultArrayStyle) where {A} = DimensionalStyle(A(), b)
Base.BroadcastStyle(a::AbstractArrayStyle{M}, ::DimensionalStyle{B}) where {B,M} = DimensionalStyle(a, B())


# We need to implement copy because if the wrapper array type does not support setindex
# then the `similar` based default method will not work
function Broadcast.copy(bc::Broadcasted{DimensionalStyle{S}}) where S
Expand All @@ -58,8 +57,6 @@ function Base.copyto!(dest::AbstractArray, bc::Broadcasted{DimensionalStyle{S}})
end
end

Base.BroadcastStyle(::Type{<:AbDimArray}) = Broadcast.ArrayStyle{AbDimArray}()

# Recursively unwraps `AbstractDimensionalArray`s and `DimensionalStyle`s.
# replacing the `AbstractDimensionalArray`s with the wrapped array,
# and `DimensionalStyle` with the wrapped `BroadcastStyle`.
Expand Down
3 changes: 3 additions & 0 deletions src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ end
# TODO deal with unordered arrays trashing the index order
@inline slicedims(d::AbDim{<:AbstractArray}, i::AbstractArray) =
(rebuild(d, d[_relate(d, i)]),), ()
@inline slicedims(d::AbDim{<:Colon}, i::Colon) = (d,), ()
@inline slicedims(d::AbDim{<:Colon}, i::AbstractArray) = (d,), ()
@inline slicedims(d::AbDim{<:Colon}, i::Number) = (), (d,)

_relate(d::AbDim, i) = _maybeflip(relationorder(d), d, i)

Expand Down
1 change: 1 addition & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using DimensionalData, Test

@testset "Binary broadcasting operations (.+)" begin
da = DimensionalArray(ones(3), X)
@test Base.BroadcastStyle(typeof(da)) isa DimensionalData.DimensionalStyle

@testset "standard case" begin
@test da .+ da == 2ones(3)
Expand Down

0 comments on commit d6c7ad8

Please sign in to comment.