std :: ml::sparse
Struct std::SparseTensor
struct SparseTensor {
&FloatTensor values;
&FloatTensor colIdx;
&FloatTensor rowPtr;
&FloatTensor rowOf;
unsigned long rows;
unsigned long cols;
unsigned long nnz;
int ownsPattern;
}Fields
[nnz, 1], trainable
[nnz] column of each nonzero
[rows + 1] start of each row in values / colIdx
[nnz] row of each nonzero (for the backward pass)
0 for a scale() view, which shares the original's pattern
Methods
Element (r, c), 0 where there is no nonzero; at1 takes r * cols + c.
Sets an existing nonzero; a position outside the pattern is left alone.
every stored value
the values must be a scalar loss's graph: forwards to values.backward()
= drop()
values and indices together; 1 on success
the values' device buffer
A dense [rows, cols] copy: a graph node (gradients reach the values).
The same pattern with every value scaled: a graph node. It shares the pattern arrays (its free() releases only its values).
The transpose (cols x rows), its values a graph node of these.
static struct SparseTensor new_csr(
unsigned long rows,
unsigned long cols,
[]const unsigned long rowPtr,
[]const unsigned long colIdx,
[]const float values,
int requiresGrad,
)source · definitionFrom CSR arrays (host): rowPtr [rows + 1], colIdx and values [nnz] (shorter slices panic).
static struct SparseTensor from_dense(
const &FloatTensor dense,
float threshold,
int requiresGrad,
)source · definitionThe entries of a dense [rows, cols] tensor whose magnitude exceeds 'threshold'.
The n x n identity.