diff --git a/src/array.jl b/src/array.jl index 870a0a43c..cd059c6f9 100644 --- a/src/array.jl +++ b/src/array.jl @@ -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 diff --git a/src/broadcast.jl b/src/broadcast.jl index b876e3676..3db45f5d7 100644 --- a/src/broadcast.jl +++ b/src/broadcast.jl @@ -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 @@ -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`. diff --git a/src/primitives.jl b/src/primitives.jl index 76d26b74f..e68ca2d4f 100644 --- a/src/primitives.jl +++ b/src/primitives.jl @@ -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) diff --git a/test/broadcast.jl b/test/broadcast.jl index 46bda8f53..67610526c 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -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)