Computing a sketch : sparse data

template<typename T, SparseMatrix SpMat, typename RNG>
inline void RandBLAS::sketch_sparse(blas::Layout layout, blas::Op opS, blas::Op opA, int64_t d, int64_t n, int64_t m, T alpha, DenseSkOp<T, RNG> &S, int64_t ro_s, int64_t co_s, SpMat &A, int64_t ro_a, int64_t co_a, T beta, T *B, int64_t ldb)

Sketch from the left in an SpMM-like operation

\[\operatorname{mat}(B) = \alpha \cdot \underbrace{\operatorname{op}(\operatorname{submat}(S))}_{d \times m} \cdot \underbrace{\operatorname{op}(\operatorname{submat}(A))}_{m \times n} + \beta \cdot \underbrace{\operatorname{mat}(B)}_{d \times n}, \tag{$\star$}\]

where \(\alpha\) and \(\beta\) are real scalars, \(\operatorname{op}(X)\) either returns a matrix \(X\) or its transpose, \(A\) is a sparse matrix, and \(S\) is a dense sketching operator.

FAQ

What’s \(\operatorname{mat}(B)\) ?

It’s matrix of shape \(d \times n\). Its contents are determined by \((B, \texttt{ldb})\) and “layout”, following the same convention as the Level 3 BLAS function “GEMM.”

What are \(\operatorname{submat}(S)\) and \(\operatorname{submat}(A)\) ?

Their shapes are determined implicitly by \((\texttt{opS}, d, m)\) and \((\texttt{opA}, n, m)\). If \({\operatorname{submat}(X)}\) is of shape \(r \times c\), then it is the \(r \times c\) submatrix of \({X}\) whose upper-left corner appears at index \((\texttt{ro_x}, \texttt{co_x})\) of \({X}\).

Full parameter descriptions
layout - [in]
  • Layout::ColMajor or Layout::RowMajor.

  • Matrix storage for \(\operatorname{mat}(B)\).

opS - [in]
  • If \(\texttt{opS}\) = NoTrans, then \(\operatorname{op}(\operatorname{submat}(S)) = \operatorname{submat}(S)\).

  • If \(\texttt{opS}\) = Trans, then \(\operatorname{op}(\operatorname{submat}(S)) = \operatorname{submat}(S)^T\).

opA - [in]
  • If \(\texttt{opA}\) = NoTrans, then \(\operatorname{op}(\operatorname{submat}(A)) = \operatorname{submat}(A)\).

  • If \(\texttt{opA}\) = Trans, then \(\operatorname{op}(\operatorname{submat}(A)) = \operatorname{submat}(A)^T\).

d - [in]
  • A nonnegative integer.

  • The number of rows in \(\operatorname{mat}(B)\).

  • The number of rows in \(\operatorname{op}(\operatorname{submat}(S))\).

n - [in]
  • A nonnegative integer.

  • The number of columns in \(\operatorname{mat}(B)\).

  • The number of columns in \(\operatorname{op}(\operatorname{mat}(A))\).

m - [in]
  • A nonnegative integer.

  • The number of columns in \(\operatorname{op}(\operatorname{submat}(S))\)

  • The number of rows in \(\operatorname{op}(\operatorname{mat}(A))\).

alpha - [in]
  • A real scalar.

  • If zero, then \(A\) is not accessed.

S - [in]
  • A DenseSkOp object.

  • Defines \(\operatorname{submat}(S)\).

ro_s - [in]
  • A nonnegative integer.

  • The rows of \(\operatorname{submat}(S)\) are a contiguous subset of rows of \(S\).

  • The rows of \(\operatorname{submat}(S)\) start at \(S[\texttt{ro_s}, :]\).

co_s - [in]
  • A nonnegative integer.

  • The columns of \(\operatorname{submat}(S)\) are a contiguous subset of columns of \(S\).

  • The columns \(\operatorname{submat}(S)\) start at \(S[:,\texttt{co_s}]\).

A - [in]
  • A RandBLAS sparse matrix object.

  • Defines \(\operatorname{submat}(A)\).

ro_a - [in]
  • A nonnegative integer.

  • The rows of \(\operatorname{submat}(A)\) are a contiguous subset of rows of \(A\).

  • The rows of \(\operatorname{submat}(A)\) start at \(A[\texttt{ro_a}, :]\).

co_a - [in]
  • A nonnegative integer.

  • The columns of \(\operatorname{submat}(A)\) are a contiguous subset of columns of \(A\).

  • The columns \(\operatorname{submat}(A)\) start at \(A[:,\texttt{co_a}]\).

beta - [in]
  • A real scalar.

  • If zero, then \(B\) need not be set on input.

B - [in, out]
  • Pointer to 1D array of real scalars.

  • On entry, defines \(\operatorname{mat}(B)\) on the RIGHT-hand side of \((\star)\).

  • On exit, defines \(\operatorname{mat}(B)\) on the LEFT-hand side of \((\star)\).

ldb - [in]
  • A nonnegative integer.

  • Leading dimension of \(\operatorname{mat}(B)\) when reading from \(B\).

