Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sparse matrix multiplication #108

Open
tkoolen opened this issue Oct 22, 2019 · 1 comment
Open

Support for sparse matrix multiplication #108

tkoolen opened this issue Oct 22, 2019 · 1 comment

Comments

@tkoolen
Copy link
Owner

tkoolen commented Oct 22, 2019

I just noticed that in @expression and in @constraint sparse matrices are not accepted.
For example, A=spzeros(n,m). If I use
A_expr = @expression A or @constraint(model, A * X ==0)
It gives me this error:

ERROR: LoadError: MethodError: no method matching one(::Type{Any})
Closest candidates are:
  one(::Type{Union{Missing, T}}) where T at missing.jl:87
  one(::Missing) at missing.jl:83
  one(::BitArray{2}) at bitarray.jl:400
  ...
Stacktrace:
 [1] one(::Type{Any}) at ./missing.jl:87
 [2] *(::SparseMatrixCSC{Float32,Int64}, ::Array{Variable,1})at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/SparseArrays/src/linalg.jl:53

Originally posted by @ssadat in #107 (comment)

@blegat
Copy link

blegat commented Oct 23, 2019

This might be related: We started a project to abstract all the code we have in JuMP/src/operator.jl to rewrite LinearAlgebra and SparseArrays code for JuMP expressions:
https://github.com/JuliaOpt/MutableArithmetics.jl/blob/master/src/linear_algebra.jl
The approach would be to create an abstract type so that if Parametron.Variable is a subtype of this abstract type, the call is dispatched to MutableArithmetics instead of LinearAlgebra/SparseArrays. Then the multiplication will exploit the mutability of the expressions created and will compute the element type of the resulting array correctly (usually, what is used in SparseArrays doesn't work as it start by promoting the type of both array to a common type so it the product of an array of Int and an array of Variable gives quadratic expressions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants