std1.0.0-beta-7 SafeC docs

std :: ml::sparse

Struct std::SparseTensor

#include <std/ml/sparse.h> source

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)

§unsigned long rowssource
§unsigned long colssource
§unsigned long nnzsource
§int ownsPatternsource

0 for a scale() view, which shares the original's pattern

Methods

§float at1(unsigned long i) constsource · definition

Element (r, c), 0 where there is no nonzero; at1 takes r * cols + c.

§float at2(unsigned long r, unsigned long c) constsource · definition
§void set1(unsigned long i, float v)source · definition

Sets an existing nonzero; a position outside the pattern is left alone.

§void set2(unsigned long r, unsigned long c, float v)source · definition
§void fill(float v)source · definition

every stored value

§void backward()source · definition

the values must be a scalar loss's graph: forwards to values.backward()

§void zero_grad()source · definition
§void drop()source · definition
§void free() consumesource · definition

= drop()

§int device() constsource · definition
§int place(int device)source · definition

values and indices together; 1 on success

§int sync()source · definition
§unsigned long device_buffer() constsource · definition

the values' device buffer

§&FloatTensor to_dense() constsource · definition

A dense [rows, cols] copy: a graph node (gradients reach the values).

§struct SparseTensor scale(float k) constsource · definition

The same pattern with every value scaled: a graph node. It shares the pattern arrays (its free() releases only its values).

§struct SparseTensor transpose() constsource · definition

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 · definition

From 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 · definition

The entries of a dense [rows, cols] tensor whose magnitude exceeds 'threshold'.

§static struct SparseTensor identity(unsigned long n, int requiresGrad)source · definition

The n x n identity.