dense_to_sparse_indices#

lumopt2.utils.sparse_helpers.dense_to_sparse_indices(dense_indices: tuple[ndarray, ...], original_shape: ndarray[int64]) ndarray[int64]#

Convert multi-dimensional dense indices to flattened sparse indices.

Takes per-axis indices of non-zero entries in a dense array and converts them into the corresponding flattened indices for a sparse representation.

Parameters:
dense_indicestuple[np.ndarray, …]

A tuple of M 1D numpy arrays, where each array contains the indices along a particular axis of the original dense matrix corresponding to the non-zero entries. Each numpy array is of length N.

original_shapenp.ndarray[int64]

The shape of the original dense matrix before sparsification. Has shape (M,). Assumes 0-based indexing compatible with Python.

Returns:
np.ndarray[int64]

The indices of the non-zero entries in the sparse matrix, in flattened form. Has shape (N,).

Raises:
ValueError

If the length of dense_indices does not match the number of dimensions in original_shape, or if the per-axis index arrays have inconsistent lengths.