Is this related to
julia> x = [1.0, 2.0]; y = Vector{Union{Float64,String}}([3.0, 4.0]); julia> import MutableArithmetics, LinearAlgebra julia> MutableArithmetics.operate!!(LinearAlgebra.dot, x', y) ERROR: MethodError: no method matching zero(::Type{Union{Float64, String}}) Closest candidates are: zero(::Union{Type{P}, P}) where P<:Dates.Period at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Dates/src/periods.jl:53 zero(::MutableArithmetics.AbstractMutable) at /Users/oscar/.julia/packages/MutableArithmetics/maUDe/src/dispatch.jl:784 zero(::SparseArrays.AbstractSparseArray) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/SparseArrays/src/SparseArrays.jl:55 ... Stacktrace: [1] _instantiate_zero(#unused#::Type{Union{Float64, String}}) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/interface.jl:28 [2] promote_operation_fallback(op::typeof(*), #unused#::Type{Float64}, #unused#::Type{Union{Float64, String}}) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/interface.jl:51 [3] promote_operation(::typeof(*), ::Type, ::Type) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/interface.jl:113 [4] promote_operation_fallback(#unused#::typeof(LinearAlgebra.dot), #unused#::Type{Float64}, #unused#::Type{Union{Float64, String}}) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/interface.jl:666 [5] promote_operation(::typeof(LinearAlgebra.dot), ::Type, ::Type) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/interface.jl:113 [6] promote_map_reduce(::Function, ::Type, ::Type) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/reduce.jl:32 [7] fused_map_reduce(::typeof(MutableArithmetics.add_dot), ::LinearAlgebra.Adjoint{Float64, Vector{Float64}}, ::Vector{Union{Float64, String}}) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/reduce.jl:41 [8] operate(#unused#::typeof(LinearAlgebra.dot), x::LinearAlgebra.Adjoint{Float64, Vector{Float64}}, y::Vector{Union{Float64, String}}) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/implementations/LinearAlgebra.jl:486 [9] operate_fallback!!(::MutableArithmetics.IsNotMutable, ::typeof(LinearAlgebra.dot), ::LinearAlgebra.Adjoint{Float64, Vector{Float64}}, ::Vector{Union{Float64, String}}) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/interface.jl:571 [10] operate!!(::typeof(LinearAlgebra.dot), ::LinearAlgebra.Adjoint{Float64, Vector{Float64}}, ::Vector{Union{Float64, String}}) @ MutableArithmetics ~/.julia/packages/MutableArithmetics/maUDe/src/interface.jl:563 [11] top-level scope @ REPL[9]:1 julia> LinearAlgebra.dot(x', y) 11.0
The last example happens because of https://github.com/jump-dev/JuMP.jl/blob/31fd986a5ea6b0a073f4942b1cbf68cf8c008d2b/docs/src/tutorials/linear/geographic_clustering.jl#L36-L38
MA works around this by converting every argument in * to a mutable via operate!!(add_mul, Zero(), x).
*
operate!!(add_mul, Zero(), x)
I assume the original issue is:
julia> x = [1, 2] 2-element Vector{Int64}: 1 2 julia> y = [x, x] 2-element Vector{Vector{Int64}}: [1, 2] [1, 2] julia> MA.operate(LinearAlgebra.dot, y, y) (op, args) = (MutableArithmetics.add_dot, ([[1, 2], [1, 2]], [[1, 2], [1, 2]])) ERROR: MethodError: promote_operation_fallback(::typeof(dot), ::Type{Vector{Int64}}, ::Type{Vector{Int64}}) is ambiguous. Candidates: promote_operation_fallback(op::Function, x::Type{var"#s1"} where var"#s1"<:AbstractArray, y::Type{var"#s2"} where var"#s2"<:AbstractArray) in MutableArithmetics at /Users/oscar/.julia/dev/MutableArithmetics/src/interface.jl:15 promote_operation_fallback(::typeof(dot), ::Type{A}, ::Type{B}) where {A, B} in MutableArithmetics at /Users/oscar/.julia/dev/MutableArithmetics/src/interface.jl:661 Possible fix, define promote_operation_fallback(::typeof(dot), ::Type{A}, ::Type{B}) where {A<:AbstractArray, B<:AbstractArray} Stacktrace: [1] promote_operation(::typeof(dot), ::Type, ::Type) @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/interface.jl:113 [2] promote_map_reduce(::Function, ::Type, ::Type) @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/reduce.jl:32 [3] fused_map_reduce(::typeof(MutableArithmetics.add_dot), ::Vector{Vector{Int64}}, ::Vector{Vector{Int64}}) @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/reduce.jl:42 [4] operate(#unused#::typeof(dot), x::Vector{Vector{Int64}}, y::Vector{Vector{Int64}}) @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/implementations/LinearAlgebra.jl:486 [5] top-level scope @ REPL[117]:1
but the underlying problem is that fused_map_reduce does not match the semantics of LinearAlgebra.dot in either case.
fused_map_reduce
LinearAlgebra.dot
Yes, that's the original issue
Activity
odow commentedon Nov 7, 2022
Is this related to
odow commentedon Nov 7, 2022
The last example happens because of https://github.com/jump-dev/JuMP.jl/blob/31fd986a5ea6b0a073f4942b1cbf68cf8c008d2b/docs/src/tutorials/linear/geographic_clustering.jl#L36-L38
MA works around this by converting every argument in
*to a mutable viaoperate!!(add_mul, Zero(), x).odow commentedon Nov 7, 2022
I assume the original issue is:
but the underlying problem is that
fused_map_reducedoes not match the semantics ofLinearAlgebra.dotin either case.blegat commentedon Nov 10, 2022
Yes, that's the original issue