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_indices
tuple[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_shape
np.ndarray[int64] The shape of the original dense matrix before sparsification. Has shape (M,). Assumes 0-based indexing compatible with Python.
- dense_indices
- Returns:
np.ndarray[int64]The indices of the non-zero entries in the sparse matrix, in flattened form. Has shape (N,).
- Raises:
ValueErrorIf the length of
dense_indicesdoes not match the number of dimensions inoriginal_shape, or if the per-axis index arrays have inconsistent lengths.