Skip to content

Commit 596c163

Browse files
committed
Fix #128 broadcast ambiguities.
1 parent cf650e2 commit 596c163

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AxisKeys"
22
uuid = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
33
license = "MIT"
4-
version = "0.2.8"
4+
version = "0.2.9"
55

66
[deps]
77
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/broadcast.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,25 @@ Base.BroadcastStyle(::Type{<:KeyedArray{T,N,AT}}) where {T,N,AT} =
2121
Base.BroadcastStyle(::KeyedStyle{A}, ::KeyedStyle{B}) where {A, B} = KeyedStyle(A(), B())
2222
Base.BroadcastStyle(::KeyedStyle{A}, b::B) where {A, B} = KeyedStyle(A(), b)
2323
Base.BroadcastStyle(a::A, ::KeyedStyle{B}) where {A, B} = KeyedStyle(a, B())
24-
Base.BroadcastStyle(::KeyedStyle{A}, b::DefaultArrayStyle) where {A} = KeyedStyle(A(), b)
25-
Base.BroadcastStyle(a::AbstractArrayStyle{M}, ::KeyedStyle{B}) where {B,M} = KeyedStyle(a, B())
2624

2725
using NamedDims: NamedDimsStyle
2826
# this resolves in favour of KeyedArray(NamedDimsArray())
2927
Base.BroadcastStyle(a::NamedDimsStyle, ::KeyedStyle{B}) where {B} = KeyedStyle(a, B())
3028
Base.BroadcastStyle(::KeyedStyle{A}, b::NamedDimsStyle) where {A} = KeyedStyle(A(), b)
3129

30+
# Resolve ambiguities
31+
# for all these cases, we define that we win to be the outer style regardless of order
32+
for B in (
33+
:BroadcastStyle, :DefaultArrayStyle, :AbstractArrayStyle, :(Broadcast.Style{Tuple}),
34+
)
35+
@eval function Base.BroadcastStyle(::KeyedStyle{A}, b::$B) where A
36+
return KeyedStyle(A(), b)
37+
end
38+
@eval function Base.BroadcastStyle(b::$B, ::KeyedStyle{A}) where A
39+
return KeyedStyle(b, A())
40+
end
41+
end
42+
3243
function unwrap_broadcasted(bc::Broadcasted{KeyedStyle{S}}) where {S}
3344
inner_args = map(unwrap_broadcasted, bc.args)
3445
Broadcasted{S}(bc.f, inner_args)

0 commit comments

Comments
 (0)