MutableArithmetics.jl icon indicating copy to clipboard operation
MutableArithmetics.jl copied to clipboard

Upstream

Open blegat opened this issue 5 years ago • 0 comments

Some implementations in Base/LinearAlgebra/SparseArrays have the following assumption:

  1. zero(T) isa T
  2. one(T) isa T
  3. -(::T) isa T
  4. +(::T, ::T) isa T
  5. *(::T, ::T) isa T
  6. x * y = y * x
  7. Implements ==
  8. *(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._iszero assumes 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_container assumes 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.lu assumes 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

blegat avatar May 05 '20 11:05 blegat