Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new sketch_symmetric function, reorganized tests, slightly improved web docs #98

Merged
merged 15 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RandBLAS.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <RandBLAS/sparse_skops.hh>
#include <RandBLAS/dense_skops.hh>
#include <RandBLAS/skge.hh>
#include <RandBLAS/skve.hh>
#include <RandBLAS/sksy.hh>
#include <RandBLAS/sparse_data/sksp.hh>

#endif
220 changes: 9 additions & 211 deletions RandBLAS/skge.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ using namespace RandBLAS::sparse;
*/


// MARK: SUBMAT(S), LEFT

// =============================================================================
/// \fn sketch_general(blas::Layout layout, blas::Op opS, blas::Op opA, int64_t d,
/// int64_t n, int64_t m, T alpha, SKOP &S, int64_t ro_s, int64_t co_s,
Expand Down Expand Up @@ -249,6 +251,8 @@ inline void sketch_general(
);
}

// MARK: SUBMAT(S), RIGHT

// =============================================================================
/// \fn sketch_general(blas::Layout layout, blas::Op opA, blas::Op opS, int64_t m, int64_t d, int64_t n,
/// T alpha, const T *A, int64_t lda, SKOP &S,
Expand Down Expand Up @@ -419,6 +423,9 @@ inline void sketch_general(
);
}


// MARK: FULL(S), LEFT

