Skip to content

[C++] Support 1D tensors in SparseCSR/CSC matrix conversion #50906

Description

@pratyushadk

Describe the enhancement requested

Currently, calling SparseCSRMatrix::Make or SparseCSCMatrix::Make on a 1D dense tensor returns a NotImplemented error with the message "TODO for ndim <= 1". The converter in csx_converter.cc explicitly bails out for any tensor with ndim <= 1.

For a 1D vector, the CSR representation is well-defined and simple. The indptr has exactly two entries [0, nnz], the indices array holds the positions of non-zero values, and the values array holds the corresponding values. This is essentially a single-row sparse matrix. The COO format already handles 1D tensors, so the surrounding infrastructure is already in place.

The fix is to add a 1D path in SparseCSXMatrixConverter alongside the existing 2D path, along with unit tests covering basic conversion, all-zero vectors, and a round-trip back to dense. I have already worked through the implementation and plan to submit a PR for this shortly.

ndim == 0 (scalar) should continue to return Invalid since scalars have no meaningful sparse representation.

Component(s)

C++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions