Skip to content

Commit a43835a

Browse files
fix: fix some method ambiguities for array methods
1 parent 07f53bc commit a43835a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/array-lib.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ end
8181
function *(a::PolyadicT, b::Arr, bs::PolyadicT...)
8282
return *(a, unwrap(b), bs...)
8383
end
84-
function *(a::LinearAlgebra.Adjoint{T, <: AbstractVector}, b::Arr, bs::PolyadicT...) where {T}
84+
function *(a::LinearAlgebra.Adjoint{T, <: AbstractVector}, b::Arr, bs::PolyadicT...) where {T <: Number}
8585
return *(a, unwrap(b), bs...)
8686
end
87-
function *(a::LinearAlgebra.Adjoint{T, <: AbstractVector}, b::Arr, c::AbstractVector, bs::PolyadicT...) where {T}
87+
function *(a::LinearAlgebra.Adjoint{T, <: AbstractVector}, b::Arr, c::AbstractVector, bs::PolyadicT...) where {T <: Number}
8888
return *(a, unwrap(b), unwrap(c), bs...)
8989
end
9090
function *(a::Number, b::Arr, bs::PolyadicT...)
@@ -122,6 +122,20 @@ function +(x1::Arr, x2::Arr, args::AbstractArray...)
122122
return +(unwrap(x1), unwrap(x2), args...)
123123
end
124124

125+
for T1 in [Arr, AbstractArray], T2 in [Arr, AbstractArray]
126+
T1 == T2 == AbstractArray && continue
127+
@eval Base.:(\)(x1::$T1{Num, 1}, x2::$T2{Num, 1}) = Num(unwrap(x1) \ unwrap(x2))
128+
@eval Base.:(\)(x1::$T1{Num, 1}, x2::$T2{Num, 2}) = Arr{Num, 2}(unwrap(x1) \ unwrap(x2))
129+
@eval Base.:(\)(x1::$T1{Num, 2}, x2::$T2{Num, 1}) = Arr{Num, 1}(unwrap(x1) \ unwrap(x2))
130+
@eval Base.:(\)(x1::$T1{Num, 2}, x2::$T2{Num, 2}) = Arr{Num, 2}(unwrap(x1) \ unwrap(x2))
131+
132+
@eval Base.:(/)(x1::$T1{Num, 1}, x2::$T2{Num, 1}) = Arr{Num, 2}(unwrap(x1) / unwrap(x2))
133+
@eval Base.:(/)(x1::$T1{Num, 1}, x2::$T2{Num, 2}) = Arr{Num, 2}(unwrap(x1) / unwrap(x2))
134+
@eval Base.:(/)(x1::$T1{Num, 2}, x2::$T2{Num, 2}) = Arr{Num, 2}(unwrap(x1) / unwrap(x2))
135+
end
136+
137+
Base.:(/)(x1::Num, x2::Arr{Num, 1}) = Arr{Num, 2}(unwrap(x1) / unwrap(x2))
138+
125139
#################### MAP-REDUCE ################
126140

127141
SymbolicUtils.@map_methods Arr unwrap wrap

src/num.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ for (T1, T2) in Iterators.product([Num, Integer], [Num, Integer])
6565
end
6666
end
6767

68-
for f in [/, \, ^]
68+
for f in [\, ^]
6969
@eval function (::$(typeof(f)))(x1::AbstractArray{<:Real}, x2::Num)
7070
$f(x1, unwrap(x2))
7171
end
@@ -75,6 +75,14 @@ for f in [/, \, ^]
7575
end
7676
end
7777

78+
function Base.:(/)(x1::AbstractArray{<:Real}, x2::Num)
79+
/(unwrap(x1), unwrap(x2))
80+
end
81+
82+
function Base.:(/)(x1::Num, x2::AbstractVector{<:Real})
83+
/(unwrap(x1), unwrap(x2))
84+
end
85+
7886
Base.conj(x::Num) = x
7987
Base.transpose(x::Num) = x
8088

0 commit comments

Comments
 (0)