// =============================================================================
/// \fn sketch_general(blas::Layout layout, blas::Op opS, blas::Op opA, int64_t d,
/// int64_t n, int64_t m, T alpha, SKOP &S, const T *A, int64_t lda, T beta, T *B, int64_t ldb
Expand All @@ -431,15 +438,6 @@ inline void sketch_general(
///
/// where :math:`\alpha` and :math:`\beta` are real scalars, :math:`\op(X)` either returns a matrix :math:`X`
/// or its transpose, and :math:`S` is a sketching operator.
///
/// .. dropdown:: FAQ
/// :animate: fade-in-slide-down
///
/// **What are** :math:`\mat(A)` **and** :math:`\mat(B)` **?**
///
/// Their shapes are defined implicitly by :math:`(d, m, n, \opA).`
/// Their precise contents are determined by :math:`(A, \lda),` :math:`(B, \ldb),`
/// and "layout", following the same convention as the Level 3 BLAS function "GEMM."
///
/// .. dropdown:: Full parameter descriptions
/// :animate: fade-in-slide-down
Expand Down Expand Up @@ -530,6 +528,8 @@ inline void sketch_general(
return sketch_general(layout, opS, opA, d, n, m, alpha, S, 0, 0, A, lda, beta, B, ldb);
};

// MARK: FULL(S), RIGHT

// =============================================================================
/// \fn sketch_general(blas::Layout layout, blas::Op opA, blas::Op opS, int64_t m, int64_t d, int64_t n,
/// T alpha, const T *A, int64_t lda, SKOP &S, T beta, T *B, int64_t ldb
Expand All @@ -542,15 +542,6 @@ inline void sketch_general(
///
/// where :math:`\alpha` and :math:`\beta` are real scalars, :math:`\op(X)` either returns a matrix :math:`X`
/// or its transpose, and :math:`S` is a sketching operator.
///
/// .. dropdown:: FAQ
/// :animate: fade-in-slide-down
///
/// **What are** :math:`\mat(A)` **and** :math:`\mat(B)` **?**
///
/// Their shapes are defined implicitly by :math:`(m, d, n, \opA).`
/// Their precise contents are determined by :math:`(A, \lda),` :math:`(B, \ldb),`
/// and "layout", following the same convention as the Level 3 BLAS function "GEMM."
///
/// .. dropdown:: Full parameter descriptions
/// :animate: fade-in-slide-down
Expand Down Expand Up @@ -640,198 +631,5 @@ inline void sketch_general(
return sketch_general(layout, opA, opS, m, d, n, alpha, A, lda, S, 0, 0, beta, B, ldb);
};

// =============================================================================
/// \fn sketch_vector(blas::Op opS, int64_t d, int64_t m, T alpha, SKOP &S,
/// int64_t ro_s, int64_t co_s, const T *x, int64_t incx, T beta, T *y, int64_t incy
/// )
/// @verbatim embed:rst:leading-slashes
/// Perform a GEMV-like operation. If :math:`{\opS} = \texttt{NoTrans},` then we perform
///
/// .. math::
/// \mat(y) = \alpha \cdot \underbrace{\submat(S)}_{d \times m} \cdot \underbrace{\mat(x)}_{m \times 1} + \beta \cdot \underbrace{\mat(y)}_{d \times 1}, \tag{$\star$}
///
/// otherwise, we perform
///
/// .. math::
/// \mat(y) = \alpha \cdot \underbrace{\submat(S)^T}_{m \times d} \cdot \underbrace{\mat(x)}_{d \times 1} + \beta \cdot \underbrace{\mat(y)}_{m \times 1}, \tag{$\diamond$}
///
/// where :math:`\alpha` and :math:`\beta` are real scalars and :math:`S` is a sketching operator.
///
/// .. dropdown:: FAQ
/// :animate: fade-in-slide-down
///
/// **What are** :math:`\mat(x)` **and** :math:`\mat(y)` **?**
///
/// Their shapes are defined as tall vectors of dimension :math:`(\mat(x), L_x \times 1),` :math:`(\mat(y), L_y \times 1),`
/// where :math:`(L_x, L_y)` are lengths so that :math:`\opS(\submat(S)) \mat(x)` is well-defined and the same shape as :math:`\mat(y).`
/// Their precise contents are determined in a way that is identical to the Level 2 BLAS function "GEMV."
///
/// **Why no "layout" argument?**
///
/// The GEMV in CBLAS accepts a parameter that specifies row-major or column-major layout of the matrix.
/// Since our matrix is a sketching operator, and since RandBLAS has no notion of the layout of a sketching operator, we do not have a layout parameter.
///
/// .. dropdown:: Full parameter descriptions
/// :animate: fade-in-slide-down
///
/// opS - [in]
/// * Either Op::Trans or Op::NoTrans.
/// * If :math:`\opS` = NoTrans, then :math:`\op(\submat(S)) = \submat(S).`
/// * If :math:`\opS` = Trans, then :math:`\op(\submat(S)) = \submat(S)^T.`
///
/// d - [in]
/// * A nonnegative integer.
/// * The number of rows in :math:`\submat(S).`
///
/// m - [in]
/// * A nonnegative integer.
/// * The number of columns in :math:`\submat(S).`
///
/// alpha - [in]
/// * A real scalar.
/// * If zero, then :math:`x` is not accessed.
///
/// S - [in]
/// * A DenseSkOp or SparseSkOp object.
/// * Defines :math:`\submat(S).`
///
/// ro_s - [in]
/// * A nonnegative integer.
/// * :math:`\submat(S)` is a contiguous submatrix of :math:`S[\texttt{ro_s}:(\texttt{ro_s} + d), :].`
///
/// co_s - [in]
/// * A nonnegative integer.
/// * :math:`\submat(S)` is a contiguous submatrix of :math:`S[:,\texttt{co_s}:(\texttt{co_s} + m)].`
///
/// x - [in]
/// * Pointer to a 1D array of real scalars.
/// * Defines :math:`\mat(x).`
///
/// incx - [in]
/// * A positive integer.
/// * Stride between elements of x.
///
/// beta - [in]
/// * A real scalar.
/// * If zero, then :math:`y` need not be set on input.
///
/// y - [in, out]
/// * Pointer to 1D array of real scalars.
/// * On entry, defines :math:`\mat(y)` on the RIGHT-hand side of
/// :math:`(\star)` (if :math:`\opS = \texttt{NoTrans}`) or
/// :math:`(\diamond)` (if :math:`\opS = \texttt{Trans}`)
/// * On exit, defines :math:`\mat(y)` on the LEFT-hand side of the same.
///
/// incy - [in]
/// * A positive integer.
/// * Stride between elements of y.
///
/// @endverbatim
template <typename T, typename SKOP>
inline void sketch_vector(
blas::Op opS,
int64_t d, // rows in submat(S)
int64_t m, // cols in submat(S)
T alpha,
SKOP &S,
int64_t ro_s,
int64_t co_s,
const T *x,
int64_t incx,
T beta,
T *y,
int64_t incy
) {
int64_t _d, _m;
if (opS == blas::Op::Trans) {
_d = m;
_m = d;
} else {
_d = d;
_m = m;
}
return sketch_general(blas::Layout::RowMajor, opS, blas::Op::NoTrans, _d, 1, _m, alpha, S, ro_s, co_s, x, incx, beta, y, incy);
}

// =============================================================================
/// \fn sketch_vector(blas::Op opS, T alpha, SKOP &S,
/// const T *x, int64_t incx, T beta, T *y, int64_t incy
/// )
/// @verbatim embed:rst:leading-slashes
/// Perform a GEMV-like operation:
///
/// .. math::
/// \mat(y) = \alpha \cdot \op(S) \cdot \mat(x) + \beta \cdot \mat(y), \tag{$\star$}
///
/// where :math:`\alpha` and :math:`\beta` are real scalars and :math:`S` is a sketching operator.
///
/// .. dropdown:: FAQ
/// :animate: fade-in-slide-down
///
/// **What are** :math:`\mat(x)` **and** :math:`\mat(y)` **?**
///
/// Their shapes are defined as tall vectors of dimension :math:`(\mat(x), L_x \times 1),` :math:`(\mat(y), L_y \times 1),`
/// where :math:`(L_x, L_y)` are lengths so that :math:`\opS(S) \mat(x)` is well-defined and the same shape as :math:`\mat(y).`
/// Their precise contents are determined in a way that is identical to the Level 2 BLAS function "GEMV."
///
/// **Why no "layout" argument?**
///
/// The GEMV in CBLAS accepts a parameter that specifies row-major or column-major layout of the matrix.
/// Since our matrix is a sketching operator, and since RandBLAS has no notion of the layout of a sketching operator, we do not have a layout parameter.
///
/// .. dropdown:: Full parameter descriptions
/// :animate: fade-in-slide-down
///
/// opS - [in]
/// * Either Op::Trans or Op::NoTrans.
/// * If :math:`\opS` = NoTrans, then :math:`\op(S) = S.`
/// * If :math:`\opS` = Trans, then :math:`\op(S) = S^T.`
///
/// alpha - [in]
/// * A real scalar.
/// * If zero, then :math:`x` is not accessed.
///
/// S - [in]
/// * A DenseSkOp or SparseSkOp object.
///
/// x - [in]
/// * Pointer to a 1D array of real scalars.
/// * Defines :math:`\mat(x).`
///
/// incx - [in]
/// * A positive integer.
/// * Stride between elements of x.
///
/// beta - [in]
/// * A real scalar.
/// * If zero, then :math:`y` need not be set on input.
///
/// y - [in, out]
/// * Pointer to 1D array of real scalars.
/// * On entry, defines :math:`\mat(y)` on the RIGHT-hand side of
/// :math:`(\star).`
/// * On exit, defines :math:`\mat(y)` on the LEFT-hand side of the same.
///
/// incy - [in]
/// * A positive integer.
/// * Stride between elements of y.
///
/// @endverbatim
template <typename T, typename SKOP>
inline void sketch_vector(
blas::Op opS,
T alpha,
SKOP &S,
const T *x,
int64_t incx,
T beta,
T *y,
int64_t incy
) {
int64_t d = S.dist.n_rows;
int64_t m = S.dist.n_cols;
return sketch_vector(opS, d, m, alpha, S, 0, 0, x, incx, beta, y, incy);
}

} // end namespace RandBLAS
#endif
Loading
Loading