MutableArithmetics.jl
MutableArithmetics.jl copied to clipboard
Upstream
Some implementations in Base/LinearAlgebra/SparseArrays have the following assumption:
zero(T) isa Tone(T) isa T-(::T) isa T+(::T, ::T) isa T*(::T, ::T) isa Tx * y = y * x- Implements
== *(x::T, y::S) = *(promote(x, y)...)
However, these assumptions are violated for the following types where MP stands for MultivariatePolynomials and MOI stand for MathOptInterface.
| Type | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
Bool |
x | x | ||||||
JuMP.VariableRef |
x | x | x | x | x | x | ||
MOI.VariableRef |
x | x | x | x | x | x | ||
MOI.ScalarAffineExpression |
x | x | x | |||||
MP.AbstractVariable |
x | x | x | x | x | |||
MP.AbstractMonomial |
x | x | x | x | ||||
MP.AbstractTerm |
x | |||||||
AbstractArray |
x | |||||||
Non-commutative MP.AbstractVariable |
x | x | x | x | x | x |
The current approach is to create an AbstractMutable type and redefine methods for the methods defined in Base for these types.
The long term solution would be to fix the issue upstream. In the short term, as Julia v1.5 might be an LTS, that would allow the package to be simplified once we drop Julia v1.0 for all the fixes that are merged before Julia v1.5.
The following are the issues in LinearAlgebra.
- [ ]
Matrix(::Tridiagonal),Matrix(::SymTridiagonal),Matrix(::LowerTriangular),Matrix(::UpperTriangular),Matrix(::UnitLowerTriangular),Matrix(::UnitUpperTriangular)assumes 1: https://github.com/JuliaLang/julia/pull/36256 Current workaround: https://github.com/JuliaOpt/MutableArithmetics.jl/blob/407a8fdfb5ef1810f3785a88e490291d37b9fb03/src/dispatch.jl#L231-L241 - [x]
LinearAlgebra._iszeroassumes 7: https://github.com/JuliaLang/julia/pull/36194 Current workaround: https://github.com/JuliaOpt/MutableArithmetics.jl/blob/407a8fdfb5ef1810f3785a88e490291d37b9fb03/src/dispatch.jl#L267-L272 - [x]
convert(::Type{<:UniformScaling}, ::UniformScaling)is not defined: https://github.com/JuliaLang/julia/pull/36193 Current workaround: https://github.com/JuliaOpt/MutableArithmetics.jl/blob/407a8fdfb5ef1810f3785a88e490291d37b9fb03/src/MutableArithmetics.jl#L60-L64 - [x]
LinearAlgebra.diagm_containerassumes 1. : https://github.com/JuliaLang/julia/pull/35743 Current workaround: https://github.com/JuliaOpt/MutableArithmetics.jl/blob/407a8fdfb5ef1810f3785a88e490291d37b9fb03/src/dispatch.jl#L27-L31 - [x]
-(::LinearAlgebra.Symmetric)assumes 3. : https://github.com/JuliaLang/julia/pull/32375/ Current workaround: https://github.com/JuliaOpt/MutableArithmetics.jl/blob/407a8fdfb5ef1810f3785a88e490291d37b9fb03/src/dispatch.jl#L204-L212 - [x]
LinearAlgebra.luassumes 4. and 5. : https://github.com/JuliaLang/julia/pull/26344 - [x]
*(::AbstractArray, ::AbstractArray)assumes 4. : https://github.com/JuliaLang/julia/pull/18218/
The following are the issues in SparseArrays.
- [ ]
*(::AbstractSparseArray, ::AbstractSparseArray)assumes 8. Beginning of current workaround (many more follows): https://github.com/JuliaOpt/MutableArithmetics.jl/blob/407a8fdfb5ef1810f3785a88e490291d37b9fb03/src/dispatch.jl#L105-L116