注意

RAFT 中的向量搜索和聚类算法正在迁移到一个专门用于向量搜索的新库,名为 cuVS。在此迁移过程中,我们将继续支持 RAFT 中的向量搜索算法,但在 RAPIDS 24.06(6月)发布后将不再更新它们。我们计划在 RAPIDS 24.10(10月)发布时完成迁移,并在 24.12(12月)发布时将它们从 RAFT 中完全移除。

操作符和仿函数#

#include <raft/core/operators.hpp>

namespace raft::core

template<typename Type>
using add_const_op = plug_const_op<Type, add_op>#
template<typename Type>
using sub_const_op = plug_const_op<Type, sub_op>#
template<typename Type>
using mul_const_op = plug_const_op<Type, mul_op>#
template<typename Type>
using div_const_op = plug_const_op<Type, div_op>#
template<typename Type>
using div_checkzero_const_op = plug_const_op<Type, div_checkzero_op>#
template<typename Type>
using pow_const_op = plug_const_op<Type, pow_op>#
template<typename Type>
using mod_const_op = plug_const_op<Type, mod_op>#
template<typename Type>
using equal_const_op = plug_const_op<Type, equal_op>#
using absdiff_op = compose_op<abs_op, sub_op>#
using sqdiff_op = compose_op<sq_op, sub_op>#
struct identity_op#
#include <operators.hpp>

Subclassed by raft::neighbors::experimental::nn_descent::DistEpilogue< value_idx, value_t >

struct void_op#
#include <operators.hpp>
template<typename OutT>
struct cast_op#
#include <operators.hpp>
struct key_op#
#include <operators.hpp>
struct value_op#
#include <operators.hpp>
struct sqrt_op#
#include <operators.hpp>
struct nz_op#
#include <operators.hpp>
struct abs_op#
#include <operators.hpp>
struct sq_op#
#include <operators.hpp>
struct add_op#
#include <operators.hpp>
struct sub_op#
#include <operators.hpp>
struct mul_op#
#include <operators.hpp>
struct div_op#
#include <operators.hpp>
struct div_checkzero_op#
#include <operators.hpp>
struct pow_op#
#include <operators.hpp>
struct mod_op#
#include <operators.hpp>
struct min_op#
#include <operators.hpp>
struct max_op#
#include <operators.hpp>
struct argmin_op#
#include <operators.hpp>
struct argmax_op#
#include <operators.hpp>
struct greater_op#
#include <operators.hpp>
struct less_op#
#include <operators.hpp>
struct greater_or_equal_op#
#include <operators.hpp>
struct less_or_equal_op#
#include <operators.hpp>
struct equal_op#
#include <operators.hpp>
struct notequal_op#
#include <operators.hpp>
template<typename ScalarT>
struct const_op#
#include <operators.hpp>
template<typename ConstT, typename BinaryOpT>
struct plug_const_op#
#include <operators.hpp>

包装一个二元操作符,并在右侧传递一个常量。

使用示例

#include <raft/core/operators.hpp>

raft::plug_const_op<float, raft::mul_op> op(2.0f);
std::cout << op(2.1f) << std::endl;  // 4.2

模板参数:
  • ConstT

  • BinaryOpT

template<typename ...OpsT>
struct compose_op#
#include <operators.hpp>

通过组合操作符链构造一个操作符。

注意所有参数都会传递给最内层的操作符。

使用示例

#include <raft/core/operators.hpp>

auto op = raft::compose_op(raft::sqrt_op(), raft::abs_op(), raft::cast_op<float>(),
                           raft::add_const_op<int>(8));
std::cout << op(-50) << std::endl;  // 6.48074

模板参数:

OpsT – 任意数量的操作类型。

template<typename OuterOpT, typename ...ArgOpsT>
struct map_args_op#
#include <operators.hpp>

通过将一个外部操作与每个输入的内部操作组合来构造一个操作符。

使用示例

#include <raft/core/operators.hpp>

raft::map_args_op<raft::add_op, raft::sqrt_op, raft::cast_op<float>> op;
std::cout << op(42.0f, 10) << std::endl;  // 16.4807

模板参数:
  • OuterOpT – 外部操作类型

  • ArgOpsT – 外部操作每个输入的内部操作类型