注意
RAFT 中的向量搜索和聚类算法正在迁移到一个名为 cuVS 的新库,该库专门用于向量搜索。在此迁移过程中,我们将继续支持 RAFT 中的向量搜索算法,但在 RAPIDS 24.06(六月)发布后将不再更新它们。我们计划在 RAPIDS 24.10(十月)发布时完成迁移,并在 24.12(十二月)发布时将它们完全从 RAFT 中移除。
算术#
加法#
#include <raft/linalg/add.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void add(raft::resources const &handle, InType in1, InType in2, OutType out)# 逐元素加法运算。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
- 参数:
handle – [输入] raft::resources
in1 – [输入] 第一个输入
in2 – [输入] 第二个输入
out – [输出] 输出
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void add_scalar(raft::resources const &handle, InType in, OutType out, raft::device_scalar_view<const typename InType::value_type, ScalarIdxType> scalar)# 将设备标量逐元素添加到输入。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
ScalarIdxType – 标量的索引类型
- 参数:
handle – [输入] raft::resources
in – [输入] 输入
scalar – [输入] raft::device_scalar_view
out – [输入] 输出
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void add_scalar(raft::resources const &handle, const InType in, OutType out, raft::host_scalar_view<const typename InType::value_type, ScalarIdxType> scalar)# 将主机标量逐元素添加到输入。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
ScalarIdxType – 标量的索引类型
- 参数:
handle – [输入] raft::resources
in – [输入] 输入
scalar – [输入] raft::host_scalar_view
out – [输入] 输出
二元运算#
#include <raft/linalg/binary_op.cuh>
namespace raft::linalg
-
template<typename InType, typename Lambda, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void binary_op(raft::resources const &handle, InType in1, InType in2, OutType out, Lambda op)# 对输入数组执行逐元素二元运算
注意
Lambda 必须是一个具有以下签名的函数对象:
OutType func(const InType& val1, const InType& val2);
- 模板参数:
InType – 输入类型 raft::device_mdspan
Lambda – 执行实际操作的设备 lambda
OutType – 输出类型 raft::device_mdspan
- 参数:
handle – [输入] raft::resources
in1 – [输入] 第一个输入
in2 – [输入] 第二个输入
out – [输出] 输出
op – [输入] 设备 lambda
除法#
#include <raft/linalg/divide.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void divide_scalar(raft::resources const &handle, InType in, OutType out, raft::host_scalar_view<const typename InType::value_type, ScalarIdxType> scalar)# 输入逐元素除以主机标量。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
ScalarIdxType – 标量的索引类型
- 参数:
handle – [输入] raft::resources
in – [输入] 输入
scalar – [输入] raft::host_scalar_view
out – [输出] 输出
乘法#
#include <raft/linalg/multiply.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void multiply_scalar(raft::resources const &handle, InType in, OutType out, raft::host_scalar_view<const typename InType::value_type, ScalarIdxType> scalar)# 主机标量逐元素乘法。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
ScalarIdxType – 标量的索引类型
- 参数:
handle – [输入] raft::resources
in – [输入] 输入缓冲区
out – [输出] 输出缓冲区
scalar – [输入] 操作中使用的标量
幂#
#include <raft/linalg/power.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void power(raft::resources const &handle, InType in1, InType in2, OutType out)# 对输入缓冲区执行逐元素幂运算。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
- 参数:
handle – [输入] raft::resources
in1 – [输入] 第一个输入
in2 – [输入] 第二个输入
out – [输出] 输出
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void power_scalar(raft::resources const &handle, InType in, OutType out, const raft::host_scalar_view<const typename InType::value_type, ScalarIdxType> scalar)# 主机标量的逐元素幂应用于输入。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
ScalarIdxType – 标量的索引类型
- 参数:
handle – [输入] raft::resources
in – [输入] 输入
out – [输出] 输出
scalar – [输入] raft::host_scalar_view
平方根#
#include <raft/linalg/sqrt.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void sqrt(raft::resources const &handle, InType in, OutType out)# 逐元素平方根运算。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
- 参数:
handle – [输入] raft::resources
in – [输入] 输入
out – [输出] 输出
减法#
#include <raft/linalg/subtract.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void subtract(raft::resources const &handle, InType in1, InType in2, OutType out)# 对输入缓冲区执行逐元素减法运算。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
- 参数:
handle – raft::resources
in1 – [输入] 第一个输入
in2 – [输入] 第二个输入
out – [输出] 输出
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void subtract_scalar(raft::resources const &handle, InType in, OutType out, raft::device_scalar_view<const typename InType::element_type, ScalarIdxType> scalar)# 将设备标量逐元素从输入中减去。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
ScalarIdxType – 标量的索引类型
- 参数:
handle – [输入] raft::resources
in – [输入] 输入
out – [输出] 输出
scalar – [输入] raft::device_scalar_view
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void subtract_scalar(raft::resources const &handle, InType in, OutType out, raft::host_scalar_view<const typename InType::element_type, ScalarIdxType> scalar)# 将主机标量逐元素从输入中减去。
- 模板参数:
InType – 输入类型 raft::device_mdspan
OutType – 输出类型 raft::device_mdspan
ScalarIdxType – 标量的索引类型
- 参数:
handle – [输入] raft::resources
in – [输入] 输入
out – [输出] 输出
scalar – [输入] raft::host_scalar_view
三元运算#
#include <raft/linalg/ternary_op.cuh>
namespace raft::linalg
-
template<typename InType, typename Lambda, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void ternary_op(raft::resources const &handle, InType in1, InType in2, InType in3, OutType out, Lambda op)# 对输入数组执行逐元素三元运算
注意
Lambda 必须是一个具有以下签名的函数对象:
OutType func(const InType& val1, const InType& val2, const InType& val3);
- 模板参数:
InType – 输入类型 raft::device_mdspan
Lambda – 执行实际操作的设备 lambda
OutType – 输出类型 raft::device_mdspan
- 参数:
handle – [输入] raft::resources
in1 – [输入] 第一个输入
in2 – [输入] 第二个输入
in3 – [输入] 第三个输入
out – [输出] 输出
op – [输入] 设备 lambda
一元运算#
#include <raft/linalg/unary_op.cuh>
namespace raft::linalg
-
template<typename InType, typename Lambda, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void unary_op(raft::resources const &handle, InType in, OutType out, Lambda op)# 在输出数组中执行逐元素一元运算。
- 模板参数:
InType – 输入类型 raft::device_mdspan
Lambda – 执行实际操作的设备 lambda,具有签名
out_value_t func(const in_value_t& val);
OutType – 输出类型 raft::device_mdspan
- 参数:
handle – [输入] RAFT handle
in – [输入] 输入
out – [输出] 输出
op – [输入] 设备 lambda
-
template<typename OutType, typename Lambda, typename = raft::enable_if_output_device_mdspan<OutType>>
void write_only_unary_op(const raft::resources &handle, OutType out, Lambda op)# 对输入索引执行逐元素一元运算,并将结果写入输出数组。
注意
此操作已弃用。请改用
raft/linalg/map.cuh
中的 map_offset。- 模板参数:
OutType – 输出类型 raft::device_mdspan
Lambda – 执行实际操作的设备 lambda,具有签名
void func(out_value_t* out_location, index_t idx);
- 参数:
handle – [输入] RAFT handle
out – [输出] 输出
op – [输入] 设备 lambda