| 299 | namespace internal { |
| 300 | |
| 301 | Result<int64_t> ComputeSparseCSXIndptrLength(SparseMatrixCompressedAxis compressed_axis, |
| 302 | const std::vector<int64_t>& shape) { |
| 303 | if (shape.size() != 2) { |
| 304 | return Status::Invalid("Invalid shape length for a sparse matrix"); |
| 305 | } |
| 306 | const int64_t compressed_axis_size = |
| 307 | compressed_axis == SparseMatrixCompressedAxis::ROW ? shape[0] : shape[1]; |
| 308 | const auto indptr_length = |
| 309 | AddWithOverflow<int64_t>({compressed_axis_size, static_cast<int64_t>(1)}); |
| 310 | if (!indptr_length.has_value()) { |
| 311 | return Status::Invalid("shape is inconsistent to the size of indptr buffer"); |
| 312 | } |
| 313 | return indptr_length.value(); |
| 314 | } |
| 315 | |
| 316 | Status ValidateSparseCSXIndex(const std::shared_ptr<DataType>& indptr_type, |
| 317 | const std::shared_ptr<DataType>& indices_type, |