template<typename T, SparseMatrix SpMat, typename RNG>
inline void RandBLAS::sketch_sparse(blas::Layout layout, blas::Op opA, blas::Op opS, int64_t m, int64_t d, int64_t n, T alpha, SpMat &A, int64_t ro_a, int64_t co_a, DenseSkOp<T, RNG> &S, int64_t ro_s, int64_t co_s, T beta, T *B, int64_t ldb)

Sketch from the right in an SpMM-like operation

\[\operatorname{mat}(B) = \alpha \cdot \underbrace{\operatorname{op}(\operatorname{submat}(A))}_{m \times n} \cdot \underbrace{\operatorname{op}(\operatorname{submat}(S))}_{n \times d} + \beta \cdot \underbrace{\operatorname{mat}(B)}_{m \times d}, \tag{$\star$}\]

where \(\alpha\) and \(\beta\) are real scalars, \(\operatorname{op}(X)\) either returns a matrix \(X\) or its transpose, \(A\) is a sparse matrix, and \(S\) is a dense sketching operator.

FAQ

What’s \(\operatorname{mat}(B)\) ?

It’s matrix of shape \(m \times d\). Its contents are determined by \((B, \texttt{ldb})\) and “layout”, following the same convention as the Level 3 BLAS function “GEMM.”

What are \(\operatorname{submat}(S)\) and \(\operatorname{submat}(A)\) ?

Their shapes are determined implicitly by \((\texttt{opS}, n, d)\) and \((\texttt{opA}, m, n)\). If \({\operatorname{submat}(X)}\) is of shape \(r \times c\), then it is the \(r \times c\) submatrix of \({X}\) whose upper-left corner appears at index \((\texttt{ro_x}, \texttt{co_x})\) of \({X}\).

Full parameter descriptions
layout - [in]
  • Layout::ColMajor or Layout::RowMajor.

  • Matrix storage for \(\operatorname{mat}(B)\).

opA - [in]
  • If \(\texttt{opA}\) == NoTrans, then \(\operatorname{op}(\operatorname{submat}(A)) = \operatorname{submat}(A)\).

  • If \(\texttt{opA}\) == Trans, then \(\operatorname{op}(\operatorname{submat}(A)) = \operatorname{submat}(A)^T\).

opS - [in]
  • If \(\texttt{opS}\) = NoTrans, then \(\operatorname{op}(\operatorname{submat}(S)) = \operatorname{submat}(S)\).

  • If \(\texttt{opS}\) = Trans, then \(\operatorname{op}(\operatorname{submat}(S)) = \operatorname{submat}(S)^T\).

m - [in]
  • A nonnegative integer.

  • The number of rows in \(\operatorname{mat}(B)\).

  • The number of rows in \(\operatorname{op}(\operatorname{submat}(A))\).

d - [in]
  • A nonnegative integer.

  • The number of columns in \(\operatorname{mat}(B)\)

  • The number of columns in \(\operatorname{op}(\operatorname{submat}(S))\).

n - [in]
  • A nonnegative integer.

  • The number of columns in \(\operatorname{op}(\operatorname{submat}(A))\)

  • The number of rows in \(\operatorname{op}(\operatorname{submat}(S))\).

alpha - [in]
  • A real scalar.

  • If zero, then \(A\) is not accessed.

S - [in]
  • A DenseSkOp object.

  • Defines \(\operatorname{submat}(S)\).

ro_s - [in]
  • A nonnegative integer.

  • The rows of \(\operatorname{submat}(S)\) are a contiguous subset of rows of \(S\).

  • The rows of \(\operatorname{submat}(S)\) start at \(S[\texttt{ro_s}, :]\).

co_s - [in]
  • A nonnegative integer.

  • The columns of \(\operatorname{submat}(S)\) are a contiguous subset of columns of \(S\).

  • The columns \(\operatorname{submat}(S)\) start at \(S[:,\texttt{co_s}]\).

A - [in]
  • A RandBLAS sparse matrix object.

  • Defines \(\operatorname{submat}(A)\).

ro_a - [in]
  • A nonnegative integer.

  • The rows of \(\operatorname{submat}(A)\) are a contiguous subset of rows of \(A\).

  • The rows of \(\operatorname{submat}(A)\) start at \(A[\texttt{ro_a}, :]\).

co_a - [in]
  • A nonnegative integer.

  • The columns of \(\operatorname{submat}(A)\) are a contiguous subset of columns of \(A\).

  • The columns \(\operatorname{submat}(A)\) start at \(A[:,\texttt{co_a}]\).

beta - [in]
  • A real scalar.

  • If zero, then \(B\) need not be set on input.

B - [in, out]
  • Pointer to 1D array of real scalars.

  • On entry, defines \(\operatorname{mat}(B)\) on the RIGHT-hand side of \((\star)\).

  • On exit, defines \(\operatorname{mat}(B)\) on the LEFT-hand side of \((\star)\).

ldb - [in]
  • A nonnegative integer.

  • Leading dimension of \(\operatorname{mat}(B)\) when reading from \(B\).