Skip to content

Draft: Feature Request: Structural Zeros in SpMat

Hello,

Feature Overview and Motivation

I'd like to request a feature that would allow users to store zeros in SpMat. This may sound odd but I believe there is a valuable use case for this regarding quadratic programming which I will explain. QP solvers like osqp use csc sparse matrices and once the solver has been initialized the structure of the sparse matrices cannot change between solves. Consider a sequential quadratic program where certain elements in the sparse matrix may be zero at one iteration and nonzero at another iteration or vice versa. This example represents the need to distinguish structural zeros from non-structural zeros when the sparse structure may not change.

Possible Implementation Details

SpMat could distinguish set matrix coefficients from non-set coefficients when removing zeros in the call to sync(). The class could cache the row/column pairs and corresponding values that are set. When the remove zeros function is called it would ignore the cached row and column pairs that were set prior. Additionally there could be a flag passed to the constructor of SpMat that could enable the use of structural zeros. Please let me know your thoughts.

Feature Demo

SpMat<double> A(2,2);
A(0,0) = 0.0; // structural zero 
A(1,1) = 1.0; // nonzero element 

A.print(); // Should show the elements 0 at (0,0) and 1 at (1,1)

// Update a nonzero element to be a structural zero 
A(1,1) = 0.0; 

A.print(); // Should show the elements 0 at (0,0) and 0 at (1,1)

Merge request reports