JuliaSmoothOptimizers / SparseMatricesCOO.jl

Sparse matrices in coordinate format for Julia
Mozilla Public License 2.0
7 stars 4 forks source link

Why is the SparseMatrixCOO mutable? #44

Open albertomercurio opened 1 month ago

albertomercurio commented 1 month ago

Hello,

looking at the code I noticed that the SparseMatrixCOO constructor is mutable, while the SparseMatrixCSC one is not.

I think that it can be safely converted into immutable. Am I wrong?

dpo commented 1 month ago

It’s useful to keep it mutable because in optimization, a Hessian or Jacobian often retains the same sparsity pattern; only the nonzero values change from one iteration to the next. That is what happens in NLPModels.jl.

albertomercurio commented 1 month ago

But than one can still change the vals vector inplace. The struct would be immutable, but the vectors inside not. Even for the SparseMatrixCSC I can update its nonzero values.

dpo commented 1 month ago

Well, yes, I suppose you're right. Do you need the struct to be immutable for a special reason? Or just for uniformity with SparseMatrixCSC?

albertomercurio commented 1 month ago

Yes, for sure because of uniformity. But also because immutable structs would be also faster AFAIK.

dpo commented 1 month ago

Sounds good. Would you like to submit a PR?

albertomercurio commented 1 month ago

Yes, why not. When I will have some free time I will do it.