Skip to content

Commit 6d48e73

Browse files
committed
Make broadcasting more general
1 parent ad48a28 commit 6d48e73

File tree

2 files changed

+23
-38
lines changed

2 files changed

+23
-38
lines changed

src/abstractblocksparsearray/broadcast.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,23 @@ function Broadcast.BroadcastStyle(
4646
)
4747
return BlockSparseArrayStyle{ndims(arraytype)}()
4848
end
49+
50+
# These catch cases that aren't caught by the standard
51+
# `BlockSparseArrayStyle` definition, and also fix
52+
# ambiguity issues.
53+
function Base.copyto!(dest::AnyAbstractBlockSparseArray, bc::Broadcasted)
54+
copyto_blocksparse!(dest, bc)
55+
return dest
56+
end
57+
function Base.copyto!(
58+
dest::AnyAbstractBlockSparseArray, bc::Broadcasted{<:Base.Broadcast.AbstractArrayStyle{0}}
59+
)
60+
copyto_blocksparse!(dest, bc)
61+
return dest
62+
end
63+
function Base.copyto!(
64+
dest::AnyAbstractBlockSparseArray{<:Any,N}, bc::Broadcasted{BlockSparseArrayStyle{N}}
65+
) where {N}
66+
copyto_blocksparse!(dest, bc)
67+
return dest
68+
end

src/blocksparsearrayinterface/broadcast.jl

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,17 @@ end
3838

3939
# Broadcasting implementation
4040
# TODO: Delete this in favor of `DerivableInterfaces` version.
41-
function Base.copyto!(
42-
dest::AbstractArray{<:Any,N}, bc::Broadcasted{BlockSparseArrayStyle{N}}
43-
) where {N}
41+
function copyto_blocksparse!(dest::AbstractArray, bc::Broadcasted)
4442
# convert to map
4543
# flatten and only keep the AbstractArray arguments
4644
m = Mapped(bc)
4745
@interface interface(dest, bc) map!(m.f, dest, m.args...)
4846
return dest
4947
end
5048

51-
# Broadcasting implementation
52-
# TODO: Delete this in favor of `DerivableInterfaces` version.
53-
function Base.copyto!(dest::AnyAbstractBlockSparseArray, bc::Broadcasted)
54-
# convert to map
55-
# flatten and only keep the AbstractArray arguments
56-
m = Mapped(bc)
57-
# TODO: Include `bc` when determining interface, currently
58-
# `interface(::Type{<:Base.Broadcast.DefaultArrayStyle})`
59-
# isn't defined.
60-
@interface interface(dest) map!(m.f, dest, m.args...)
61-
return dest
62-
end
63-
64-
# Broadcasting implementation
65-
# TODO: Delete this in favor of `DerivableInterfaces` version.
6649
function Base.copyto!(
67-
dest::AnyAbstractBlockSparseArray, bc::Broadcasted{<:Base.Broadcast.AbstractArrayStyle{0}}
68-
)
69-
# convert to map
70-
# flatten and only keep the AbstractArray arguments
71-
m = Mapped(bc)
72-
# TODO: Include `bc` when determining interface, currently
73-
# `interface(::Type{<:Base.Broadcast.DefaultArrayStyle})`
74-
# isn't defined.
75-
@interface interface(dest) map!(m.f, dest, m.args...)
76-
return dest
77-
end
78-
79-
# Broadcasting implementation
80-
# TODO: Delete this in favor of `DerivableInterfaces` version.
81-
function Base.copyto!(
82-
dest::AnyAbstractBlockSparseArray{<:Any,N}, bc::Broadcasted{BlockSparseArrayStyle{N}}
50+
dest::AbstractArray{<:Any,N}, bc::Broadcasted{BlockSparseArrayStyle{N}}
8351
) where {N}
84-
# convert to map
85-
# flatten and only keep the AbstractArray arguments
86-
m = Mapped(bc)
87-
@interface interface(dest, bc) map!(m.f, dest, m.args...)
52+
copyto_blocksparse!(dest, bc)
8853
return dest
8954
end

0 commit comments

Comments
 (0)