Build a dense global indptr of size numSourceRows+1 from sparse (srcRows, counts) runs. indptr[src+1] is set to counts[i] for the touched src = srcRows[i], then prefix-summed so indptr[src] gives the offset of src's edges in the (source-sorted) indices vector. Source rows absent from srcRows keep their slot at 0, i.e. no edges. Returns an empty vector on validation failure (bad src/count, or the d
| 81 | // disjointness invariant is violated — a source row appearing more than |
| 82 | // once would silently corrupt the merged CSR). |
| 83 | static std::vector<int64_t> buildDenseIndptr(int64_t numSourceRows, |
| 84 | const std::vector<int64_t>& srcRows, const std::vector<int64_t>& counts) { |
| 85 | std::vector<int64_t> indptr(static_cast<size_t>(numSourceRows) + 1, 0); |
| 86 | for (auto i = 0u; i < srcRows.size(); ++i) { |
| 87 | const auto src = srcRows[i]; |
| 88 | const auto count = counts[i]; |
| 89 | if (src < 0 || src >= numSourceRows || count < 0) { |
| 90 | return {}; |
| 91 | } |
| 92 | if (indptr[static_cast<size_t>(src) + 1] != 0) { |
| 93 | return {}; |
| 94 | } |
| 95 | indptr[static_cast<size_t>(src) + 1] = count; |
| 96 | } |
| 97 | for (size_t i = 0; i + 1 < indptr.size(); ++i) { |
| 98 | indptr[i + 1] += indptr[i]; |
| 99 | } |
| 100 | return indptr; |
| 101 | } |
| 102 | |
| 103 | // K-way merge of per-batch sparse CSR metadata chunks (in batch_index |
| 104 | // order) into a single flat CSRMetadata with a dense global indptr. |
no test coverage detected