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 5 months ago

albertomercurio commented 5 months 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 5 months 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 5 months 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 5 months 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 5 months ago

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

dpo commented 5 months ago

Sounds good. Would you like to submit a PR?

albertomercurio commented 5 months ago

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