Attention

The vector search and clustering algorithms in RAFT are being migrated to a new library dedicated to vector search called cuVS. We will continue to support the vector search algorithms in RAFT during this move, but will no longer update them after the RAPIDS 24.06 (June) release. We plan to complete the migration by RAPIDS 24.08 (August) release.

Matrix-Vector Operations#

Arithmetic#

#include <raft/linalg/matrix_vector.cuh>

namespace raft::linalg

template<typename math_t, typename idx_t, typename layout_t>
void binary_mult_skip_zero(raft::resources const &handle, raft::device_matrix_view<math_t, idx_t, layout_t> data, raft::device_vector_view<const math_t, idx_t> vec, Apply apply)#

multiply each row or column of matrix with vector, skipping zeros in vector

Parameters:
  • handle[in] raft handle for managing library resources

  • data[inout] input matrix, results are in-place

  • vec[in] input vector

  • apply[in] whether the broadcast of vector needs to happen along the rows of the matrix or columns using enum class raft::linalg::Apply

template<typename math_t, typename idx_t, typename layout_t>
void binary_div(raft::resources const &handle, raft::device_matrix_view<math_t, idx_t, layout_t> data, raft::device_vector_view<const math_t, idx_t> vec, Apply apply)#

divide each row or column of matrix with vector

Parameters:
  • handle[in] raft handle for managing library resources

  • data[inout] input matrix, results are in-place

  • vec[in] input vector

  • apply[in] whether the broadcast of vector needs to happen along the rows of the matrix or columns using enum class raft::linalg::Apply

template<typename math_t, typename idx_t, typename layout_t>
void binary_div_skip_zero(raft::resources const &handle, raft::device_matrix_view<math_t, idx_t, layout_t> data, raft::device_vector_view<const math_t, idx_t> vec, Apply apply, bool return_zero = false)#

divide each row or column of matrix with vector, skipping zeros in vector

Parameters:
  • handle[in] raft handle for managing library resources

  • data[inout] input matrix, results are in-place

  • vec[in] input vector

  • apply[in] whether the broadcast of vector needs to happen along the rows of the matrix or columns using enum class raft::linalg::Apply

  • return_zero[in] result is zero if true and vector value is below threshold, original value if false

template<typename math_t, typename idx_t, typename layout_t>
void binary_add(raft::resources const &handle, raft::device_matrix_view<math_t, idx_t, layout_t> data, raft::device_vector_view<const math_t, idx_t> vec, Apply apply)#

add each row or column of matrix with vector

Parameters:
  • handle[in] raft handle for managing library resources

  • data[inout] input matrix, results are in-place

  • vec[in] input vector

  • apply[in] whether the broadcast of vector needs to happen along the rows of the matrix or columns using enum class raft::linalg::Apply

template<typename math_t, typename idx_t, typename layout_t>
void binary_sub(raft::resources const &handle, raft::device_matrix_view<math_t, idx_t, layout_t> data, raft::device_vector_view<const math_t, idx_t> vec, Apply apply)#

subtract each row or column of matrix with vector

Parameters:
  • handle[in] raft handle for managing library resources

  • data[inout] input matrix, results are in-place

  • vec[in] input vector

  • apply[in] whether the broadcast of vector needs to happen along the rows of the matrix or columns using enum class raft::linalg::Apply

Operations#

#include <raft/linalg/matrix_vector_op.cuh>

namespace raft::linalg

template<typename MatValueType, typename VecValueType, typename LayoutPolicy, typename Lambda, typename IndexType>
void matrix_vector_op(raft::resources const &handle, raft::device_matrix_view<const MatValueType, IndexType, LayoutPolicy> matrix, raft::device_vector_view<const VecValueType, IndexType> vec, raft::device_matrix_view<MatValueType, IndexType, LayoutPolicy> out, Apply apply, Lambda op)#

Operations for all the columns or rows with a given vector. Caution : Threads process multiple elements to speed up processing. These are loaded in a single read thanks to type promotion. Faster processing would thus only be enabled when addresses are optimally aligned for it. Note : the function will also check that the size of the window of accesses is a multiple of the number of elements processed by a thread in order to enable faster processing.

Template Parameters:
  • MatValueType – the data-type of the input matrix

  • VecValueType – the data-type of the input vector

  • LayoutPolicy – the layout of input and output (raft::row_major or raft::col_major)

  • Lambda – a device function which represents a binary operator

  • IndexType – Integer used for addressing

Parameters:
  • handle[in] raft::resources

  • matrix[in] input raft::matrix_view

  • vec[in] vector raft::vector_view

  • out[out] output raft::matrix_view

  • apply[in] whether the broadcast of vector needs to happen along the rows of the matrix or columns using enum class raft::linalg::Apply

  • op[in] the mathematical operation

template<typename MatValueType, typename Vec1ValueType, typename Vec2ValueType, typename LayoutPolicy, typename Lambda, typename IndexType>
void matrix_vector_op(raft::resources const &handle, raft::device_matrix_view<const MatValueType, IndexType, LayoutPolicy> matrix, raft::device_vector_view<const Vec1ValueType, IndexType> vec1, raft::device_vector_view<const Vec2ValueType, IndexType> vec2, raft::device_matrix_view<MatValueType, IndexType, LayoutPolicy> out, Apply apply, Lambda op)#

Operations for all the columns or rows with the given vectors. Caution : Threads process multiple elements to speed up processing. These are loaded in a single read thanks to type promotion. Faster processing would thus only be enabled when addresses are optimally aligned for it. Note : the function will also check that the size of the window of accesses is a multiple of the number of elements processed by a thread in order to enable faster processing.

Template Parameters:
  • MatValueType – the data-type of the input and output matrices

  • Vec1ValueType – the data-type of the first input vector

  • Vec2ValueType – the data-type of the second input vector

  • LayoutPolicy – the layout of input and output (raft::row_major or raft::col_major)

  • Lambda – a device function which represents a binary operator

  • IndexType – Integer used for addressing

Parameters:
  • handle – raft::resources

  • matrix – input raft::matrix_view

  • vec1 – the first vector raft::vector_view

  • vec2 – the second vector raft::vector_view

  • out – output raft::matrix_view

  • apply – whether the broadcast of vector needs to happen along the rows of the matrix or columns using enum class raft::linalg::Apply

  • op – the mathematical operation