Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move sketch_vector from skge.hh to skve.hh
Browse files Browse the repository at this point in the history
rileyjmurray committed Jun 27, 2024
1 parent 7320f0a commit f6bf945
Showing 3 changed files with 271 additions and 199 deletions.
2 changes: 2 additions & 0 deletions RandBLAS.hh
Original file line number Diff line number Diff line change
@@ -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
205 changes: 6 additions & 199 deletions RandBLAS/skge.hh
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ using namespace RandBLAS::sparse;
*/


// MARK: SUBMAT(S)
// MARK: SUBMAT(S), LEFT

// =============================================================================
/// \fn sketch_general(blas::Layout layout, blas::Op opS, blas::Op opA, int64_t d,
@@ -251,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,
@@ -422,7 +424,7 @@ inline void sketch_general(
}


// MARK: FULL(S)
// MARK: FULL(S), LEFT

// =============================================================================
/// \fn sketch_general(blas::Layout layout, blas::Op opS, blas::Op opA, int64_t d,
@@ -526,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
@@ -627,202 +631,5 @@ inline void sketch_general(
return sketch_general(layout, opA, opS, m, d, n, alpha, A, lda, S, 0, 0, beta, B, ldb);
};

// MARK: VECTOR, SUBMAT(S)

// =============================================================================
/// \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)` **?**
///
/// They are vectors of shapes :math:`(\mat(x), L_x \times 1)` and :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 GEMV from BLAS.
///
/// **Why no "layout" argument?**
///
/// GEMV in CBLAS accepts a parameter that specifies row-major or column-major layout of the matrix operand.
/// 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);
}

// MARK: VECTOR, FULL(S)

// =============================================================================
/// \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)` **?**
///
/// They are vectors of shapes :math:`(\mat(x), L_x \times 1)` and :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 GEMV from BLAS.
///
/// **Why no "layout" argument?**
///
/// GEMV in CBLAS accepts a parameter that specifies row-major or column-major layout of the matrix operand.
/// 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

0 comments on commit f6bf945

Please sign in to comment.