sparse_to_sparse#

lumopt2.utils.sparse_helpers.sparse_to_sparse(sparse_indices: ndarray[int64], current_dense_shape: ndarray[int64], new_dense_shape: ndarray[int64], offsets: ndarray[int64]) ndarray[int64]#

Re-index sparse indices from one dense shape to another with offsets.

Takes the indices of non-zero entries in a sparse matrix corresponding to a certain dense shape, and converts them into the indices relative to a different (larger) dense shape, accounting for positional offsets.

Parameters:
sparse_indicesnp.ndarray[int64]

The indices of the non-zero entries in the original sparse matrix, in flattened form. 1D array of length N. Assumes 0-based indexing.

current_dense_shapenp.ndarray[int64]

The shape of the original dense matrix before sparsification. 1D array of length M.

new_dense_shapenp.ndarray[int64]

The shape of the new dense matrix. 1D array of length M. Each element must be >= the corresponding element in current_dense_shape + offsets.

offsetsnp.ndarray[int64]

The starting point of the old dense matrix within the new dense matrix. 1D array of length M.

Returns:
np.ndarray[int64]

The indices of the non-zero entries in the new sparse matrix, in flattened form. 0-based indexing.

Raises:
ValueError

If the lengths of current_dense_shape, new_dense_shape, and offsets do not match, or if any element of new_dense_shape is too small to contain the offset sub-array.