1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! CSR (Compressed Sparse Row) layout descriptor.
//!
//! Tag `0x07`. Rank MUST be 2. Buffer count = 3 (values + col_indices + row_ptr).
//! See `docs/spec/layouts/csr.md`.
/// Descriptor for the CSR (Compressed Sparse Row) sparse layout.
///
/// CSR is defined **only for rank-2 tensors**. A conforming implementation MUST
/// reject a CSR descriptor whose tensor rank is not 2 (checked by
/// [`crate::layout::LayoutDescriptor::validate_against_shape`]).
///
/// Three buffers are required:
///
/// | Buffer | Contents |
/// |--------|----------|
/// | 0 — `values` | Non-zero values in row-major order; `nnz` elements. |
/// | 1 — `col_indices` | Column index of each non-zero; `nnz` `uint64` elements. |
/// | 2 — `row_ptr` | Row pointer array; `nrows + 1` `uint64` elements where `nrows = shape[0]`. |
///
/// The `byte_offset` field MUST be `0` for CSR tensors.
///
/// # Examples
///
/// ```
/// use hurray_core::layout::{CsrLayout, LayoutDescriptor};
///
/// let layout = LayoutDescriptor::Csr(CsrLayout::new(5));
/// assert_eq!(layout.tag(), 0x07);
/// assert_eq!(layout.buffer_count().map(|n| n.get()), Some(3));
/// ```