diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 6ad6960925..c91fcefed4 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -278,81 +278,83 @@ set_target_properties(raft_distance PROPERTIES EXPORT_NAME distance) if(RAFT_COMPILE_DIST_LIBRARY) add_library( raft_distance_lib - src/distance/pairwise_distance.cu - src/distance/fused_l2_min_arg.cu - src/distance/update_centroids_float.cu - src/distance/update_centroids_double.cu - src/distance/cluster_cost_float.cu - src/distance/cluster_cost_double.cu - src/distance/kmeans_fit_float.cu - src/distance/kmeans_fit_double.cu - src/distance/specializations/detail/canberra.cu - src/distance/specializations/detail/chebyshev.cu - src/distance/specializations/detail/correlation.cu - src/distance/specializations/detail/cosine.cu - src/distance/specializations/detail/cosine.cu - src/distance/specializations/detail/hamming_unexpanded.cu - src/distance/specializations/detail/hellinger_expanded.cu - src/distance/specializations/detail/jensen_shannon_float_float_float_int.cu - src/distance/specializations/detail/jensen_shannon_float_float_float_uint32.cu - src/distance/specializations/detail/jensen_shannon_double_double_double_int.cu - src/distance/specializations/detail/kernels/gram_matrix_base_double.cu - src/distance/specializations/detail/kernels/gram_matrix_base_float.cu - src/distance/specializations/detail/kernels/polynomial_kernel_double_int.cu - src/distance/specializations/detail/kernels/polynomial_kernel_float_int.cu + src/distance/distance/pairwise_distance.cu + src/distance/distance/fused_l2_min_arg.cu + src/distance/cluster/update_centroids_float.cu + src/distance/cluster/update_centroids_double.cu + src/distance/cluster/cluster_cost_float.cu + src/distance/cluster/cluster_cost_double.cu + src/distance/neighbors/refine.cu + src/distance/neighbors/ivfpq_search.cu + src/distance/cluster/kmeans_fit_float.cu + src/distance/cluster/kmeans_fit_double.cu + src/distance/distance/specializations/detail/canberra.cu + src/distance/distance/specializations/detail/chebyshev.cu + src/distance/distance/specializations/detail/correlation.cu + src/distance/distance/specializations/detail/cosine.cu + src/distance/distance/specializations/detail/cosine.cu + src/distance/distance/specializations/detail/hamming_unexpanded.cu + src/distance/distance/specializations/detail/hellinger_expanded.cu + src/distance/distance/specializations/detail/jensen_shannon_float_float_float_int.cu + src/distance/distance/specializations/detail/jensen_shannon_float_float_float_uint32.cu + src/distance/distance/specializations/detail/jensen_shannon_double_double_double_int.cu + src/distance/distance/specializations/detail/kernels/gram_matrix_base_double.cu + src/distance/distance/specializations/detail/kernels/gram_matrix_base_float.cu + src/distance/distance/specializations/detail/kernels/polynomial_kernel_double_int.cu + src/distance/distance/specializations/detail/kernels/polynomial_kernel_float_int.cu # These are somehow missing a kernel definition which is causing a compile error. # src/distance/specializations/detail/kernels/rbf_kernel_double.cu # src/distance/specializations/detail/kernels/rbf_kernel_float.cu - src/distance/specializations/detail/kernels/tanh_kernel_double.cu - src/distance/specializations/detail/kernels/tanh_kernel_float.cu - src/distance/specializations/detail/kl_divergence_float_float_float_int.cu - src/distance/specializations/detail/kl_divergence_float_float_float_uint32.cu - src/distance/specializations/detail/kl_divergence_double_double_double_int.cu - src/distance/specializations/detail/l1_float_float_float_int.cu - src/distance/specializations/detail/l1_float_float_float_uint32.cu - src/distance/specializations/detail/l1_double_double_double_int.cu - src/distance/specializations/detail/l2_expanded_float_float_float_int.cu - src/distance/specializations/detail/l2_expanded_float_float_float_uint32.cu - src/distance/specializations/detail/l2_expanded_double_double_double_int.cu - src/distance/specializations/detail/l2_sqrt_expanded_float_float_float_int.cu - src/distance/specializations/detail/l2_sqrt_expanded_float_float_float_uint32.cu - src/distance/specializations/detail/l2_sqrt_expanded_double_double_double_int.cu - src/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_int.cu - src/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_uint32.cu - src/distance/specializations/detail/l2_sqrt_unexpanded_double_double_double_int.cu - src/distance/specializations/detail/l2_unexpanded_double_double_double_int.cu - src/distance/specializations/detail/l2_unexpanded_float_float_float_uint32.cu - src/distance/specializations/detail/l2_unexpanded_float_float_float_int.cu - src/distance/specializations/detail/lp_unexpanded_double_double_double_int.cu - src/distance/specializations/detail/lp_unexpanded_float_float_float_uint32.cu - src/distance/specializations/detail/lp_unexpanded_float_float_float_int.cu - src/distance/specializations/detail/russel_rao_double_double_double_int.cu - src/distance/specializations/detail/russel_rao_float_float_float_uint32.cu - src/distance/specializations/detail/russel_rao_float_float_float_int.cu - src/distance/specializations/fused_l2_nn_double_int.cu - src/distance/specializations/fused_l2_nn_double_int64.cu - src/distance/specializations/fused_l2_nn_float_int.cu - src/distance/specializations/fused_l2_nn_float_int64.cu - src/nn/specializations/detail/ivfpq_build.cu - src/nn/specializations/detail/ivfpq_compute_similarity_float_fast.cu - src/nn/specializations/detail/ivfpq_compute_similarity_float_no_basediff.cu - src/nn/specializations/detail/ivfpq_compute_similarity_float_no_smem_lut.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_fast.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_no_basediff.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_no_smem_lut.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_fast.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_no_basediff.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_no_smem_lut.cu - src/nn/specializations/detail/ivfpq_compute_similarity_half_fast.cu - src/nn/specializations/detail/ivfpq_compute_similarity_half_no_basediff.cu - src/nn/specializations/detail/ivfpq_compute_similarity_half_no_smem_lut.cu - src/nn/specializations/detail/ivfpq_search.cu - src/nn/specializations/detail/ivfpq_search_float_uint64_t.cu - src/nn/specializations/refine.cu - src/random/specializations/rmat_rectangular_generator_int_double.cu - src/random/specializations/rmat_rectangular_generator_int64_double.cu - src/random/specializations/rmat_rectangular_generator_int_float.cu - src/random/specializations/rmat_rectangular_generator_int64_float.cu + src/distance/distance/specializations/detail/kernels/tanh_kernel_double.cu + src/distance/distance/specializations/detail/kernels/tanh_kernel_float.cu + src/distance/distance/specializations/detail/kl_divergence_float_float_float_int.cu + src/distance/distance/specializations/detail/kl_divergence_float_float_float_uint32.cu + src/distance/distance/specializations/detail/kl_divergence_double_double_double_int.cu + src/distance/distance/specializations/detail/l1_float_float_float_int.cu + src/distance/distance/specializations/detail/l1_float_float_float_uint32.cu + src/distance/distance/specializations/detail/l1_double_double_double_int.cu + src/distance/distance/specializations/detail/l2_expanded_float_float_float_int.cu + src/distance/distance/specializations/detail/l2_expanded_float_float_float_uint32.cu + src/distance/distance/specializations/detail/l2_expanded_double_double_double_int.cu + src/distance/distance/specializations/detail/l2_sqrt_expanded_float_float_float_int.cu + src/distance/distance/specializations/detail/l2_sqrt_expanded_float_float_float_uint32.cu + src/distance/distance/specializations/detail/l2_sqrt_expanded_double_double_double_int.cu + src/distance/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_int.cu + src/distance/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_uint32.cu + src/distance/distance/specializations/detail/l2_sqrt_unexpanded_double_double_double_int.cu + src/distance/distance/specializations/detail/l2_unexpanded_double_double_double_int.cu + src/distance/distance/specializations/detail/l2_unexpanded_float_float_float_uint32.cu + src/distance/distance/specializations/detail/l2_unexpanded_float_float_float_int.cu + src/distance/distance/specializations/detail/lp_unexpanded_double_double_double_int.cu + src/distance/distance/specializations/detail/lp_unexpanded_float_float_float_uint32.cu + src/distance/distance/specializations/detail/lp_unexpanded_float_float_float_int.cu + src/distance/distance/specializations/detail/russel_rao_double_double_double_int.cu + src/distance/distance/specializations/detail/russel_rao_float_float_float_uint32.cu + src/distance/distance/specializations/detail/russel_rao_float_float_float_int.cu + src/distance/distance/specializations/fused_l2_nn_double_int.cu + src/distance/distance/specializations/fused_l2_nn_double_int64.cu + src/distance/distance/specializations/fused_l2_nn_float_int.cu + src/distance/distance/specializations/fused_l2_nn_float_int64.cu + src/distance/neighbors/ivfpq_build.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_fast.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_no_basediff.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_no_smem_lut.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_fast.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_no_basediff.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_no_smem_lut.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_fast.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_no_basediff.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_no_smem_lut.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_fast.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_no_basediff.cu + src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_no_smem_lut.cu + src/distance/neighbors/specializations/detail/ivfpq_search_float_int64_t.cu + src/distance/neighbors/specializations/detail/ivfpq_search_float_uint64_t.cu + src/distance/neighbors/specializations/detail/ivfpq_search_float_uint32_t.cu + src/distance/random/rmat_rectangular_generator_int_double.cu + src/distance/random/rmat_rectangular_generator_int64_double.cu + src/distance/random/rmat_rectangular_generator_int_float.cu + src/distance/random/rmat_rectangular_generator_int64_float.cu ) set_target_properties( raft_distance_lib @@ -410,23 +412,6 @@ if(RAFT_COMPILE_NN_LIBRARY) src/nn/specializations/detail/ball_cover_lowdim_pass_two_2d.cu src/nn/specializations/detail/ball_cover_lowdim_pass_one_3d.cu src/nn/specializations/detail/ball_cover_lowdim_pass_two_3d.cu - src/nn/specializations/detail/ivfpq_compute_similarity_float_fast.cu - src/nn/specializations/detail/ivfpq_compute_similarity_float_no_basediff.cu - src/nn/specializations/detail/ivfpq_compute_similarity_float_no_smem_lut.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_fast.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_no_basediff.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_no_smem_lut.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_fast.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_no_basediff.cu - src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_no_smem_lut.cu - src/nn/specializations/detail/ivfpq_compute_similarity_half_fast.cu - src/nn/specializations/detail/ivfpq_compute_similarity_half_no_basediff.cu - src/nn/specializations/detail/ivfpq_compute_similarity_half_no_smem_lut.cu - src/nn/specializations/detail/ivfpq_build.cu - src/nn/specializations/detail/ivfpq_search.cu - src/nn/specializations/detail/ivfpq_search_float_int64_t.cu - src/nn/specializations/detail/ivfpq_search_float_uint32_t.cu - src/nn/specializations/detail/ivfpq_search_float_uint64_t.cu src/nn/specializations/fused_l2_knn_long_float_true.cu src/nn/specializations/fused_l2_knn_long_float_false.cu src/nn/specializations/fused_l2_knn_int_float_true.cu @@ -519,7 +504,7 @@ if(TARGET raft_distance_lib) EXPORT raft-distance-lib-exports ) install( - DIRECTORY include/raft_distance + DIRECTORY include/raft_runtime DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT distance ) diff --git a/cpp/include/raft/distance/distance.cuh b/cpp/include/raft/distance/distance.cuh index 6e3f97b45c..1c069fc397 100644 --- a/cpp/include/raft/distance/distance.cuh +++ b/cpp/include/raft/distance/distance.cuh @@ -25,14 +25,14 @@ #include +namespace raft { +namespace distance { + /** - * @defgroup pairwise_distance pairwise distance prims + * @defgroup pairwise_distance pointer-based pairwise distance prims * @{ */ -namespace raft { -namespace distance { - /** * @brief Evaluate pairwise distances with the user epilogue lamba allowed * @tparam DistanceType which distance to evaluate @@ -219,58 +219,6 @@ void distance(const InType* x, x, y, dist, m, n, k, workspace.data(), worksize, stream, isRowMajor, metric_arg); } -/** - * @brief Evaluate pairwise distances for the simple use case. - * - * Note: Only contiguous row- or column-major layouts supported currently. - * - * @tparam DistanceType which distance to evaluate - * @tparam InType input argument type - * @tparam AccType accumulation type - * @tparam OutType output type - * @tparam Index_ Index type - * @param handle raft handle for managing expensive resources - * @param x first set of points (size n*k) - * @param y second set of points (size m*k) - * @param dist output distance matrix (size n*m) - * @param metric_arg metric argument (used for Minkowski distance) - */ -template -void distance(raft::handle_t const& handle, - raft::device_matrix_view const x, - raft::device_matrix_view const y, - raft::device_matrix_view dist, - InType metric_arg = 2.0f) -{ - RAFT_EXPECTS(x.extent(1) == y.extent(1), "Number of columns must be equal."); - RAFT_EXPECTS(dist.extent(0) == x.extent(0), - "Number of rows in output must be equal to " - "number of rows in X"); - RAFT_EXPECTS(dist.extent(1) == y.extent(0), - "Number of columns in output must be equal to " - "number of rows in Y"); - - RAFT_EXPECTS(x.is_exhaustive(), "Input x must be contiguous."); - RAFT_EXPECTS(y.is_exhaustive(), "Input y must be contiguous."); - - constexpr auto is_rowmajor = std::is_same_v; - - distance(x.data_handle(), - y.data_handle(), - dist.data_handle(), - x.extent(0), - y.extent(0), - x.extent(1), - handle.get_stream(), - is_rowmajor, - metric_arg); -} - /** * @brief Convenience wrapper around 'distance' prim to convert runtime metric * into compile time for the purpose of dispatch @@ -401,6 +349,85 @@ void pairwise_distance(const raft::handle_t& handle, handle, x, y, dist, m, n, k, workspace, metric, isRowMajor, metric_arg); } +/** @} */ + +/** + * \defgroup distance_mdspan Pairwise distance functions + * @{ + */ + +/** + * @brief Evaluate pairwise distances for the simple use case. + * + * Note: Only contiguous row- or column-major layouts supported currently. + * + * Usage example: + * @code{.cpp} + * #include + * #include + * #include + * #include + * + * raft::handle_t handle; + * int n_samples = 5000; + * int n_features = 50; + * + * auto input = raft::make_device_matrix(handle, n_samples, n_features); + * auto labels = raft::make_device_vector(handle, n_samples); + * auto output = raft::make_device_matrix(handle, n_samples, n_samples); + * + * raft::random::make_blobs(handle, input.view(), labels.view()); + * auto metric = raft::distance::DistanceType::L2SqrtExpanded; + * raft::distance::pairwise_distance(handle, input.view(), input.view(), output.view(), metric); + * @endcode + * + * @tparam DistanceType which distance to evaluate + * @tparam InType input argument type + * @tparam AccType accumulation type + * @tparam OutType output type + * @tparam Index_ Index type + * @param handle raft handle for managing expensive resources + * @param x first set of points (size n*k) + * @param y second set of points (size m*k) + * @param dist output distance matrix (size n*m) + * @param metric_arg metric argument (used for Minkowski distance) + */ +template +void distance(raft::handle_t const& handle, + raft::device_matrix_view const x, + raft::device_matrix_view const y, + raft::device_matrix_view dist, + InType metric_arg = 2.0f) +{ + RAFT_EXPECTS(x.extent(1) == y.extent(1), "Number of columns must be equal."); + RAFT_EXPECTS(dist.extent(0) == x.extent(0), + "Number of rows in output must be equal to " + "number of rows in X"); + RAFT_EXPECTS(dist.extent(1) == y.extent(0), + "Number of columns in output must be equal to " + "number of rows in Y"); + + RAFT_EXPECTS(x.is_exhaustive(), "Input x must be contiguous."); + RAFT_EXPECTS(y.is_exhaustive(), "Input y must be contiguous."); + + constexpr auto is_rowmajor = std::is_same_v; + + distance(x.data_handle(), + y.data_handle(), + dist.data_handle(), + x.extent(0), + y.extent(0), + x.extent(1), + handle.get_stream(), + is_rowmajor, + metric_arg); +} + /** * @brief Convenience wrapper around 'distance' prim to convert runtime metric * into compile time for the purpose of dispatch @@ -449,9 +476,9 @@ void pairwise_distance(raft::handle_t const& handle, metric_arg); } +/** @} */ + }; // namespace distance }; // namespace raft -/** @} */ - #endif \ No newline at end of file diff --git a/cpp/include/raft/distance/fused_l2_nn.cuh b/cpp/include/raft/distance/fused_l2_nn.cuh index ef51a54622..1f677e919d 100644 --- a/cpp/include/raft/distance/fused_l2_nn.cuh +++ b/cpp/include/raft/distance/fused_l2_nn.cuh @@ -30,6 +30,10 @@ namespace raft { namespace distance { +/** + * \defgroup fused_l2_nn Fused 1-nearest neighbors + * @{ + */ template using KVPMinReduce = detail::KVPMinReduceImpl; @@ -40,6 +44,8 @@ using MinAndDistanceReduceOp = detail::MinAndDistanceReduceOpImpl template using MinReduceOp = detail::MinReduceOpImpl; +/** @} */ + /** * Initialize array using init value from reduction op */ @@ -49,6 +55,10 @@ void initialize(const raft::handle_t& handle, OutT* min, IdxT m, DataT maxVal, R detail::initialize(min, m, maxVal, redOp, handle.get_stream()); } +/** + * \ingroup fused_l2_nn + * @{ + */ /** * @brief Fused L2 distance and 1-nearest-neighbor computation in a single call. * @@ -211,6 +221,8 @@ void fusedL2NNMinReduce(OutT* min, min, x, y, xn, yn, m, n, k, workspace, redOp, pairRedOp, sqrt, initOutBuffer, stream); } +/** @} */ + } // namespace distance } // namespace raft diff --git a/cpp/include/raft/linalg/add.cuh b/cpp/include/raft/linalg/add.cuh index 37956fe762..341ba45af5 100644 --- a/cpp/include/raft/linalg/add.cuh +++ b/cpp/include/raft/linalg/add.cuh @@ -16,11 +16,6 @@ #ifndef __ADD_H #define __ADD_H -/** - * @defgroup arithmetic Dense matrix arithmetic - * @{ - */ - #pragma once #include "detail/add.cuh" @@ -94,7 +89,7 @@ void addDevScalar( } /** - * @defgroup add Addition Arithmetic + * @defgroup add_dense Addition Arithmetic * @{ */ @@ -226,6 +221,4 @@ void add_scalar(const raft::handle_t& handle, }; // end namespace linalg }; // end namespace raft -/** @} */ - #endif \ No newline at end of file diff --git a/cpp/include/raft/linalg/axpy.cuh b/cpp/include/raft/linalg/axpy.cuh index 88b065c8b0..35a34bc2b5 100644 --- a/cpp/include/raft/linalg/axpy.cuh +++ b/cpp/include/raft/linalg/axpy.cuh @@ -54,7 +54,7 @@ void axpy(const raft::handle_t& handle, } /** - * @defgroup axpy axpy + * @defgroup axpy axpy routine * @{ */ diff --git a/cpp/include/raft/linalg/dot.cuh b/cpp/include/raft/linalg/dot.cuh index 48577650bc..4b1bc913e1 100644 --- a/cpp/include/raft/linalg/dot.cuh +++ b/cpp/include/raft/linalg/dot.cuh @@ -25,6 +25,12 @@ #include namespace raft::linalg { + +/** + * @defgroup dot BLAS dot routine + * @{ + */ + /** * @brief Computes the dot product of two vectors. * @param[in] handle raft::handle_t @@ -84,5 +90,8 @@ void dot(const raft::handle_t& handle, out.data_handle(), handle.get_stream())); } + +/** @} */ // end of group dot + } // namespace raft::linalg #endif diff --git a/cpp/include/raft/linalg/eig.cuh b/cpp/include/raft/linalg/eig.cuh index 2ad222d42d..271ff13db5 100644 --- a/cpp/include/raft/linalg/eig.cuh +++ b/cpp/include/raft/linalg/eig.cuh @@ -25,11 +25,6 @@ namespace raft { namespace linalg { -/** - * @defgroup eig Eigen Decomposition Methods - * @{ - */ - /** * @brief eig decomp with divide and conquer method for the column-major * symmetric matrices @@ -115,6 +110,11 @@ void eigJacobi(const raft::handle_t& handle, detail::eigJacobi(handle, in, n_rows, n_cols, eig_vectors, eig_vals, stream, tol, sweeps); } +/** + * @defgroup eig Eigen Decomposition Methods + * @{ + */ + /** * @brief eig decomp with divide and conquer method for the column-major * symmetric matrices diff --git a/cpp/include/raft/linalg/map_reduce.cuh b/cpp/include/raft/linalg/map_reduce.cuh index 180ed128a1..4158d35bca 100644 --- a/cpp/include/raft/linalg/map_reduce.cuh +++ b/cpp/include/raft/linalg/map_reduce.cuh @@ -24,11 +24,6 @@ namespace raft::linalg { -/** - * @defgroup map_reduce Map-Reduce ops - * @{ - */ - /** * @brief CUDA version of map and then generic reduction operation * @tparam Type data-type upon which the math operation will be performed @@ -67,6 +62,10 @@ void mapReduce(OutType* out, out, len, neutral, map, op, stream, in, args...); } +/** + * @defgroup map_reduce Map-Reduce ops + * @{ + */ /** * @brief CUDA version of map and then generic reduction operation * @tparam InValueType the data-type of the input diff --git a/cpp/include/raft/linalg/matrix_vector.cuh b/cpp/include/raft/linalg/matrix_vector.cuh index 57bc0cf21f..5529ded16f 100644 --- a/cpp/include/raft/linalg/matrix_vector.cuh +++ b/cpp/include/raft/linalg/matrix_vector.cuh @@ -23,6 +23,11 @@ namespace raft::linalg { +/** + * @defgroup matrix_vector Matrix-Vector Operations + * @{ + */ + /** * @brief multiply each row or column of matrix with vector, skipping zeros in vector * @param [in] handle: raft handle for managing library resources @@ -191,4 +196,7 @@ void binary_sub(const raft::handle_t& handle, bcast_along_rows, handle.get_stream()); } + +/** @} */ // end of matrix_vector + } // namespace raft::linalg \ No newline at end of file diff --git a/cpp/include/raft/linalg/norm.cuh b/cpp/include/raft/linalg/norm.cuh index 9abfd3bdb0..19757eb86d 100644 --- a/cpp/include/raft/linalg/norm.cuh +++ b/cpp/include/raft/linalg/norm.cuh @@ -87,6 +87,11 @@ void colNorm(Type* dots, detail::colNormCaller(dots, data, D, N, type, rowMajor, stream, fin_op); } +/** + * @defgroup norm Row- or Col-norm computation + * @{ + */ + /** * @brief Compute norm of the input matrix and perform fin_op * @tparam ElementType Input/Output data type @@ -142,6 +147,8 @@ void norm(const raft::handle_t& handle, } } +/** @} */ + }; // end namespace linalg }; // end namespace raft diff --git a/cpp/include/raft/linalg/normalize.cuh b/cpp/include/raft/linalg/normalize.cuh index 4bdf697581..e64436762c 100644 --- a/cpp/include/raft/linalg/normalize.cuh +++ b/cpp/include/raft/linalg/normalize.cuh @@ -23,6 +23,11 @@ namespace raft { namespace linalg { +/** + * @defgroup norm Row- or Col-norm computation + * @{ + */ + /** * @brief Divide rows by their norm defined by main_op, reduce_op and fin_op * @@ -127,5 +132,7 @@ void row_normalize(const raft::handle_t& handle, } } +/** @} */ + } // namespace linalg } // namespace raft diff --git a/cpp/include/raft/linalg/qr.cuh b/cpp/include/raft/linalg/qr.cuh index 7e6e14e680..7c5c0ea628 100644 --- a/cpp/include/raft/linalg/qr.cuh +++ b/cpp/include/raft/linalg/qr.cuh @@ -23,11 +23,6 @@ namespace raft { namespace linalg { -/** - * @defgroup QRdecomp QR decomposition - * @{ - */ - /** * @brief compute QR decomp and return only Q matrix * @param handle: raft handle @@ -70,6 +65,11 @@ void qrGetQR(const raft::handle_t& handle, detail::qrGetQR(handle, M, Q, R, n_rows, n_cols, stream); } +/** + * @defgroup qr QR Decomposition + * @{ + */ + /** * @brief Compute the QR decomposition of matrix M and return only the Q matrix. * @param[in] handle raft::handle_t diff --git a/cpp/include/raft/linalg/transpose.cuh b/cpp/include/raft/linalg/transpose.cuh index e765ea7925..608a87b489 100644 --- a/cpp/include/raft/linalg/transpose.cuh +++ b/cpp/include/raft/linalg/transpose.cuh @@ -56,6 +56,11 @@ void transpose(math_t* inout, int n, cudaStream_t stream) detail::transpose(inout, n, stream); } +/** + * @defgroup transpose Matrix transpose + * @{ + */ + /** * @brief Transpose a matrix. The output has same layout policy as the input. * @@ -94,6 +99,9 @@ auto transpose(handle_t const& handle, } } } + +/** @} */ // end of group transpose + }; // end namespace linalg }; // end namespace raft diff --git a/cpp/include/raft/matrix/argmax.cuh b/cpp/include/raft/matrix/argmax.cuh index e6736b14de..a614f7043f 100644 --- a/cpp/include/raft/matrix/argmax.cuh +++ b/cpp/include/raft/matrix/argmax.cuh @@ -21,6 +21,11 @@ namespace raft::matrix { +/** + * @defgroup argmax Argmax operation + * @{ + */ + /** * @brief Argmax: find the col idx with maximum value for each row * @param[in] handle: raft handle @@ -37,4 +42,7 @@ void argmax(const raft::handle_t& handle, detail::argmax( in.data_handle(), in.extent(1), in.extent(0), out.data_handle(), handle.get_stream()); } + +/** @} */ // end of group argmax + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/argmin.cuh b/cpp/include/raft/matrix/argmin.cuh index e8cf763f70..ca7b0252d2 100644 --- a/cpp/include/raft/matrix/argmin.cuh +++ b/cpp/include/raft/matrix/argmin.cuh @@ -21,6 +21,11 @@ namespace raft::matrix { +/** + * @defgroup argmin Argmin operation + * @{ + */ + /** * @brief Argmin: find the col idx with minimum value for each row * @param[in] handle: raft handle @@ -37,4 +42,7 @@ void argmin(const raft::handle_t& handle, detail::argmin( in.data_handle(), in.extent(1), in.extent(0), out.data_handle(), handle.get_stream()); } + +/** @} */ // end of group argmin + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/col_wise_sort.cuh b/cpp/include/raft/matrix/col_wise_sort.cuh index 5f9b3ab848..662f62d865 100644 --- a/cpp/include/raft/matrix/col_wise_sort.cuh +++ b/cpp/include/raft/matrix/col_wise_sort.cuh @@ -52,6 +52,11 @@ void sort_cols_per_row(const InType* in, in, out, n_rows, n_columns, bAllocWorkspace, workspacePtr, workspaceSize, stream, sortedKeys); } +/** + * @defgroup col_wise_sort Sort rows within each column + * @{ + */ + /** * @brief sort columns within each row of row-major input matrix and return sorted indexes * modelled as key-value sort with key being input matrix and value being index of values @@ -126,6 +131,8 @@ void sort_cols_per_row(Args... args) sort_cols_per_row(std::forward(args)..., std::nullopt); } +/** @} */ // end of group col_wise_sort + }; // end namespace raft::matrix #endif \ No newline at end of file diff --git a/cpp/include/raft/matrix/copy.cuh b/cpp/include/raft/matrix/copy.cuh index 5f1d16485c..0727fac246 100644 --- a/cpp/include/raft/matrix/copy.cuh +++ b/cpp/include/raft/matrix/copy.cuh @@ -22,6 +22,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_copy Matrix copy operations + * @{ + */ + /** * @brief Copy selected rows of the input matrix into contiguous space. * @@ -94,4 +99,6 @@ void trunc_zero_origin(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end of group matrix_copy + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/diagonal.cuh b/cpp/include/raft/matrix/diagonal.cuh index d83c932fcd..22862e43b6 100644 --- a/cpp/include/raft/matrix/diagonal.cuh +++ b/cpp/include/raft/matrix/diagonal.cuh @@ -22,6 +22,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_diagonal Matrix diagonal operations + * @{ + */ + /** * @brief Initialize a diagonal matrix with a vector * @param[in] handle: raft handle @@ -76,4 +81,7 @@ void invert_diagonal(const raft::handle_t& handle, RAFT_EXPECTS(inout.extent(0) == inout.extent(1), "Matrix must be square."); detail::getDiagonalInverseMatrix(inout.data_handle(), inout.extent(0), handle.get_stream()); } + +/** @} */ // end of group matrix_diagonal + } // namespace raft::matrix \ No newline at end of file diff --git a/cpp/include/raft/matrix/gather.cuh b/cpp/include/raft/matrix/gather.cuh index 12b0b94fa5..6a923fb0cc 100644 --- a/cpp/include/raft/matrix/gather.cuh +++ b/cpp/include/raft/matrix/gather.cuh @@ -22,6 +22,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_gather Matrix gather operations + * @{ + */ + /** * @brief gather copies rows from a source matrix into a destination matrix according to a map. * @@ -51,76 +56,6 @@ void gather(const MatrixIteratorT in, detail::gather(in, D, N, map, map_length, out, stream); } -/** - * @brief gather copies rows from a source matrix into a destination matrix according to a map. - * - * @tparam matrix_t Matrix element type - * @tparam map_t Map vector type - * @tparam idx_t integer type used for indexing - * @param[in] handle raft handle for managing resources - * @param[in] in Input matrix (assumed to be row-major) - * @param[in] map Vector of gather locations - * @param[out] out Output matrix (assumed to be row-major) - */ -template -void gather(const raft::handle_t& handle, - raft::device_matrix_view in, - raft::device_vector_view map, - raft::device_matrix_view out) -{ - RAFT_EXPECTS(out.extent(0) == map.extent(0), - "Number of rows in output matrix must equal the size of the map vector"); - RAFT_EXPECTS(out.extent(1) == in.extent(1), - "Number of columns in input and output matrices must be equal."); - - raft::matrix::detail::gather( - const_cast(in.data_handle()), // TODO: There's a better way to handle this - static_cast(in.extent(1)), - static_cast(in.extent(0)), - map.data_handle(), - static_cast(map.extent(0)), - out.data_handle(), - handle.get_stream()); -} - -/** - * @brief gather copies rows from a source matrix into a destination matrix according to a - * transformed map. - * - * @tparam matrix_t Matrix type - * @tparam map_t Map vector type - * @tparam map_xform_t Unary lambda expression or operator type, MapTransformOp's result - * type must be convertible to idx_t (= int) type. - * @tparam idx_t integer type for indexing - * @param[in] handle raft handle for managing resources - * @param[in] in Input matrix (assumed to be row-major) - * @param[in] map Input vector of gather locations - * @param[out] out Output matrix (assumed to be row-major) - * @param[in] transform_op The transformation operation, transforms the map values to idx_t - */ -template -void gather(const raft::handle_t& handle, - raft::device_matrix_view in, - raft::device_vector_view map, - raft::device_matrix_view out, - map_xform_t transform_op) -{ - RAFT_EXPECTS(out.extent(0) == map.extent(0), - "Number of rows in output matrix must equal the size of the map vector"); - RAFT_EXPECTS(out.extent(1) == in.extent(1), - "Number of columns in input and output matrices must be equal."); - - detail::gather( - const_cast(in.data_handle()), // TODO: There's a better way to handle this - static_cast(in.extent(1)), - static_cast(in.extent(0)), - map, - static_cast(map.extent(0)), - out.data_handle(), - transform_op, - handle.get_stream()); -} - /** * @brief gather copies rows from a source matrix into a destination matrix according to a * transformed map. @@ -196,6 +131,122 @@ void gather_if(const MatrixIteratorT in, detail::gather_if(in, D, N, map, stencil, map_length, out, pred_op, stream); } +/** + * @brief gather_if conditionally copies rows from a source matrix into a destination matrix + * according to a transformed map. + * + * @tparam MatrixIteratorT Random-access iterator type, for reading input matrix (may be a + * simple pointer type). + * @tparam MapIteratorT Random-access iterator type, for reading input map (may be a simple + * pointer type). + * @tparam StencilIteratorT Random-access iterator type, for reading input stencil (may be a + * simple pointer type). + * @tparam UnaryPredicateOp Unary lambda expression or operator type, UnaryPredicateOp's result + * type must be convertible to bool type. + * @tparam MapTransformOp Unary lambda expression or operator type, MapTransformOp's result + * type must be convertible to IndexT (= int) type. + * + * @param in Pointer to the input matrix (assumed to be row-major) + * @param D Leading dimension of the input matrix 'in', which in-case of row-major + * storage is the number of columns + * @param N Second dimension + * @param map Pointer to the input sequence of gather locations + * @param stencil Pointer to the input sequence of stencil or predicate values + * @param map_length The length of 'map' and 'stencil' + * @param out Pointer to the output matrix (assumed to be row-major) + * @param pred_op Predicate to apply to the stencil values + * @param transform_op The transformation operation, transforms the map values to IndexT + * @param stream CUDA stream to launch kernels within + */ +template +void gather_if(const MatrixIteratorT in, + int D, + int N, + MapIteratorT map, + StencilIteratorT stencil, + int map_length, + MatrixIteratorT out, + UnaryPredicateOp pred_op, + MapTransformOp transform_op, + cudaStream_t stream) +{ + detail::gather_if(in, D, N, map, stencil, map_length, out, pred_op, transform_op, stream); +} + +/** + * @brief gather copies rows from a source matrix into a destination matrix according to a map. + * + * @tparam matrix_t Matrix element type + * @tparam map_t Map vector type + * @tparam idx_t integer type used for indexing + * @param[in] handle raft handle for managing resources + * @param[in] in Input matrix (assumed to be row-major) + * @param[in] map Vector of gather locations + * @param[out] out Output matrix (assumed to be row-major) + */ +template +void gather(const raft::handle_t& handle, + raft::device_matrix_view in, + raft::device_vector_view map, + raft::device_matrix_view out) +{ + RAFT_EXPECTS(out.extent(0) == map.extent(0), + "Number of rows in output matrix must equal the size of the map vector"); + RAFT_EXPECTS(out.extent(1) == in.extent(1), + "Number of columns in input and output matrices must be equal."); + + raft::matrix::detail::gather( + const_cast(in.data_handle()), // TODO: There's a better way to handle this + static_cast(in.extent(1)), + static_cast(in.extent(0)), + map.data_handle(), + static_cast(map.extent(0)), + out.data_handle(), + handle.get_stream()); +} + +/** + * @brief gather copies rows from a source matrix into a destination matrix according to a + * transformed map. + * + * @tparam matrix_t Matrix type + * @tparam map_t Map vector type + * @tparam map_xform_t Unary lambda expression or operator type, MapTransformOp's result + * type must be convertible to idx_t (= int) type. + * @tparam idx_t integer type for indexing + * @param[in] handle raft handle for managing resources + * @param[in] in Input matrix (assumed to be row-major) + * @param[in] map Input vector of gather locations + * @param[out] out Output matrix (assumed to be row-major) + * @param[in] transform_op The transformation operation, transforms the map values to idx_t + */ +template +void gather(const raft::handle_t& handle, + raft::device_matrix_view in, + raft::device_vector_view map, + raft::device_matrix_view out, + map_xform_t transform_op) +{ + RAFT_EXPECTS(out.extent(0) == map.extent(0), + "Number of rows in output matrix must equal the size of the map vector"); + RAFT_EXPECTS(out.extent(1) == in.extent(1), + "Number of columns in input and output matrices must be equal."); + + detail::gather( + const_cast(in.data_handle()), // TODO: There's a better way to handle this + static_cast(in.extent(1)), + static_cast(in.extent(0)), + map, + static_cast(map.extent(0)), + out.data_handle(), + transform_op, + handle.get_stream()); +} + /** * @brief gather_if conditionally copies rows from a source matrix into a destination matrix * according to a map. @@ -243,52 +294,6 @@ void gather_if(const raft::handle_t& handle, handle.get_stream()); } -/** - * @brief gather_if conditionally copies rows from a source matrix into a destination matrix - * according to a transformed map. - * - * @tparam MatrixIteratorT Random-access iterator type, for reading input matrix (may be a - * simple pointer type). - * @tparam MapIteratorT Random-access iterator type, for reading input map (may be a simple - * pointer type). - * @tparam StencilIteratorT Random-access iterator type, for reading input stencil (may be a - * simple pointer type). - * @tparam UnaryPredicateOp Unary lambda expression or operator type, UnaryPredicateOp's result - * type must be convertible to bool type. - * @tparam MapTransformOp Unary lambda expression or operator type, MapTransformOp's result - * type must be convertible to IndexT (= int) type. - * - * @param in Pointer to the input matrix (assumed to be row-major) - * @param D Leading dimension of the input matrix 'in', which in-case of row-major - * storage is the number of columns - * @param N Second dimension - * @param map Pointer to the input sequence of gather locations - * @param stencil Pointer to the input sequence of stencil or predicate values - * @param map_length The length of 'map' and 'stencil' - * @param out Pointer to the output matrix (assumed to be row-major) - * @param pred_op Predicate to apply to the stencil values - * @param transform_op The transformation operation, transforms the map values to IndexT - * @param stream CUDA stream to launch kernels within - */ -template -void gather_if(const MatrixIteratorT in, - int D, - int N, - MapIteratorT map, - StencilIteratorT stencil, - int map_length, - MatrixIteratorT out, - UnaryPredicateOp pred_op, - MapTransformOp transform_op, - cudaStream_t stream) -{ - detail::gather_if(in, D, N, map, stencil, map_length, out, pred_op, transform_op, stream); -} - /** * @brief gather_if conditionally copies rows from a source matrix into a destination matrix * according to a transformed map. @@ -342,4 +347,6 @@ void gather_if(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end of group matrix_gather + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/init.cuh b/cpp/include/raft/matrix/init.cuh index caee2555a9..faf65a96fd 100644 --- a/cpp/include/raft/matrix/init.cuh +++ b/cpp/include/raft/matrix/init.cuh @@ -22,6 +22,12 @@ #include namespace raft::matrix { + +/** + * @defgroup matrix_init Matrix initialization operations + * @{ + */ + /** * @brief set values to scalar in matrix * @tparam math_t data-type upon which the math operation will be performed @@ -63,4 +69,7 @@ void fill(const raft::handle_t& handle, detail::setValue( inout.data_handle(), inout.data_handle(), scalar, inout.size(), handle.get_stream()); } + +/** @} */ // end of group matrix_init + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/linewise_op.cuh b/cpp/include/raft/matrix/linewise_op.cuh index 77f70239ea..cd80b539c4 100644 --- a/cpp/include/raft/matrix/linewise_op.cuh +++ b/cpp/include/raft/matrix/linewise_op.cuh @@ -22,6 +22,11 @@ namespace raft::matrix { +/** + * @defgroup linewise_op Matrix Linewise Operations + * @{ + */ + /** * Run a function over matrix lines (rows or columns) with a variable number * row-vectors or column-vectors. @@ -115,4 +120,6 @@ void linewise_op(const raft::handle_t& handle, out, in, lineLen, nLines, alongLines, op, handle.get_stream(), vecs.data_handle()...); } +/** @} */ // end of group linewise_op + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/norm.cuh b/cpp/include/raft/matrix/norm.cuh index deb3657905..c37b3995d8 100644 --- a/cpp/include/raft/matrix/norm.cuh +++ b/cpp/include/raft/matrix/norm.cuh @@ -21,6 +21,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_norm Matrix Norm Operations + * @{ + */ + /** * @brief Get the L2/F-norm of a matrix * @param[in] handle: raft handle @@ -32,4 +37,7 @@ m_t l2_norm(const raft::handle_t& handle, raft::device_mdspan { return detail::getL2Norm(handle, in.data_handle(), in.size(), handle.get_stream()); } + +/** @} */ // end of group matrix_norm + } // namespace raft::matrix \ No newline at end of file diff --git a/cpp/include/raft/matrix/power.cuh b/cpp/include/raft/matrix/power.cuh index 4e2b3b7d72..2bdbd475ca 100644 --- a/cpp/include/raft/matrix/power.cuh +++ b/cpp/include/raft/matrix/power.cuh @@ -21,6 +21,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_power Matrix Power Operations + * @{ + */ + /** * @brief Power of every element in the input matrix * @tparam math_t type of matrix elements @@ -91,4 +96,6 @@ void power(const raft::handle_t& handle, detail::power(in.data_handle(), out.data_handle(), in.size(), handle.get_stream()); } +/** @} */ // end group matrix_power + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/print.cuh b/cpp/include/raft/matrix/print.cuh index 4d3a8ca938..935af8233b 100644 --- a/cpp/include/raft/matrix/print.cuh +++ b/cpp/include/raft/matrix/print.cuh @@ -24,6 +24,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_print Matrix print operations + * @{ + */ + /** * @brief Prints the data stored in GPU memory * @tparam m_t type of matrix elements @@ -44,4 +49,6 @@ void print(const raft::handle_t& handle, separators.vertical, handle.get_stream()); } + +/** @} */ // end group matrix_print } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/ratio.cuh b/cpp/include/raft/matrix/ratio.cuh index 7895ea972f..2e449698d5 100644 --- a/cpp/include/raft/matrix/ratio.cuh +++ b/cpp/include/raft/matrix/ratio.cuh @@ -21,6 +21,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_ratio Matrix ratio operations + * @{ + */ + /** * @brief ratio of every element over sum of input vector is calculated * @tparam math_t data-type upon which the math operation will be performed @@ -53,4 +58,7 @@ void ratio(const raft::handle_t& handle, raft::device_matrix_view struct slice_coordinates { idx_t row1; ///< row coordinate of the top-left point of the wanted area (0-based) @@ -68,4 +73,7 @@ void slice(const raft::handle_t& handle, coords.col2, handle.get_stream()); } + +/** @} */ // end group matrix_slice + } // namespace raft::matrix \ No newline at end of file diff --git a/cpp/include/raft/matrix/sqrt.cuh b/cpp/include/raft/matrix/sqrt.cuh index 302167480e..ca9b280773 100644 --- a/cpp/include/raft/matrix/sqrt.cuh +++ b/cpp/include/raft/matrix/sqrt.cuh @@ -23,6 +23,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_sqrt Matrix Square Root + * @{ + */ + /** * @brief Square root of every element in the input matrix * @tparam math_t data-type upon which the math operation will be performed @@ -102,4 +107,6 @@ void weighted_sqrt(const raft::handle_t& handle, inout.data_handle(), *(scalar.data_handle()), inout.size(), handle.get_stream(), set_neg_zero); } +/** @} */ // end group matrix_sqrt + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/threshold.cuh b/cpp/include/raft/matrix/threshold.cuh index 7540ceb3c6..5ac7136a26 100644 --- a/cpp/include/raft/matrix/threshold.cuh +++ b/cpp/include/raft/matrix/threshold.cuh @@ -21,6 +21,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_threshold Matrix thesholding + * @{ + */ + /** * @brief sets the small values to zero based on a defined threshold * @tparam math_t data-type upon which the math operation will be performed @@ -58,4 +63,7 @@ void zero_small_values(const raft::handle_t& handle, { detail::setSmallValuesZero(inout.data_handle(), inout.size(), handle.get_stream(), thres); } + +/** @} */ // end group matrix_threshold + } // namespace raft::matrix diff --git a/cpp/include/raft/matrix/triangular.cuh b/cpp/include/raft/matrix/triangular.cuh index fad3dd77af..7820af8b16 100644 --- a/cpp/include/raft/matrix/triangular.cuh +++ b/cpp/include/raft/matrix/triangular.cuh @@ -21,6 +21,11 @@ namespace raft::matrix { +/** + * @defgroup matrix_triangular Extract Matrix Triangles + * @{ + */ + /** * @brief Copy the upper triangular part of a matrix to another * @param[in] handle: raft handle @@ -38,4 +43,7 @@ void upper_triangular(const raft::handle_t& handle, detail::copyUpperTriangular( src.data_handle(), dst.data_handle(), src.extent(0), src.extent(1), handle.get_stream()); } + +/** @} */ // end group matrix_triangular + } // namespace raft::matrix \ No newline at end of file diff --git a/cpp/include/raft/neighbors/ann_types.hpp b/cpp/include/raft/neighbors/ann_types.hpp index 5c6fd52be9..5bf2062f2f 100644 --- a/cpp/include/raft/neighbors/ann_types.hpp +++ b/cpp/include/raft/neighbors/ann_types.hpp @@ -20,6 +20,11 @@ namespace raft::neighbors::ann { +/** + * @defgroup ann_types Approximate Nearest Neighbors Types + * @{ + */ + /** The base for approximate KNN index structures. */ struct index { }; @@ -44,4 +49,6 @@ struct index_params { struct search_params { }; +/** @} */ // end group ann_types + }; // namespace raft::neighbors::ann diff --git a/cpp/include/raft/neighbors/ball_cover.cuh b/cpp/include/raft/neighbors/ball_cover.cuh index 28ff8491b6..3818399e5f 100644 --- a/cpp/include/raft/neighbors/ball_cover.cuh +++ b/cpp/include/raft/neighbors/ball_cover.cuh @@ -20,14 +20,19 @@ #include -#include "ball_cover_types.hpp" #include +#include #include #include #include namespace raft::neighbors::ball_cover { +/** + * @defgroup random_ball_cover Random Ball Cover algorithm + * @{ + */ + /** * Builds and populates a previously unbuilt BallCoverIndex * @@ -73,6 +78,8 @@ void build_index(const raft::handle_t& handle, index.set_index_trained(); } +/** @} */ // end group random_ball_cover + /** * Performs a faster exact knn in metric spaces using the triangle * inequality with a number of landmark points to reduce the @@ -139,6 +146,11 @@ void all_knn_query(const raft::handle_t& handle, index.set_index_trained(); } +/** + * @ingroup random_ball_cover + * @{ + */ + /** * Performs a faster exact knn in metric spaces using the triangle * inequality with a number of landmark points to reduce the @@ -212,6 +224,8 @@ void all_knn_query(const raft::handle_t& handle, handle, index, k, inds.data_handle(), dists.data_handle(), perform_post_filtering, weight); } +/** @} */ + /** * Performs a faster exact knn in metric spaces using the triangle * inequality with a number of landmark points to reduce the @@ -281,6 +295,11 @@ void knn_query(const raft::handle_t& handle, } } +/** + * @ingroup random_ball_cover + * @{ + */ + /** * Performs a faster exact knn in metric spaces using the triangle * inequality with a number of landmark points to reduce the @@ -365,6 +384,8 @@ void knn_query(const raft::handle_t& handle, weight); } +/** @} */ + // TODO: implement functions for: // 4. rbc_eps_neigh() - given a populated index, perform query against different query array // 5. rbc_all_eps_neigh() - populate a BallCoverIndex and query against training data diff --git a/cpp/include/raft/neighbors/ball_cover_types.hpp b/cpp/include/raft/neighbors/ball_cover_types.hpp index f6e49ab5c4..1c5babbc4e 100644 --- a/cpp/include/raft/neighbors/ball_cover_types.hpp +++ b/cpp/include/raft/neighbors/ball_cover_types.hpp @@ -25,6 +25,11 @@ namespace raft::neighbors::ball_cover { +/** + * @ingroup random_ball_cover + * @{ + */ + /** * Stores raw index data points, sampled landmarks, the 1-nns of index points * to their closest landmarks, and the ball radii of each landmark. This @@ -158,4 +163,7 @@ class BallCoverIndex { protected: bool index_trained; }; + +/** @} */ + } // namespace raft::neighbors::ball_cover diff --git a/cpp/include/raft/neighbors/brute_force.cuh b/cpp/include/raft/neighbors/brute_force.cuh index 96cd5f11c5..8d94ffd9a7 100644 --- a/cpp/include/raft/neighbors/brute_force.cuh +++ b/cpp/include/raft/neighbors/brute_force.cuh @@ -24,6 +24,11 @@ namespace raft::neighbors::brute_force { +/** + * @defgroup brute_force_knn Brute-force K-Nearest Neighbors + * @{ + */ + /** * @brief Performs a k-select across several (contiguous) row-partitioned index/distance * matrices formatted like the following: @@ -269,4 +274,6 @@ void fused_l2_knn(const raft::handle_t& handle, metric); } +/** @} */ // end group brute_force_knn + } // namespace raft::neighbors::brute_force diff --git a/cpp/include/raft/neighbors/epsilon_neighborhood.cuh b/cpp/include/raft/neighbors/epsilon_neighborhood.cuh index 114216fc50..ee92222066 100644 --- a/cpp/include/raft/neighbors/epsilon_neighborhood.cuh +++ b/cpp/include/raft/neighbors/epsilon_neighborhood.cuh @@ -59,6 +59,11 @@ void epsUnexpL2SqNeighborhood(bool* adj, adj, vd, x, y, m, n, k, eps, stream); } +/** + * @defgroup epsilon_neighbors Epislon Neighborhood Operations + * @{ + */ + /** * @brief Computes epsilon neighborhood for the L2-Squared distance metric and given ball size. * The epsilon neighbors is represented by a dense boolean adjacency matrix of size m * n and @@ -110,6 +115,8 @@ void eps_neighbors_l2sq(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group epsilon_neighbors + } // namespace raft::neighbors::epsilon_neighborhood #endif \ No newline at end of file diff --git a/cpp/include/raft/neighbors/ivf_flat.cuh b/cpp/include/raft/neighbors/ivf_flat.cuh index 5317f406e1..e05f63ef61 100644 --- a/cpp/include/raft/neighbors/ivf_flat.cuh +++ b/cpp/include/raft/neighbors/ivf_flat.cuh @@ -16,7 +16,7 @@ #pragma once -#include "ivf_flat_types.hpp" +#include #include #include @@ -68,6 +68,11 @@ auto build( return raft::spatial::knn::ivf_flat::detail::build(handle, params, dataset, n_rows, dim); } +/** + * @defgroup ivf_flat IVF Flat Algorithm + * @{ + */ + /** * @brief Build the index from the dataset for efficient search. * @@ -112,6 +117,8 @@ auto build(const handle_t& handle, static_cast(dataset.extent(1))); } +/** @} */ + /** * @brief Build a new index containing the data of the original plus new extra vectors. * @@ -155,6 +162,11 @@ auto extend(const handle_t& handle, handle, orig_index, new_vectors, new_indices, n_rows); } +/** + * @ingroup ivf_flat + * @{ + */ + /** * @brief Build a new index containing the data of the original plus new extra vectors. * @@ -203,6 +215,8 @@ auto extend(const handle_t& handle, new_vectors.extent(0)); } +/** @} */ + /** * @brief Extend the index in-place with the new data. * @@ -239,6 +253,11 @@ void extend(const handle_t& handle, *index = extend(handle, *index, new_vectors, new_indices, n_rows); } +/** + * @ingroup ivf_flat + * @{ + */ + /** * @brief Extend the index in-place with the new data. * @@ -279,6 +298,8 @@ void extend(const handle_t& handle, static_cast(new_vectors.extent(0))); } +/** @} */ + /** * @brief Search ANN using the constructed index. * @@ -336,6 +357,11 @@ void search(const handle_t& handle, handle, params, index, queries, n_queries, k, neighbors, distances, mr); } +/** + * @ingroup ivf_flat + * @{ + */ + /** * @brief Search ANN using the constructed index. * @@ -402,4 +428,6 @@ void search(const handle_t& handle, nullptr); } +/** @} */ + } // namespace raft::neighbors::ivf_flat diff --git a/cpp/include/raft/neighbors/ivf_flat_types.hpp b/cpp/include/raft/neighbors/ivf_flat_types.hpp index 44b88a0b23..eea6ae256d 100644 --- a/cpp/include/raft/neighbors/ivf_flat_types.hpp +++ b/cpp/include/raft/neighbors/ivf_flat_types.hpp @@ -27,6 +27,10 @@ #include namespace raft::neighbors::ivf_flat { +/** + * @ingroup ivf_flat + * @{ + */ /** Size of the interleaved group (see `index::data` description). */ constexpr static uint32_t kIndexGroupSize = 32; @@ -301,4 +305,6 @@ struct index : ann::index { } }; +/** @} */ + } // namespace raft::neighbors::ivf_flat diff --git a/cpp/include/raft/neighbors/ivf_pq.cuh b/cpp/include/raft/neighbors/ivf_pq.cuh index 5b2035fadf..2296339a2a 100644 --- a/cpp/include/raft/neighbors/ivf_pq.cuh +++ b/cpp/include/raft/neighbors/ivf_pq.cuh @@ -16,7 +16,7 @@ #pragma once -#include "ivf_pq_types.hpp" +#include #include #include @@ -27,6 +27,11 @@ namespace raft::neighbors::ivf_pq { +/** + * @defgroup ivf_pq IVF PQ Algorithm + * @{ + */ + /** * @brief Build the index from the dataset for efficient search. * @@ -191,4 +196,6 @@ inline void search(const handle_t& handle, handle, params, index, queries, n_queries, k, neighbors, distances, mr); } +/** @} */ // end group ivf_pq + } // namespace raft::neighbors::ivf_pq diff --git a/cpp/include/raft/neighbors/ivf_pq_types.hpp b/cpp/include/raft/neighbors/ivf_pq_types.hpp index afb3eb6cd6..825e2902c3 100644 --- a/cpp/include/raft/neighbors/ivf_pq_types.hpp +++ b/cpp/include/raft/neighbors/ivf_pq_types.hpp @@ -29,6 +29,11 @@ namespace raft::neighbors::ivf_pq { +/** + * @ingroup ivf_pq + * @{ + */ + /** A type for specifying how PQ codebooks are created. */ enum class codebook_gen { // NOLINT PER_SUBSPACE = 0, // NOLINT @@ -497,4 +502,6 @@ struct index : ann::index { } }; +/** @} */ + } // namespace raft::neighbors::ivf_pq diff --git a/cpp/include/raft/neighbors/refine.cuh b/cpp/include/raft/neighbors/refine.cuh index 7b6708f18c..6f373c0a2f 100644 --- a/cpp/include/raft/neighbors/refine.cuh +++ b/cpp/include/raft/neighbors/refine.cuh @@ -25,6 +25,11 @@ namespace raft::neighbors { +/** + * @defgroup ann_refine Approximate Nearest Neighbors Refinement + * @{ + */ + /** * @brief Refine nearest neighbor search. * @@ -95,4 +100,6 @@ void refine(raft::handle_t const& handle, { detail::refine_host(dataset, queries, neighbor_candidates, indices, distances, metric); } + +/** @} */ // end group ann_refine } // namespace raft::neighbors diff --git a/cpp/include/raft/neighbors/specializations/ivf_pq_specialization.hpp b/cpp/include/raft/neighbors/specializations/ivf_pq_specialization.hpp deleted file mode 100644 index 2bce997e18..0000000000 --- a/cpp/include/raft/neighbors/specializations/ivf_pq_specialization.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2022, NVIDIA CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace raft::neighbors ::ivf_pq { - -#define RAFT_INST_SEARCH(T, IdxT) \ - void search(const handle_t&, \ - const search_params&, \ - const index&, \ - const T*, \ - uint32_t, \ - uint32_t, \ - IdxT*, \ - float*, \ - rmm::mr::device_memory_resource*); - -RAFT_INST_SEARCH(float, uint64_t); -RAFT_INST_SEARCH(int8_t, uint64_t); -RAFT_INST_SEARCH(uint8_t, uint64_t); - -#undef RAFT_INST_SEARCH - -// We define overloads for build and extend with void return type. This is used in the Cython -// wrappers, where exception handling is not compatible with return type that has nontrivial -// constructor. -#define RAFT_INST_BUILD_EXTEND(T, IdxT) \ - auto build(const handle_t& handle, \ - const index_params& params, \ - const T* dataset, \ - IdxT n_rows, \ - uint32_t dim) \ - ->index; \ - \ - auto extend(const handle_t& handle, \ - const index& orig_index, \ - const T* new_vectors, \ - const IdxT* new_indices, \ - IdxT n_rows) \ - ->index; \ - \ - void build(const handle_t& handle, \ - const index_params& params, \ - const T* dataset, \ - IdxT n_rows, \ - uint32_t dim, \ - index* idx); \ - \ - void extend(const handle_t& handle, \ - index* idx, \ - const T* new_vectors, \ - const IdxT* new_indices, \ - IdxT n_rows); - -RAFT_INST_BUILD_EXTEND(float, uint64_t) -RAFT_INST_BUILD_EXTEND(int8_t, uint64_t) -RAFT_INST_BUILD_EXTEND(uint8_t, uint64_t) - -#undef RAFT_INST_BUILD_EXTEND - -} // namespace raft::neighbors::ivf_pq diff --git a/cpp/include/raft/random/detail/multi_variable_gaussian.cuh b/cpp/include/raft/random/detail/multi_variable_gaussian.cuh index 5bed71f2f4..750ebf2ef1 100644 --- a/cpp/include/raft/random/detail/multi_variable_gaussian.cuh +++ b/cpp/include/raft/random/detail/multi_variable_gaussian.cuh @@ -444,5 +444,41 @@ void compute_multi_variable_gaussian_impl( compute_multi_variable_gaussian_impl(token, x, P, X); } +template +class multi_variable_gaussian : public detail::multi_variable_gaussian_impl { + public: + // using Decomposer = typename detail::multi_variable_gaussian_impl::Decomposer; + // using detail::multi_variable_gaussian_impl::Decomposer::chol_decomp; + // using detail::multi_variable_gaussian_impl::Decomposer::jacobi; + // using detail::multi_variable_gaussian_impl::Decomposer::qr; + + multi_variable_gaussian() = delete; + multi_variable_gaussian(const raft::handle_t& handle, + const int dim, + typename detail::multi_variable_gaussian_impl::Decomposer method) + : detail::multi_variable_gaussian_impl{handle, dim, method} + { + } + + std::size_t get_workspace_size() + { + return detail::multi_variable_gaussian_impl::get_workspace_size(); + } + + void set_workspace(T* workarea) + { + detail::multi_variable_gaussian_impl::set_workspace(workarea); + } + + void give_gaussian(const int nPoints, T* P, T* X, const T* x = 0) + { + detail::multi_variable_gaussian_impl::give_gaussian(nPoints, P, X, x); + } + + void deinit() { detail::multi_variable_gaussian_impl::deinit(); } + + ~multi_variable_gaussian() { deinit(); } +}; // end of multi_variable_gaussian + }; // end of namespace detail }; // end of namespace raft::random diff --git a/cpp/include/raft/random/make_blobs.cuh b/cpp/include/raft/random/make_blobs.cuh index 82c940b471..ff1a20f58a 100644 --- a/cpp/include/raft/random/make_blobs.cuh +++ b/cpp/include/raft/random/make_blobs.cuh @@ -93,6 +93,11 @@ void make_blobs(DataT* out, type); } +/** + * @defgroup make_blobs Generate Isotropic Gaussian Clusters + * @{ + */ + /** * @brief GPU-equivalent of sklearn.datasets.make_blobs * @@ -173,6 +178,9 @@ void make_blobs( seed, type); } + +/** @} */ // end group make_blobs + } // end namespace raft::random #endif \ No newline at end of file diff --git a/cpp/include/raft/random/make_regression.cuh b/cpp/include/raft/random/make_regression.cuh index c575ea987c..a92d5bb12f 100644 --- a/cpp/include/raft/random/make_regression.cuh +++ b/cpp/include/raft/random/make_regression.cuh @@ -102,6 +102,11 @@ void make_regression(const raft::handle_t& handle, type); } +/** + * @defgroup make_regression Generate Dataset for Regression Model + * @{ + */ + /** * @brief GPU-equivalent of sklearn.datasets.make_regression as documented at: * https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_regression.html @@ -177,6 +182,8 @@ void make_regression(const raft::handle_t& handle, type); } +/** @} */ // end group make_regression + } // namespace raft::random #endif diff --git a/cpp/include/raft/random/multi_variable_gaussian.cuh b/cpp/include/raft/random/multi_variable_gaussian.cuh index 6bee323007..37ea58c0fb 100644 --- a/cpp/include/raft/random/multi_variable_gaussian.cuh +++ b/cpp/include/raft/random/multi_variable_gaussian.cuh @@ -24,61 +24,28 @@ namespace raft::random { -template -class multi_variable_gaussian : public detail::multi_variable_gaussian_impl { - public: - // using Decomposer = typename detail::multi_variable_gaussian_impl::Decomposer; - // using detail::multi_variable_gaussian_impl::Decomposer::chol_decomp; - // using detail::multi_variable_gaussian_impl::Decomposer::jacobi; - // using detail::multi_variable_gaussian_impl::Decomposer::qr; - - multi_variable_gaussian() = delete; - multi_variable_gaussian(const raft::handle_t& handle, - const int dim, - typename detail::multi_variable_gaussian_impl::Decomposer method) - : detail::multi_variable_gaussian_impl{handle, dim, method} - { - } - - std::size_t get_workspace_size() - { - return detail::multi_variable_gaussian_impl::get_workspace_size(); - } - - void set_workspace(T* workarea) - { - detail::multi_variable_gaussian_impl::set_workspace(workarea); - } - - void give_gaussian(const int nPoints, T* P, T* X, const T* x = 0) - { - detail::multi_variable_gaussian_impl::give_gaussian(nPoints, P, X, x); - } - - void deinit() { detail::multi_variable_gaussian_impl::deinit(); } - - ~multi_variable_gaussian() { deinit(); } -}; // end of multi_variable_gaussian +/** + * \defgroup multi_variable_gaussian Compute multi-variable Gaussian + * @{ + */ template -void compute_multi_variable_gaussian( - const raft::handle_t& handle, - rmm::mr::device_memory_resource& mem_resource, - std::optional> x, - raft::device_matrix_view P, - raft::device_matrix_view X, - const multi_variable_gaussian_decomposition_method method) +void multi_variable_gaussian(const raft::handle_t& handle, + rmm::mr::device_memory_resource& mem_resource, + std::optional> x, + raft::device_matrix_view P, + raft::device_matrix_view X, + const multi_variable_gaussian_decomposition_method method) { detail::compute_multi_variable_gaussian_impl(handle, mem_resource, x, P, X, method); } template -void compute_multi_variable_gaussian( - const raft::handle_t& handle, - std::optional> x, - raft::device_matrix_view P, - raft::device_matrix_view X, - const multi_variable_gaussian_decomposition_method method) +void multi_variable_gaussian(const raft::handle_t& handle, + std::optional> x, + raft::device_matrix_view P, + raft::device_matrix_view X, + const multi_variable_gaussian_decomposition_method method) { rmm::mr::device_memory_resource* mem_resource_ptr = rmm::mr::get_current_device_resource(); RAFT_EXPECTS(mem_resource_ptr != nullptr, @@ -88,6 +55,8 @@ void compute_multi_variable_gaussian( detail::compute_multi_variable_gaussian_impl(handle, *mem_resource_ptr, x, P, X, method); } +/** @} */ + }; // end of namespace raft::random #endif diff --git a/cpp/include/raft/random/permute.cuh b/cpp/include/raft/random/permute.cuh index 17b103fab6..b532cb584d 100644 --- a/cpp/include/raft/random/permute.cuh +++ b/cpp/include/raft/random/permute.cuh @@ -28,6 +28,40 @@ namespace raft::random { +namespace permute_impl { + +template +struct perms_out_view { +}; + +template +struct perms_out_view { + // permsOut won't have a value anyway, + // so we can pick any integral value type we want. + using type = raft::device_vector_view; +}; + +template +struct perms_out_view>, + InputOutputValueType, + IdxType, + Layout> { + using type = raft::device_vector_view; +}; + +template +using perms_out_view_t = typename perms_out_view::type; + +} // namespace permute_impl + +/** + * \defgroup permute Permutation + * @{ + */ + /** * @brief Randomly permute the rows of the input matrix. * @@ -99,35 +133,6 @@ void permute(const raft::handle_t& handle, } } -namespace permute_impl { - -template -struct perms_out_view { -}; - -template -struct perms_out_view { - // permsOut won't have a value anyway, - // so we can pick any integral value type we want. - using type = raft::device_vector_view; -}; - -template -struct perms_out_view>, - InputOutputValueType, - IdxType, - Layout> { - using type = raft::device_vector_view; -}; - -template -using perms_out_view_t = typename perms_out_view::type; - -} // namespace permute_impl - /** * @brief Overload of `permute` that compiles if users pass in `std::nullopt` * for either or both of `permsOut` and `out`. @@ -160,6 +165,8 @@ void permute(const raft::handle_t& handle, permute(handle, in, permsOut_arg, out_arg); } +/** @} */ + /** * @brief Legacy overload of `permute` that takes raw arrays instead of mdspan. * diff --git a/cpp/include/raft/random/random_types.hpp b/cpp/include/raft/random/random_types.hpp index 96b55a4727..cd15c2f838 100644 --- a/cpp/include/raft/random/random_types.hpp +++ b/cpp/include/raft/random/random_types.hpp @@ -19,9 +19,14 @@ namespace raft::random { /** - * @brief Matrix decomposition method for `compute_multi_variable_gaussian` to use. + * \ingroup multi_variable_gaussian + * @{ + */ + +/** + * @brief Matrix decomposition method for `multi_variable_gaussian` to use. * - * `compute_multi_variable_gaussian` can use any of the following methods. + * `multi_variable_gaussian` can use any of the following methods. * * - `CHOLESKY`: Uses Cholesky decomposition on the normal equations. * This may be faster than the other two methods, but less accurate. @@ -36,4 +41,6 @@ namespace raft::random { */ enum class multi_variable_gaussian_decomposition_method { CHOLESKY, JACOBI, QR }; +/** @} */ + }; // end of namespace raft::random diff --git a/cpp/include/raft/random/rmat_rectangular_generator.cuh b/cpp/include/raft/random/rmat_rectangular_generator.cuh index cedcca1711..cd9acda999 100644 --- a/cpp/include/raft/random/rmat_rectangular_generator.cuh +++ b/cpp/include/raft/random/rmat_rectangular_generator.cuh @@ -20,6 +20,11 @@ namespace raft::random { +/** + * @defgroup rmat RMAT Rectangular Generator + * @{ + */ + /** * @brief Generate a bipartite RMAT graph for a rectangular adjacency matrix. * @@ -212,6 +217,8 @@ void rmat_rectangular_gen( detail::rmat_rectangular_gen_impl(handle, r, output, a, b, c, r_scale, c_scale); } +/** @} */ // end group rmat + /** * @brief Legacy overload of `rmat_rectangular_gen` * taking raw arrays instead of mdspan. diff --git a/cpp/include/raft/random/rng.cuh b/cpp/include/raft/random/rng.cuh index 504b01ebc3..9469c393f1 100644 --- a/cpp/include/raft/random/rng.cuh +++ b/cpp/include/raft/random/rng.cuh @@ -743,143 +743,6 @@ std::enable_if_t> discrete( handle.get_stream()); } -namespace sample_without_replacement_impl { -template -struct weight_alias { -}; - -template <> -struct weight_alias { - using type = double; -}; - -template -struct weight_alias>> { - using type = typename raft::device_vector_view::value_type; -}; - -template -using weight_t = typename weight_alias::type; -} // namespace sample_without_replacement_impl - -/** - * \defgroup sample_without_replacement Sampling without Replacement - * @{ - */ - -/** - * @brief Sample the input vector without replacement, optionally based on the - * input weight vector for each element in the array. - * - * The implementation is based on the `one-pass sampling` algorithm described in - * ["Accelerating weighted random sampling without - * replacement,"](https://www.ethz.ch/content/dam/ethz/special-interest/baug/ivt/ivt-dam/vpl/reports/1101-1200/ab1141.pdf) - * a technical report by Kirill Mueller. - * - * If no input weight vector is provided, then input elements will be - * sampled uniformly. Otherwise, the elements sampled from the input - * vector will always appear in increasing order of their weights as - * computed using the exponential distribution. So, if you are - * particular about the order (for e.g., array permutations), then - * this might not be the right choice. - * - * @tparam DataT type of each element of the input array @c in - * @tparam IdxT type of the dimensions of the arrays; output index type - * @tparam WeightsVectorType std::optional> of - * each elements of the weights array @c weights_opt - * @tparam OutIndexVectorType std::optional> of output indices - * @c outIdx_opt - * - * @note Please do not specify template parameters explicitly, - * as the compiler can deduce them from the arguments. - * - * @param[in] handle RAFT handle containing (among other resources) - * the CUDA stream on which to run. - * @param[inout] rng_state Pseudorandom number generator state. - * @param[in] in Input vector to be sampled. - * @param[in] weights_opt std::optional weights vector. - * If not provided, uniform sampling will be used. - * @param[out] out Vector of samples from the input vector. - * @param[out] outIdx_opt std::optional vector of the indices - * sampled from the input array. - * - * @pre The number of samples `out.extent(0)` - * is less than or equal to the number of inputs `in.extent(0)`. - * - * @pre The number of weights `wts.extent(0)` - * equals the number of inputs `in.extent(0)`. - */ -template -void sample_without_replacement(const raft::handle_t& handle, - RngState& rng_state, - raft::device_vector_view in, - WeightsVectorType&& weights_opt, - raft::device_vector_view out, - OutIndexVectorType&& outIdx_opt) -{ - using weight_type = sample_without_replacement_impl::weight_t< - std::remove_const_t>>; - - std::optional> wts = - std::forward(weights_opt); - std::optional> outIdx = - std::forward(outIdx_opt); - - static_assert(std::is_integral::value, "IdxT must be an integral type."); - const IdxT sampledLen = out.extent(0); - const IdxT len = in.extent(0); - RAFT_EXPECTS(sampledLen <= len, - "sampleWithoutReplacement: " - "sampledLen (out.extent(0)) must be <= len (in.extent(0))"); - RAFT_EXPECTS(len == 0 || in.data_handle() != nullptr, - "sampleWithoutReplacement: " - "If in.extents(0) != 0, then in.data_handle() must be nonnull"); - RAFT_EXPECTS(sampledLen == 0 || out.data_handle() != nullptr, - "sampleWithoutReplacement: " - "If out.extents(0) != 0, then out.data_handle() must be nonnull"); - - const bool outIdx_has_value = outIdx.has_value(); - if (outIdx_has_value) { - RAFT_EXPECTS((*outIdx).extent(0) == sampledLen, - "sampleWithoutReplacement: " - "If outIdx is provided, its extent(0) must equal out.extent(0)"); - } - IdxT* outIdx_ptr = outIdx_has_value ? (*outIdx).data_handle() : nullptr; - - const bool wts_has_value = wts.has_value(); - if (wts_has_value) { - RAFT_EXPECTS((*wts).extent(0) == len, - "sampleWithoutReplacement: " - "If wts is provided, its extent(0) must equal in.extent(0)"); - } - const weight_type* wts_ptr = wts_has_value ? (*wts).data_handle() : nullptr; - - detail::sampleWithoutReplacement(rng_state, - out.data_handle(), - outIdx_ptr, - in.data_handle(), - wts_ptr, - sampledLen, - len, - handle.get_stream()); -} - -/** - * @brief Overload of `sample_without_replacement` to help the - * compiler find the above overload, in case users pass in - * `std::nullopt` for one or both of the optional arguments. - * - * - * Please see above for documentation of `sample_without_replacement`. - */ -template > -void sample_without_replacement(Args... args) -{ - sample_without_replacement(std::forward(args)..., std::nullopt); -} - -/** @} */ - /** * @brief Legacy version of @c sample_without_replacement (see above) * that takes raw arrays instead of device mdspan. diff --git a/cpp/include/raft/random/sample_without_replacement.cuh b/cpp/include/raft/random/sample_without_replacement.cuh new file mode 100644 index 0000000000..e4428c28d6 --- /dev/null +++ b/cpp/include/raft/random/sample_without_replacement.cuh @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2018-2022, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "detail/rng_impl.cuh" +#include "rng_state.hpp" +#include +#include +#include +#include +#include +#include + +namespace raft::random { + +namespace sample_without_replacement_impl { +template +struct weight_alias { +}; + +template <> +struct weight_alias { + using type = double; +}; + +template +struct weight_alias>> { + using type = typename raft::device_vector_view::value_type; +}; + +template +using weight_t = typename weight_alias::type; +} // namespace sample_without_replacement_impl + +/** + * \defgroup sample_without_replacement Sampling without Replacement + * @{ + */ + +/** + * @brief Sample the input vector without replacement, optionally based on the + * input weight vector for each element in the array. + * + * The implementation is based on the `one-pass sampling` algorithm described in + * ["Accelerating weighted random sampling without + * replacement,"](https://www.ethz.ch/content/dam/ethz/special-interest/baug/ivt/ivt-dam/vpl/reports/1101-1200/ab1141.pdf) + * a technical report by Kirill Mueller. + * + * If no input weight vector is provided, then input elements will be + * sampled uniformly. Otherwise, the elements sampled from the input + * vector will always appear in increasing order of their weights as + * computed using the exponential distribution. So, if you are + * particular about the order (for e.g., array permutations), then + * this might not be the right choice. + * + * @tparam DataT type of each element of the input array @c in + * @tparam IdxT type of the dimensions of the arrays; output index type + * @tparam WeightsVectorType std::optional> of + * each elements of the weights array @c weights_opt + * @tparam OutIndexVectorType std::optional> of output indices + * @c outIdx_opt + * + * @note Please do not specify template parameters explicitly, + * as the compiler can deduce them from the arguments. + * + * @param[in] handle RAFT handle containing (among other resources) + * the CUDA stream on which to run. + * @param[inout] rng_state Pseudorandom number generator state. + * @param[in] in Input vector to be sampled. + * @param[in] weights_opt std::optional weights vector. + * If not provided, uniform sampling will be used. + * @param[out] out Vector of samples from the input vector. + * @param[out] outIdx_opt std::optional vector of the indices + * sampled from the input array. + * + * @pre The number of samples `out.extent(0)` + * is less than or equal to the number of inputs `in.extent(0)`. + * + * @pre The number of weights `wts.extent(0)` + * equals the number of inputs `in.extent(0)`. + */ +template +void sample_without_replacement(const raft::handle_t& handle, + RngState& rng_state, + raft::device_vector_view in, + WeightsVectorType&& weights_opt, + raft::device_vector_view out, + OutIndexVectorType&& outIdx_opt) +{ + using weight_type = sample_without_replacement_impl::weight_t< + std::remove_const_t>>; + + std::optional> wts = + std::forward(weights_opt); + std::optional> outIdx = + std::forward(outIdx_opt); + + static_assert(std::is_integral::value, "IdxT must be an integral type."); + const IdxT sampledLen = out.extent(0); + const IdxT len = in.extent(0); + RAFT_EXPECTS(sampledLen <= len, + "sampleWithoutReplacement: " + "sampledLen (out.extent(0)) must be <= len (in.extent(0))"); + RAFT_EXPECTS(len == 0 || in.data_handle() != nullptr, + "sampleWithoutReplacement: " + "If in.extents(0) != 0, then in.data_handle() must be nonnull"); + RAFT_EXPECTS(sampledLen == 0 || out.data_handle() != nullptr, + "sampleWithoutReplacement: " + "If out.extents(0) != 0, then out.data_handle() must be nonnull"); + + const bool outIdx_has_value = outIdx.has_value(); + if (outIdx_has_value) { + RAFT_EXPECTS((*outIdx).extent(0) == sampledLen, + "sampleWithoutReplacement: " + "If outIdx is provided, its extent(0) must equal out.extent(0)"); + } + IdxT* outIdx_ptr = outIdx_has_value ? (*outIdx).data_handle() : nullptr; + + const bool wts_has_value = wts.has_value(); + if (wts_has_value) { + RAFT_EXPECTS((*wts).extent(0) == len, + "sampleWithoutReplacement: " + "If wts is provided, its extent(0) must equal in.extent(0)"); + } + const weight_type* wts_ptr = wts_has_value ? (*wts).data_handle() : nullptr; + + detail::sampleWithoutReplacement(rng_state, + out.data_handle(), + outIdx_ptr, + in.data_handle(), + wts_ptr, + sampledLen, + len, + handle.get_stream()); +} + +/** + * @brief Overload of `sample_without_replacement` to help the + * compiler find the above overload, in case users pass in + * `std::nullopt` for one or both of the optional arguments. + * + * + * Please see above for documentation of `sample_without_replacement`. + */ +template > +void sample_without_replacement(Args... args) +{ + sample_without_replacement(std::forward(args)..., std::nullopt); +} + +/** @} */ + +} // end namespace raft::random \ No newline at end of file diff --git a/cpp/include/raft/stats/accuracy.cuh b/cpp/include/raft/stats/accuracy.cuh index 37cdc280f9..3bd0d40091 100644 --- a/cpp/include/raft/stats/accuracy.cuh +++ b/cpp/include/raft/stats/accuracy.cuh @@ -40,6 +40,11 @@ float accuracy(const math_t* predictions, const math_t* ref_predictions, int n, return detail::accuracy_score(predictions, ref_predictions, n, stream); } +/** + * @defgroup stats_accuracy Accuracy Score + * @{ + */ + /** * @brief Compute accuracy of predictions. Useful for classification. * @tparam value_t: data type for predictions (e.g., int for classification) @@ -63,6 +68,9 @@ float accuracy(const raft::handle_t& handle, predictions.extent(0), handle.get_stream()); } + +/** @} */ // end group stats_accuracy + } // namespace stats } // namespace raft diff --git a/cpp/include/raft/stats/adjusted_rand_index.cuh b/cpp/include/raft/stats/adjusted_rand_index.cuh index 93fd07eb0b..402071f498 100644 --- a/cpp/include/raft/stats/adjusted_rand_index.cuh +++ b/cpp/include/raft/stats/adjusted_rand_index.cuh @@ -49,6 +49,11 @@ double adjusted_rand_index(const T* firstClusterArray, return detail::compute_adjusted_rand_index(firstClusterArray, secondClusterArray, size, stream); } +/** + * @defgroup stats_adj_rand_index Adjusted Rand Index + * @{ + */ + /** * @brief Function to calculate Adjusted RandIndex * @see https://en.wikipedia.org/wiki/Rand_index @@ -75,6 +80,8 @@ double adjusted_rand_index(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_adj_rand_index + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/completeness_score.cuh b/cpp/include/raft/stats/completeness_score.cuh index fd535e77d5..a39315dc7a 100644 --- a/cpp/include/raft/stats/completeness_score.cuh +++ b/cpp/include/raft/stats/completeness_score.cuh @@ -47,6 +47,11 @@ double completeness_score(const T* truthClusterArray, predClusterArray, truthClusterArray, size, lower_label_range, upper_label_range, stream); } +/** + * @defgroup stats_completeness Completeness Score + * @{ + */ + /** * @brief Function to calculate the completeness score between two clusters * @@ -77,6 +82,8 @@ double completeness_score(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_completeness + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/contingency_matrix.cuh b/cpp/include/raft/stats/contingency_matrix.cuh index f36d95daff..ecf9c744ee 100644 --- a/cpp/include/raft/stats/contingency_matrix.cuh +++ b/cpp/include/raft/stats/contingency_matrix.cuh @@ -44,31 +44,6 @@ void getInputClassCardinality( detail::getInputClassCardinality(groundTruth, nSamples, stream, minLabel, maxLabel); } -/** - * @brief use this to allocate output matrix size - * size of matrix = (maxLabel - minLabel + 1)^2 * sizeof(int) - * @tparam value_t label type - * @tparam idx_t Index type of matrix extent. - * @param[in] handle: the raft handle. - * @param[in] groundTruth: device 1-d array for ground truth (num of rows) - * @param[out] minLabel: calculated min value in input array - * @param[out] maxLabel: calculated max value in input array - */ -template -void get_input_class_cardinality(const raft::handle_t& handle, - raft::device_vector_view groundTruth, - raft::host_scalar_view minLabel, - raft::host_scalar_view maxLabel) -{ - RAFT_EXPECTS(minLabel.data_handle() != nullptr, "Invalid minLabel pointer"); - RAFT_EXPECTS(maxLabel.data_handle() != nullptr, "Invalid maxLabel pointer"); - detail::getInputClassCardinality(groundTruth.data_handle(), - groundTruth.extent(0), - handle.get_stream(), - *minLabel.data_handle(), - *maxLabel.data_handle()); -} - /** * @brief Calculate workspace size for running contingency matrix calculations * @tparam T label type @@ -129,6 +104,36 @@ void contingencyMatrix(const T* groundTruth, maxLabel); } +/** + * @defgroup contingency_matrix Contingency Matrix + * @{ + */ + +/** + * @brief use this to allocate output matrix size + * size of matrix = (maxLabel - minLabel + 1)^2 * sizeof(int) + * @tparam value_t label type + * @tparam idx_t Index type of matrix extent. + * @param[in] handle: the raft handle. + * @param[in] groundTruth: device 1-d array for ground truth (num of rows) + * @param[out] minLabel: calculated min value in input array + * @param[out] maxLabel: calculated max value in input array + */ +template +void get_input_class_cardinality(const raft::handle_t& handle, + raft::device_vector_view groundTruth, + raft::host_scalar_view minLabel, + raft::host_scalar_view maxLabel) +{ + RAFT_EXPECTS(minLabel.data_handle() != nullptr, "Invalid minLabel pointer"); + RAFT_EXPECTS(maxLabel.data_handle() != nullptr, "Invalid maxLabel pointer"); + detail::getInputClassCardinality(groundTruth.data_handle(), + groundTruth.extent(0), + handle.get_stream(), + *minLabel.data_handle(), + *maxLabel.data_handle()); +} + /** * @brief construct contingency matrix given input ground truth and prediction * labels. Users should call function getInputClassCardinality to find @@ -191,6 +196,8 @@ void contingency_matrix(const raft::handle_t& handle, max_label_value); } +/** @} */ // end group contingency_matrix + /** * @brief Overload of `contingency_matrix` to help the * compiler find the above overload, in case users pass in diff --git a/cpp/include/raft/stats/cov.cuh b/cpp/include/raft/stats/cov.cuh index a0c2ed2090..9829564a5a 100644 --- a/cpp/include/raft/stats/cov.cuh +++ b/cpp/include/raft/stats/cov.cuh @@ -59,6 +59,11 @@ void cov(const raft::handle_t& handle, detail::cov(handle, covar, data, mu, D, N, sample, rowMajor, stable, stream); } +/** + * @defgroup stats_cov Covariance Matrix Construction + * @{ + */ + /** * @brief Compute covariance of the input matrix * @@ -107,6 +112,9 @@ void cov(const raft::handle_t& handle, stable, handle.get_stream()); } + +/** @} */ // end group stats_cov + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/dispersion.cuh b/cpp/include/raft/stats/dispersion.cuh index 9f995e4d5a..3e4b2d7d50 100644 --- a/cpp/include/raft/stats/dispersion.cuh +++ b/cpp/include/raft/stats/dispersion.cuh @@ -57,6 +57,11 @@ DataT dispersion(const DataT* centroids, centroids, clusterSizes, globalCentroid, nClusters, nPoints, dim, stream); } +/** + * @defgroup stats_cluster_dispersion Cluster Dispersion Metric + * @{ + */ + /** * @brief Compute cluster dispersion metric. This is very useful for * automatically finding the 'k' (in kmeans) that improves this metric. @@ -101,6 +106,8 @@ value_t cluster_dispersion( handle.get_stream()); } +/** @} */ // end group stats_cluster_dispersion + /** * @brief Overload of `cluster_dispersion` to help the * compiler find the above overload, in case users pass in diff --git a/cpp/include/raft/stats/entropy.cuh b/cpp/include/raft/stats/entropy.cuh index 8a98a03c6b..60836c8782 100644 --- a/cpp/include/raft/stats/entropy.cuh +++ b/cpp/include/raft/stats/entropy.cuh @@ -46,6 +46,11 @@ double entropy(const T* clusterArray, return detail::entropy(clusterArray, size, lowerLabelRange, upperLabelRange, stream); } +/** + * @defgroup stats_entropy Entropy + * @{ + */ + /** * @brief Function to calculate entropy * more info on entropy @@ -71,6 +76,9 @@ double entropy(const raft::handle_t& handle, upper_label_range, handle.get_stream()); } + +/** @} */ // end group stats_entropy + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/histogram.cuh b/cpp/include/raft/stats/histogram.cuh index 4ad5de0926..79fa881070 100644 --- a/cpp/include/raft/stats/histogram.cuh +++ b/cpp/include/raft/stats/histogram.cuh @@ -70,6 +70,11 @@ void histogram(HistType type, detail::histogram(type, bins, nbins, data, nrows, ncols, stream, binner); } +/** + * @defgroup stats_histogram Histogram + * @{ + */ + /** * @brief Perform histogram on the input data. It chooses the right load size * based on the input data vector length. It also supports large-bin cases @@ -106,6 +111,9 @@ void histogram(const raft::handle_t& handle, handle.get_stream(), binner); } + +/** @} */ // end group stats_histogram + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/homogeneity_score.cuh b/cpp/include/raft/stats/homogeneity_score.cuh index 91c479bc99..e1b627f8f1 100644 --- a/cpp/include/raft/stats/homogeneity_score.cuh +++ b/cpp/include/raft/stats/homogeneity_score.cuh @@ -48,6 +48,11 @@ double homogeneity_score(const T* truthClusterArray, truthClusterArray, predClusterArray, size, lowerLabelRange, upperLabelRange, stream); } +/** + * @defgroup stats_homogeneity_score Homogeneity Score + * @{ + */ + /** * @brief Function to calculate the homogeneity score between two clusters * more info on mutual @@ -79,6 +84,9 @@ double homogeneity_score(const raft::handle_t& handle, upper_label_range, handle.get_stream()); } + +/** @} */ // end group stats_homogeneity_score + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/information_criterion.cuh b/cpp/include/raft/stats/information_criterion.cuh index 0edeed7f0b..bddd603d01 100644 --- a/cpp/include/raft/stats/information_criterion.cuh +++ b/cpp/include/raft/stats/information_criterion.cuh @@ -65,11 +65,20 @@ void information_criterion_batched(ScalarT* d_ic, d_ic, d_loglikelihood, ic_type, n_params, batch_size, n_samples, stream); } +/** + * @defgroup stats_information_criterion Information Criterion + * @{ + */ + /** * Compute the given type of information criterion * * @note: it is safe to do the computation in-place (i.e give same pointer * as input and output) + * See: + * - AIC: https://en.wikipedia.org/wiki/Akaike_information_criterion + * - AICc: https://en.wikipedia.org/wiki/Akaike_information_criterion#AICc + * - BIC: https://en.wikipedia.org/wiki/Bayesian_information_criterion * * @tparam value_t data type * @tparam idx_t index type @@ -101,6 +110,8 @@ void information_criterion_batched(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_information_criterion + } // namespace stats } // namespace raft #endif diff --git a/cpp/include/raft/stats/kl_divergence.cuh b/cpp/include/raft/stats/kl_divergence.cuh index 265e87dc68..e969af7633 100644 --- a/cpp/include/raft/stats/kl_divergence.cuh +++ b/cpp/include/raft/stats/kl_divergence.cuh @@ -42,6 +42,11 @@ DataT kl_divergence(const DataT* modelPDF, const DataT* candidatePDF, int size, return detail::kl_divergence(modelPDF, candidatePDF, size, stream); } +/** + * @defgroup kl_divergence Kullback-Leibler Divergence + * @{ + */ + /** * @brief Function to calculate KL Divergence * more info on KL @@ -66,6 +71,8 @@ value_t kl_divergence(const raft::handle_t& handle, modelPDF.data_handle(), candidatePDF.data_handle(), modelPDF.extent(0), handle.get_stream()); } +/** @} */ // end group kl_divergence + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/mean.cuh b/cpp/include/raft/stats/mean.cuh index 5a39e29a8c..c944247b33 100644 --- a/cpp/include/raft/stats/mean.cuh +++ b/cpp/include/raft/stats/mean.cuh @@ -50,6 +50,11 @@ void mean( detail::mean(mu, data, D, N, sample, rowMajor, stream); } +/** + * @defgroup stats_mean Mean + * @{ + */ + /** * @brief Compute mean of the input matrix * @@ -85,6 +90,8 @@ void mean(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_mean + }; // namespace stats }; // namespace raft diff --git a/cpp/include/raft/stats/mean_center.cuh b/cpp/include/raft/stats/mean_center.cuh index 9f49ff8be2..b33b1bf507 100644 --- a/cpp/include/raft/stats/mean_center.cuh +++ b/cpp/include/raft/stats/mean_center.cuh @@ -52,6 +52,38 @@ void meanCenter(Type* out, detail::meanCenter(out, data, mu, D, N, rowMajor, bcastAlongRows, stream); } +/** + * @brief Add the input matrix wrt its mean + * @tparam Type the data type + * @tparam IdxType Integer type used to for addressing + * @tparam TPB threads per block of the cuda kernel launched + * @param out the output mean-added matrix + * @param data input matrix + * @param mu the mean vector + * @param D number of columns of data + * @param N number of rows of data + * @param rowMajor whether input is row or col major + * @param bcastAlongRows whether to broadcast vector along rows or columns + * @param stream cuda stream where to launch work + */ +template +void meanAdd(Type* out, + const Type* data, + const Type* mu, + IdxType D, + IdxType N, + bool rowMajor, + bool bcastAlongRows, + cudaStream_t stream) +{ + detail::meanAdd(out, data, mu, D, N, rowMajor, bcastAlongRows, stream); +} + +/** + * @defgroup stats_mean_center Mean Center + * @{ + */ + /** * @brief Center the input matrix wrt its mean * @tparam value_t the data type @@ -88,33 +120,6 @@ void mean_center(const raft::handle_t& handle, handle.get_stream()); } -/** - * @brief Add the input matrix wrt its mean - * @tparam Type the data type - * @tparam IdxType Integer type used to for addressing - * @tparam TPB threads per block of the cuda kernel launched - * @param out the output mean-added matrix - * @param data input matrix - * @param mu the mean vector - * @param D number of columns of data - * @param N number of rows of data - * @param rowMajor whether input is row or col major - * @param bcastAlongRows whether to broadcast vector along rows or columns - * @param stream cuda stream where to launch work - */ -template -void meanAdd(Type* out, - const Type* data, - const Type* mu, - IdxType D, - IdxType N, - bool rowMajor, - bool bcastAlongRows, - cudaStream_t stream) -{ - detail::meanAdd(out, data, mu, D, N, rowMajor, bcastAlongRows, stream); -} - /** * @brief Add the input matrix wrt its mean * @tparam Type the data type @@ -151,6 +156,9 @@ void mean_add(const raft::handle_t& handle, bcast_along_rows, handle.get_stream()); } + +/** @} */ // end group stats_mean_center + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/meanvar.cuh b/cpp/include/raft/stats/meanvar.cuh index fab2184637..b839ae7b72 100644 --- a/cpp/include/raft/stats/meanvar.cuh +++ b/cpp/include/raft/stats/meanvar.cuh @@ -56,6 +56,11 @@ void meanvar(Type* mean, detail::meanvar(mean, var, data, D, N, sample, rowMajor, stream); } +/** + * @defgroup stats_mean_var Mean and Variance + * @{ + */ + /** * @brief Compute mean and variance for each column of a given matrix. * @@ -99,6 +104,8 @@ void meanvar(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_mean_var + }; // namespace raft::stats #endif diff --git a/cpp/include/raft/stats/minmax.cuh b/cpp/include/raft/stats/minmax.cuh index a3cbec08fe..24e432e8da 100644 --- a/cpp/include/raft/stats/minmax.cuh +++ b/cpp/include/raft/stats/minmax.cuh @@ -70,6 +70,11 @@ void minmax(const T* data, data, rowids, colids, nrows, ncols, row_stride, globalmin, globalmax, sampledcols, stream); } +/** + * @defgroup stats_minmax Min/Max + * @{ + */ + /** * @brief Computes min/max across every column of the input matrix, as well as * optionally allow to subsample based on the given row/col ID mapping vectors @@ -131,6 +136,8 @@ void minmax(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_minmax + }; // namespace stats }; // namespace raft #endif \ No newline at end of file diff --git a/cpp/include/raft/stats/mutual_info_score.cuh b/cpp/include/raft/stats/mutual_info_score.cuh index 6c7f588050..8158c4020a 100644 --- a/cpp/include/raft/stats/mutual_info_score.cuh +++ b/cpp/include/raft/stats/mutual_info_score.cuh @@ -47,6 +47,11 @@ double mutual_info_score(const T* firstClusterArray, firstClusterArray, secondClusterArray, size, lowerLabelRange, upperLabelRange, stream); } +/** + * @defgroup stats_mutual_info Mutual Information + * @{ + */ + /** * @brief Function to calculate the mutual information between two clusters * more info on mutual information @@ -77,6 +82,9 @@ double mutual_info_score(const raft::handle_t& handle, upper_label_range, handle.get_stream()); } + +/** @} */ // end group stats_mutual_info + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/r2_score.cuh b/cpp/include/raft/stats/r2_score.cuh index 5b14c901de..5e867b64a1 100644 --- a/cpp/include/raft/stats/r2_score.cuh +++ b/cpp/include/raft/stats/r2_score.cuh @@ -46,6 +46,11 @@ math_t r2_score(math_t* y, math_t* y_hat, int n, cudaStream_t stream) return detail::r2_score(y, y_hat, n, stream); } +/** + * @defgroup stats_r2_score Regression R2 Score + * @{ + */ + /** * Calculates the "Coefficient of Determination" (R-Squared) score * normalizing the sum of squared errors by the total sum of squares. @@ -79,6 +84,8 @@ value_t r2_score(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_r2_score + } // namespace stats } // namespace raft diff --git a/cpp/include/raft/stats/rand_index.cuh b/cpp/include/raft/stats/rand_index.cuh index 70384412a8..09dc874d93 100644 --- a/cpp/include/raft/stats/rand_index.cuh +++ b/cpp/include/raft/stats/rand_index.cuh @@ -39,6 +39,11 @@ double rand_index(T* firstClusterArray, T* secondClusterArray, uint64_t size, cu return detail::compute_rand_index(firstClusterArray, secondClusterArray, size, stream); } +/** + * @defgroup stats_rand_index Rand Index + * @{ + */ + /** * @brief Function to calculate RandIndex * more info on rand index @@ -63,6 +68,9 @@ double rand_index(const raft::handle_t& handle, second_cluster_array.extent(0), handle.get_stream()); } + +/** @} */ // end group stats_rand_index + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/regression_metrics.cuh b/cpp/include/raft/stats/regression_metrics.cuh index 268440892c..c45e3be870 100644 --- a/cpp/include/raft/stats/regression_metrics.cuh +++ b/cpp/include/raft/stats/regression_metrics.cuh @@ -53,6 +53,11 @@ void regression_metrics(const T* predictions, predictions, ref_predictions, n, stream, mean_abs_error, mean_squared_error, median_abs_error); } +/** + * @defgroup stats_regression_metrics Regression Metrics + * @{ + */ + /** * @brief Compute regression metrics mean absolute error, mean squared error, median absolute error * @tparam value_t the data type for predictions (e.g., float or double for regression). @@ -92,6 +97,9 @@ void regression_metrics(const raft::handle_t& handle, *mean_squared_error.data_handle(), *median_abs_error.data_handle()); } + +/** @} */ // end group stats_regression_metrics + } // namespace stats } // namespace raft diff --git a/cpp/include/raft/stats/silhouette_score.cuh b/cpp/include/raft/stats/silhouette_score.cuh index fafddb7b23..0763cdfe1c 100644 --- a/cpp/include/raft/stats/silhouette_score.cuh +++ b/cpp/include/raft/stats/silhouette_score.cuh @@ -74,6 +74,11 @@ value_t silhouette_score_batched( handle, X, n_rows, n_cols, y, n_labels, scores, chunk, metric); } +/** + * @defgroup stats_silhouette_score Silhouette Score + * @{ + */ + /** * @brief main function that returns the average silhouette score for a given set of data and its * clusterings @@ -119,26 +124,6 @@ value_t silhouette_score( metric); } -/** - * @brief Overload of `silhouette_score` to help the - * compiler find the above overload, in case users pass in - * `std::nullopt` for the optional arguments. - * - * Please see above for documentation of `silhouette_score`. - */ -template -value_t silhouette_score( - const raft::handle_t& handle, - raft::device_matrix_view X_in, - raft::device_vector_view labels, - std::nullopt_t silhouette_score_per_sample, - idx_t n_unique_labels, - raft::distance::DistanceType metric = raft::distance::DistanceType::L2Unexpanded) -{ - std::optional> opt_scores = silhouette_score_per_sample; - return silhouette_score(handle, X_in, labels, opt_scores, n_unique_labels, metric); -} - /** * @brief function that returns the average silhouette score for a given set of data and its * clusterings @@ -191,6 +176,28 @@ value_t silhouette_score_batched( metric); } +/** @} */ // end group stats_silhouette_score + +/** + * @brief Overload of `silhouette_score` to help the + * compiler find the above overload, in case users pass in + * `std::nullopt` for the optional arguments. + * + * Please see above for documentation of `silhouette_score`. + */ +template +value_t silhouette_score( + const raft::handle_t& handle, + raft::device_matrix_view X_in, + raft::device_vector_view labels, + std::nullopt_t silhouette_score_per_sample, + idx_t n_unique_labels, + raft::distance::DistanceType metric = raft::distance::DistanceType::L2Unexpanded) +{ + std::optional> opt_scores = silhouette_score_per_sample; + return silhouette_score(handle, X_in, labels, opt_scores, n_unique_labels, metric); +} + /** * @brief Overload of `silhouette_score_batched` to help the * compiler find the above overload, in case users pass in diff --git a/cpp/include/raft/stats/stats_types.hpp b/cpp/include/raft/stats/stats_types.hpp index 5db5ef1c57..8dc7522d60 100644 --- a/cpp/include/raft/stats/stats_types.hpp +++ b/cpp/include/raft/stats/stats_types.hpp @@ -20,6 +20,11 @@ namespace raft::stats { +/** + * @ingroup stats_histogram + * @{ + */ + /** * @brief Types of support histogram implementations */ @@ -54,9 +59,18 @@ enum HistType { HistTypeAuto }; +/** @} */ + +/** + * @ingroup stats_information_criterion + * @{ + */ + /** * @brief Supported types of information criteria */ enum IC_Type { AIC, AICc, BIC }; +/** @} */ + }; // end namespace raft::stats diff --git a/cpp/include/raft/stats/stddev.cuh b/cpp/include/raft/stats/stddev.cuh index 2747029955..27bd95f0ad 100644 --- a/cpp/include/raft/stats/stddev.cuh +++ b/cpp/include/raft/stats/stddev.cuh @@ -87,6 +87,11 @@ void vars(Type* var, detail::vars(var, data, mu, D, N, sample, rowMajor, stream); } +/** + * @defgroup stats_stddev Standard Deviation + * @{ + */ + /** * @brief Compute stddev of the input matrix * @@ -127,6 +132,13 @@ void stddev(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_stddev + +/** + * @defgroup stats_variance Variance + * @{ + */ + /** * @brief Compute variance of the input matrix * @@ -167,6 +179,8 @@ void vars(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_variance + }; // namespace stats }; // namespace raft diff --git a/cpp/include/raft/stats/sum.cuh b/cpp/include/raft/stats/sum.cuh index 18265c5e3a..c3aafe286a 100644 --- a/cpp/include/raft/stats/sum.cuh +++ b/cpp/include/raft/stats/sum.cuh @@ -46,6 +46,11 @@ void sum(Type* output, const Type* input, IdxType D, IdxType N, bool rowMajor, c detail::sum(output, input, D, N, rowMajor, stream); } +/** + * @defgroup stats_sum Sum + * @{ + */ + /** * @brief Compute sum of the input matrix * @@ -77,6 +82,8 @@ void sum(const raft::handle_t& handle, handle.get_stream()); } +/** @} */ // end group stats_sum + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/trustworthiness_score.cuh b/cpp/include/raft/stats/trustworthiness_score.cuh index b7b3999f77..e8e60871d0 100644 --- a/cpp/include/raft/stats/trustworthiness_score.cuh +++ b/cpp/include/raft/stats/trustworthiness_score.cuh @@ -51,6 +51,11 @@ double trustworthiness_score(const raft::handle_t& h, h, X, X_embedded, n, m, d, n_neighbors, batchSize); } +/** + * @defgroup stats_trustworthiness Trustworthiness + * @{ + */ + /** * @brief Compute the trustworthiness score * @tparam value_t the data type @@ -87,6 +92,9 @@ double trustworthiness_score( n_neighbors, batch_size); } + +/** @} */ // end group stats_trustworthiness + } // namespace stats } // namespace raft diff --git a/cpp/include/raft/stats/v_measure.cuh b/cpp/include/raft/stats/v_measure.cuh index c52dd35fd8..a5f5b58365 100644 --- a/cpp/include/raft/stats/v_measure.cuh +++ b/cpp/include/raft/stats/v_measure.cuh @@ -49,6 +49,11 @@ double v_measure(const T* truthClusterArray, truthClusterArray, predClusterArray, size, lowerLabelRange, upperLabelRange, stream, beta); } +/** + * @defgroup stats_vmeasure V-Measure + * @{ + */ + /** * @brief Function to calculate the v-measure between two clusters * @@ -84,6 +89,8 @@ double v_measure(const raft::handle_t& handle, beta); } +/** @} */ // end group stats_vmeasure + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft/stats/weighted_mean.cuh b/cpp/include/raft/stats/weighted_mean.cuh index 30a922b243..8c7f1ca7b5 100644 --- a/cpp/include/raft/stats/weighted_mean.cuh +++ b/cpp/include/raft/stats/weighted_mean.cuh @@ -93,6 +93,11 @@ void colWeightedMean( weightedMean(mu, data, weights, D, N, true, false, stream); } +/** + * @defgroup stats_weighted_mean Weighted Mean + * @{ + */ + /** * @brief Compute the weighted mean of the input matrix with a * vector of weights, along rows or along columns @@ -177,6 +182,9 @@ void col_weighted_mean(const raft::handle_t& handle, { weighted_mean(handle, data, weights, mu, false); } + +/** @} */ // end group stats_weighted_mean + }; // end namespace stats }; // end namespace raft diff --git a/cpp/include/raft_distance/kmeans.hpp b/cpp/include/raft_runtime/cluster/kmeans.hpp similarity index 81% rename from cpp/include/raft_distance/kmeans.hpp rename to cpp/include/raft_runtime/cluster/kmeans.hpp index c05aa281c4..241f5758e8 100644 --- a/cpp/include/raft_distance/kmeans.hpp +++ b/cpp/include/raft_runtime/cluster/kmeans.hpp @@ -21,7 +21,12 @@ #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { + +/** + * @defgroup kmeans_runtime Kmeans Runtime API + * @{ + */ void update_centroids(raft::handle_t const& handle, const float* X, @@ -46,18 +51,18 @@ void update_centroids(raft::handle_t const& handle, double* weight_per_cluster); void fit(handle_t const& handle, - const KMeansParams& params, - raft::device_matrix_view X, + const raft::cluster::kmeans::KMeansParams& params, + raft::device_matrix_view X, std::optional> sample_weight, - raft::device_matrix_view centroids, + raft::device_matrix_view centroids, raft::host_scalar_view inertia, raft::host_scalar_view n_iter); void fit(handle_t const& handle, - const KMeansParams& params, - raft::device_matrix_view X, + const raft::cluster::kmeans::KMeansParams& params, + raft::device_matrix_view X, std::optional> sample_weight, - raft::device_matrix_view centroids, + raft::device_matrix_view centroids, raft::host_scalar_view inertia, raft::host_scalar_view n_iter); @@ -76,4 +81,7 @@ void cluster_cost(raft::handle_t const& handle, int n_clusters, const double* centroids, double* cost); -} // namespace raft::cluster::kmeans::runtime + +/** @} */ // end group kmeans_runtime + +} // namespace raft::runtime::cluster::kmeans diff --git a/cpp/include/raft_distance/fused_l2_min_arg.hpp b/cpp/include/raft_runtime/distance/fused_l2_nn.hpp similarity index 90% rename from cpp/include/raft_distance/fused_l2_min_arg.hpp rename to cpp/include/raft_runtime/distance/fused_l2_nn.hpp index f7d3748666..46c9aa0b43 100644 --- a/cpp/include/raft_distance/fused_l2_min_arg.hpp +++ b/cpp/include/raft_runtime/distance/fused_l2_nn.hpp @@ -17,7 +17,12 @@ #include #include -namespace raft::distance::runtime { +namespace raft::runtime::distance { + +/** + * @defgroup fused_l2_nn_min_arg_runtime Fused L2 1NN Runtime API + * @{ + */ /** * @brief Wrapper around fusedL2NN with minimum reduction operators. @@ -55,4 +60,6 @@ void fused_l2_nn_min_arg(raft::handle_t const& handle, int k, bool sqrt); -} // end namespace raft::distance::runtime \ No newline at end of file +/** @} */ // end group fused_l2_nn_min_arg_runtime + +} // end namespace raft::runtime::distance diff --git a/cpp/include/raft_distance/pairwise_distance.hpp b/cpp/include/raft_runtime/distance/pairwise_distance.hpp similarity index 87% rename from cpp/include/raft_distance/pairwise_distance.hpp rename to cpp/include/raft_runtime/distance/pairwise_distance.hpp index e91ef5de20..02dca87e43 100644 --- a/cpp/include/raft_distance/pairwise_distance.hpp +++ b/cpp/include/raft_runtime/distance/pairwise_distance.hpp @@ -16,7 +16,13 @@ #include -namespace raft::distance::runtime { +namespace raft::runtime::distance { + +/** + * @defgroup pairwise_distance_runtime Pairwise Distances Runtime API + * @{ + */ + void pairwise_distance(raft::handle_t const& handle, float* x, float* y, @@ -38,4 +44,7 @@ void pairwise_distance(raft::handle_t const& handle, raft::distance::DistanceType metric, bool isRowMajor, float metric_arg); -} // namespace raft::distance::runtime \ No newline at end of file + +/** @} */ // end group pairwise_distance_runtime + +} // namespace raft::runtime::distance diff --git a/cpp/include/raft_runtime/neighbors/ivf_pq.hpp b/cpp/include/raft_runtime/neighbors/ivf_pq.hpp new file mode 100644 index 0000000000..13e3eac61f --- /dev/null +++ b/cpp/include/raft_runtime/neighbors/ivf_pq.hpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +namespace raft::runtime::neighbors::ivf_pq { + +#define RAFT_INST_SEARCH(T, IdxT) \ + void search(const handle_t&, \ + const raft::neighbors::ivf_pq::search_params&, \ + const raft::neighbors::ivf_pq::index&, \ + const T*, \ + uint32_t, \ + uint32_t, \ + IdxT*, \ + float*, \ + rmm::mr::device_memory_resource*); + +RAFT_INST_SEARCH(float, uint64_t); +RAFT_INST_SEARCH(int8_t, uint64_t); +RAFT_INST_SEARCH(uint8_t, uint64_t); + +#undef RAFT_INST_SEARCH + +// We define overloads for build and extend with void return type. This is used in the Cython +// wrappers, where exception handling is not compatible with return type that has nontrivial +// constructor. +#define RAFT_INST_BUILD_EXTEND(T, IdxT) \ + auto build(const handle_t& handle, \ + const raft::neighbors::ivf_pq::index_params& params, \ + const T* dataset, \ + IdxT n_rows, \ + uint32_t dim) \ + ->raft::neighbors::ivf_pq::index; \ + \ + auto extend(const handle_t& handle, \ + const raft::neighbors::ivf_pq::index& orig_index, \ + const T* new_vectors, \ + const IdxT* new_indices, \ + IdxT n_rows) \ + ->raft::neighbors::ivf_pq::index; \ + \ + void build(const handle_t& handle, \ + const raft::neighbors::ivf_pq::index_params& params, \ + const T* dataset, \ + IdxT n_rows, \ + uint32_t dim, \ + raft::neighbors::ivf_pq::index* idx); \ + \ + void extend(const handle_t& handle, \ + raft::neighbors::ivf_pq::index* idx, \ + const T* new_vectors, \ + const IdxT* new_indices, \ + IdxT n_rows); + +RAFT_INST_BUILD_EXTEND(float, uint64_t) +RAFT_INST_BUILD_EXTEND(int8_t, uint64_t) +RAFT_INST_BUILD_EXTEND(uint8_t, uint64_t) + +#undef RAFT_INST_BUILD_EXTEND + +} // namespace raft::runtime::neighbors::ivf_pq diff --git a/cpp/include/raft/neighbors/specializations/refine.hpp b/cpp/include/raft_runtime/neighbors/refine.hpp similarity index 61% rename from cpp/include/raft/neighbors/specializations/refine.hpp rename to cpp/include/raft_runtime/neighbors/refine.hpp index 80b128327d..2e08ae23c0 100644 --- a/cpp/include/raft/neighbors/specializations/refine.hpp +++ b/cpp/include/raft_runtime/neighbors/refine.hpp @@ -20,23 +20,23 @@ #include //#include -namespace raft::neighbors { +namespace raft::runtime::neighbors { -#define RAFT_INST_REFINE(IDX_T, DATA_T) \ - void refine(raft::handle_t const& handle, \ - raft::device_matrix_view dataset, \ - raft::device_matrix_view queries, \ - raft::device_matrix_view neighbor_candidates, \ - raft::device_matrix_view indices, \ - raft::device_matrix_view distances, \ - distance::DistanceType metric); \ - \ - void refine(raft::handle_t const& handle, \ - raft::host_matrix_view dataset, \ - raft::host_matrix_view queries, \ - raft::host_matrix_view neighbor_candidates, \ - raft::host_matrix_view indices, \ - raft::host_matrix_view distances, \ +#define RAFT_INST_REFINE(IDX_T, DATA_T) \ + void refine(raft::handle_t const& handle, \ + raft::device_matrix_view dataset, \ + raft::device_matrix_view queries, \ + raft::device_matrix_view neighbor_candidates, \ + raft::device_matrix_view indices, \ + raft::device_matrix_view distances, \ + distance::DistanceType metric); \ + \ + void refine(raft::handle_t const& handle, \ + raft::host_matrix_view dataset, \ + raft::host_matrix_view queries, \ + raft::host_matrix_view neighbor_candidates, \ + raft::host_matrix_view indices, \ + raft::host_matrix_view distances, \ distance::DistanceType metric); RAFT_INST_REFINE(uint64_t, float); @@ -45,4 +45,4 @@ RAFT_INST_REFINE(uint64_t, int8_t); #undef RAFT_INST_REFINE -} // namespace raft::neighbors +} // namespace raft::runtime::neighbors diff --git a/cpp/include/raft_distance/random/rmat_rectangular_generator.hpp b/cpp/include/raft_runtime/random/rmat_rectangular_generator.hpp similarity index 89% rename from cpp/include/raft_distance/random/rmat_rectangular_generator.hpp rename to cpp/include/raft_runtime/random/rmat_rectangular_generator.hpp index 5dfad2af3e..1dc1199864 100644 --- a/cpp/include/raft_distance/random/rmat_rectangular_generator.hpp +++ b/cpp/include/raft_runtime/random/rmat_rectangular_generator.hpp @@ -19,7 +19,12 @@ #include #include -namespace raft::random::runtime { +namespace raft::runtime::random { + +/** + * @defgroup rmat_runtime RMAT Runtime API + * @{ + */ #define FUNC_DECL(IdxT, ProbT) \ void rmat_rectangular_gen(raft::handle_t const& handle, \ @@ -39,4 +44,6 @@ FUNC_DECL(int64_t, double); #undef FUNC_DECL -} // namespace raft::random::runtime +/** @} */ // end group rmat_runtime + +} // namespace raft::runtime::random diff --git a/cpp/src/distance/cluster_cost.cuh b/cpp/src/distance/cluster/cluster_cost.cuh similarity index 97% rename from cpp/src/distance/cluster_cost.cuh rename to cpp/src/distance/cluster/cluster_cost.cuh index 344673830b..ac8247af95 100644 --- a/cpp/src/distance/cluster_cost.cuh +++ b/cpp/src/distance/cluster/cluster_cost.cuh @@ -19,7 +19,7 @@ #include #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { template void cluster_cost(const raft::handle_t& handle, const ElementType* X, @@ -76,4 +76,4 @@ void cluster_cost(const raft::handle_t& handle, raft::update_host(cost, device_cost.data(), 1, handle.get_stream()); } -} // namespace raft::cluster::kmeans::runtime +} // namespace raft::runtime::cluster::kmeans diff --git a/cpp/src/distance/cluster_cost_double.cu b/cpp/src/distance/cluster/cluster_cost_double.cu similarity index 92% rename from cpp/src/distance/cluster_cost_double.cu rename to cpp/src/distance/cluster/cluster_cost_double.cu index b811b0bf8d..8fffa4eee0 100644 --- a/cpp/src/distance/cluster_cost_double.cu +++ b/cpp/src/distance/cluster/cluster_cost_double.cu @@ -19,7 +19,7 @@ #include #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { void cluster_cost(const raft::handle_t& handle, const double* X, @@ -31,4 +31,4 @@ void cluster_cost(const raft::handle_t& handle, { cluster_cost(handle, X, n_samples, n_features, n_clusters, centroids, cost); } -} // namespace raft::cluster::kmeans::runtime +} // namespace raft::runtime::cluster::kmeans diff --git a/cpp/src/distance/cluster_cost_float.cu b/cpp/src/distance/cluster/cluster_cost_float.cu similarity index 92% rename from cpp/src/distance/cluster_cost_float.cu rename to cpp/src/distance/cluster/cluster_cost_float.cu index d78ea446da..7f2cd9a485 100644 --- a/cpp/src/distance/cluster_cost_float.cu +++ b/cpp/src/distance/cluster/cluster_cost_float.cu @@ -19,7 +19,7 @@ #include #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { void cluster_cost(const raft::handle_t& handle, const float* X, @@ -31,4 +31,4 @@ void cluster_cost(const raft::handle_t& handle, { cluster_cost(handle, X, n_samples, n_features, n_clusters, centroids, cost); } -} // namespace raft::cluster::kmeans::runtime +} // namespace raft::runtime::cluster::kmeans diff --git a/cpp/src/distance/kmeans_fit_double.cu b/cpp/src/distance/cluster/kmeans_fit_double.cu similarity index 88% rename from cpp/src/distance/kmeans_fit_double.cu rename to cpp/src/distance/cluster/kmeans_fit_double.cu index cb5d6e8c8f..2989941d85 100644 --- a/cpp/src/distance/kmeans_fit_double.cu +++ b/cpp/src/distance/cluster/kmeans_fit_double.cu @@ -18,10 +18,10 @@ #include #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { void fit(handle_t const& handle, - const KMeansParams& params, + const raft::cluster::kmeans::KMeansParams& params, raft::device_matrix_view X, std::optional> sample_weight, raft::device_matrix_view centroids, @@ -31,4 +31,4 @@ void fit(handle_t const& handle, raft::cluster::kmeans::fit( handle, params, X, sample_weight, centroids, inertia, n_iter); } -} // namespace raft::cluster::kmeans::runtime +} // namespace raft::runtime::cluster::kmeans diff --git a/cpp/src/distance/kmeans_fit_float.cu b/cpp/src/distance/cluster/kmeans_fit_float.cu similarity index 88% rename from cpp/src/distance/kmeans_fit_float.cu rename to cpp/src/distance/cluster/kmeans_fit_float.cu index c10234d705..0e10ab30a4 100644 --- a/cpp/src/distance/kmeans_fit_float.cu +++ b/cpp/src/distance/cluster/kmeans_fit_float.cu @@ -18,10 +18,10 @@ #include #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { void fit(handle_t const& handle, - const KMeansParams& params, + const raft::cluster::kmeans::KMeansParams& params, raft::device_matrix_view X, std::optional> sample_weight, raft::device_matrix_view centroids, @@ -31,4 +31,4 @@ void fit(handle_t const& handle, raft::cluster::kmeans::fit( handle, params, X, sample_weight, centroids, inertia, n_iter); } -} // namespace raft::cluster::kmeans::runtime +} // namespace raft::runtime::cluster::kmeans diff --git a/cpp/src/distance/update_centroids.cuh b/cpp/src/distance/cluster/update_centroids.cuh similarity index 97% rename from cpp/src/distance/update_centroids.cuh rename to cpp/src/distance/cluster/update_centroids.cuh index 91f3e1e2a3..035f597523 100644 --- a/cpp/src/distance/update_centroids.cuh +++ b/cpp/src/distance/cluster/update_centroids.cuh @@ -20,7 +20,7 @@ #include #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { template void update_centroids(raft::handle_t const& handle, @@ -68,4 +68,4 @@ void update_centroids(raft::handle_t const& handle, weight_per_cluster_view, new_centroids_view); } -} // namespace raft::cluster::kmeans::runtime \ No newline at end of file +} // namespace raft::runtime::cluster::kmeans \ No newline at end of file diff --git a/cpp/src/distance/update_centroids_double.cu b/cpp/src/distance/cluster/update_centroids_double.cu similarity index 94% rename from cpp/src/distance/update_centroids_double.cu rename to cpp/src/distance/cluster/update_centroids_double.cu index fe741ddb78..85c4953150 100644 --- a/cpp/src/distance/update_centroids_double.cu +++ b/cpp/src/distance/cluster/update_centroids_double.cu @@ -19,7 +19,7 @@ #include #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { void update_centroids(raft::handle_t const& handle, const double* X, @@ -44,4 +44,4 @@ void update_centroids(raft::handle_t const& handle, weight_per_cluster); } -} // namespace raft::cluster::kmeans::runtime \ No newline at end of file +} // namespace raft::runtime::cluster::kmeans \ No newline at end of file diff --git a/cpp/src/distance/update_centroids_float.cu b/cpp/src/distance/cluster/update_centroids_float.cu similarity index 94% rename from cpp/src/distance/update_centroids_float.cu rename to cpp/src/distance/cluster/update_centroids_float.cu index ebb06376ff..aaad2bc3e4 100644 --- a/cpp/src/distance/update_centroids_float.cu +++ b/cpp/src/distance/cluster/update_centroids_float.cu @@ -19,7 +19,7 @@ #include #include -namespace raft::cluster::kmeans::runtime { +namespace raft::runtime::cluster::kmeans { void update_centroids(raft::handle_t const& handle, const float* X, @@ -44,4 +44,4 @@ void update_centroids(raft::handle_t const& handle, weight_per_cluster); } -} // namespace raft::cluster::kmeans::runtime \ No newline at end of file +} // namespace raft::runtime::cluster::kmeans \ No newline at end of file diff --git a/cpp/src/distance/fused_l2_min_arg.cu b/cpp/src/distance/distance/fused_l2_min_arg.cu similarity index 82% rename from cpp/src/distance/fused_l2_min_arg.cu rename to cpp/src/distance/distance/fused_l2_min_arg.cu index c722b5a566..f74b7c0e86 100644 --- a/cpp/src/distance/fused_l2_min_arg.cu +++ b/cpp/src/distance/distance/fused_l2_min_arg.cu @@ -23,7 +23,7 @@ #include #include -namespace raft::distance::runtime { +namespace raft::runtime::distance { template struct KeyValueIndexOp { @@ -52,18 +52,18 @@ void compute_fused_l2_nn_min_arg(raft::handle_t const& handle, raft::linalg::rowNorm(x_norms.data(), x, k, m, raft::linalg::L2Norm, true, handle.get_stream()); raft::linalg::rowNorm(y_norms.data(), y, k, n, raft::linalg::L2Norm, true, handle.get_stream()); - fusedL2NNMinReduce(kvp.data_handle(), - x, - y, - x_norms.data(), - y_norms.data(), - m, - n, - k, - (void*)workspace.data(), - sqrt, - true, - handle.get_stream()); + raft::distance::fusedL2NNMinReduce(kvp.data_handle(), + x, + y, + x_norms.data(), + y_norms.data(), + m, + n, + k, + (void*)workspace.data(), + sqrt, + true, + handle.get_stream()); KeyValueIndexOp conversion_op; thrust::transform( @@ -95,4 +95,4 @@ void fused_l2_nn_min_arg(raft::handle_t const& handle, compute_fused_l2_nn_min_arg(handle, min, x, y, m, n, k, sqrt); } -} // end namespace raft::distance::runtime \ No newline at end of file +} // end namespace raft::runtime::distance \ No newline at end of file diff --git a/cpp/src/distance/pairwise_distance.cu b/cpp/src/distance/distance/pairwise_distance.cu similarity index 95% rename from cpp/src/distance/pairwise_distance.cu rename to cpp/src/distance/distance/pairwise_distance.cu index 71133c5f84..cbdd5cd8f2 100644 --- a/cpp/src/distance/pairwise_distance.cu +++ b/cpp/src/distance/distance/pairwise_distance.cu @@ -19,7 +19,7 @@ #include #include -namespace raft::distance::runtime { +namespace raft::runtime::distance { void pairwise_distance(raft::handle_t const& handle, float* x, @@ -50,4 +50,4 @@ void pairwise_distance(raft::handle_t const& handle, raft::distance::pairwise_distance( handle, x, y, dists, m, n, k, metric, isRowMajor, metric_arg); } -} // namespace raft::distance::runtime \ No newline at end of file +} // namespace raft::runtime::distance \ No newline at end of file diff --git a/cpp/src/distance/specializations/detail/canberra.cu b/cpp/src/distance/distance/specializations/detail/canberra.cu similarity index 97% rename from cpp/src/distance/specializations/detail/canberra.cu rename to cpp/src/distance/distance/specializations/detail/canberra.cu index b2dd993ab7..3a81b35a46 100644 --- a/cpp/src/distance/specializations/detail/canberra.cu +++ b/cpp/src/distance/distance/specializations/detail/canberra.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cpp/src/distance/specializations/detail/chebyshev.cu b/cpp/src/distance/distance/specializations/detail/chebyshev.cu similarity index 97% rename from cpp/src/distance/specializations/detail/chebyshev.cu rename to cpp/src/distance/distance/specializations/detail/chebyshev.cu index ab310515bd..7406265e97 100644 --- a/cpp/src/distance/specializations/detail/chebyshev.cu +++ b/cpp/src/distance/distance/specializations/detail/chebyshev.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cpp/src/distance/specializations/detail/correlation.cu b/cpp/src/distance/distance/specializations/detail/correlation.cu similarity index 97% rename from cpp/src/distance/specializations/detail/correlation.cu rename to cpp/src/distance/distance/specializations/detail/correlation.cu index 04b9e5bf69..0e2e55ecfb 100644 --- a/cpp/src/distance/specializations/detail/correlation.cu +++ b/cpp/src/distance/distance/specializations/detail/correlation.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cpp/src/distance/specializations/detail/cosine.cu b/cpp/src/distance/distance/specializations/detail/cosine.cu similarity index 97% rename from cpp/src/distance/specializations/detail/cosine.cu rename to cpp/src/distance/distance/specializations/detail/cosine.cu index bc19599511..efbdfbcd36 100644 --- a/cpp/src/distance/specializations/detail/cosine.cu +++ b/cpp/src/distance/distance/specializations/detail/cosine.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cpp/src/distance/specializations/detail/hamming_unexpanded.cu b/cpp/src/distance/distance/specializations/detail/hamming_unexpanded.cu similarity index 97% rename from cpp/src/distance/specializations/detail/hamming_unexpanded.cu rename to cpp/src/distance/distance/specializations/detail/hamming_unexpanded.cu index e5e66e85bd..ec46ae4383 100644 --- a/cpp/src/distance/specializations/detail/hamming_unexpanded.cu +++ b/cpp/src/distance/distance/specializations/detail/hamming_unexpanded.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cpp/src/distance/specializations/detail/hellinger_expanded.cu b/cpp/src/distance/distance/specializations/detail/hellinger_expanded.cu similarity index 97% rename from cpp/src/distance/specializations/detail/hellinger_expanded.cu rename to cpp/src/distance/distance/specializations/detail/hellinger_expanded.cu index fa9b8e14d6..8bf8ed8b5a 100644 --- a/cpp/src/distance/specializations/detail/hellinger_expanded.cu +++ b/cpp/src/distance/distance/specializations/detail/hellinger_expanded.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cpp/src/distance/specializations/detail/jensen_shannon_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/jensen_shannon_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/jensen_shannon_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/jensen_shannon_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/jensen_shannon_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/jensen_shannon_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/jensen_shannon_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/jensen_shannon_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/jensen_shannon_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/jensen_shannon_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/jensen_shannon_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/jensen_shannon_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/detail/kernels/gram_matrix_base_double.cu b/cpp/src/distance/distance/specializations/detail/kernels/gram_matrix_base_double.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kernels/gram_matrix_base_double.cu rename to cpp/src/distance/distance/specializations/detail/kernels/gram_matrix_base_double.cu diff --git a/cpp/src/distance/specializations/detail/kernels/gram_matrix_base_float.cu b/cpp/src/distance/distance/specializations/detail/kernels/gram_matrix_base_float.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kernels/gram_matrix_base_float.cu rename to cpp/src/distance/distance/specializations/detail/kernels/gram_matrix_base_float.cu diff --git a/cpp/src/distance/specializations/detail/kernels/polynomial_kernel_double_int.cu b/cpp/src/distance/distance/specializations/detail/kernels/polynomial_kernel_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kernels/polynomial_kernel_double_int.cu rename to cpp/src/distance/distance/specializations/detail/kernels/polynomial_kernel_double_int.cu diff --git a/cpp/src/distance/specializations/detail/kernels/polynomial_kernel_float_int.cu b/cpp/src/distance/distance/specializations/detail/kernels/polynomial_kernel_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kernels/polynomial_kernel_float_int.cu rename to cpp/src/distance/distance/specializations/detail/kernels/polynomial_kernel_float_int.cu diff --git a/cpp/src/distance/specializations/detail/kernels/rbf_kernel_double.cu b/cpp/src/distance/distance/specializations/detail/kernels/rbf_kernel_double.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kernels/rbf_kernel_double.cu rename to cpp/src/distance/distance/specializations/detail/kernels/rbf_kernel_double.cu diff --git a/cpp/src/distance/specializations/detail/kernels/rbf_kernel_float.cu b/cpp/src/distance/distance/specializations/detail/kernels/rbf_kernel_float.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kernels/rbf_kernel_float.cu rename to cpp/src/distance/distance/specializations/detail/kernels/rbf_kernel_float.cu diff --git a/cpp/src/distance/specializations/detail/kernels/tanh_kernel_double.cu b/cpp/src/distance/distance/specializations/detail/kernels/tanh_kernel_double.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kernels/tanh_kernel_double.cu rename to cpp/src/distance/distance/specializations/detail/kernels/tanh_kernel_double.cu diff --git a/cpp/src/distance/specializations/detail/kernels/tanh_kernel_float.cu b/cpp/src/distance/distance/specializations/detail/kernels/tanh_kernel_float.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kernels/tanh_kernel_float.cu rename to cpp/src/distance/distance/specializations/detail/kernels/tanh_kernel_float.cu diff --git a/cpp/src/distance/specializations/detail/kl_divergence_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/kl_divergence_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kl_divergence_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/kl_divergence_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/kl_divergence_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/kl_divergence_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kl_divergence_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/kl_divergence_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/kl_divergence_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/kl_divergence_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/kl_divergence_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/kl_divergence_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/detail/l1_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/l1_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l1_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/l1_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/l1_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/l1_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l1_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/l1_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/l1_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/l1_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l1_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/l1_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/detail/l2_expanded_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/l2_expanded_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_expanded_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/l2_expanded_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/l2_expanded_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/l2_expanded_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_expanded_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/l2_expanded_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/l2_expanded_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/l2_expanded_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_expanded_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/l2_expanded_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/detail/l2_sqrt_expanded_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/l2_sqrt_expanded_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_sqrt_expanded_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/l2_sqrt_expanded_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/l2_sqrt_expanded_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/l2_sqrt_expanded_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_sqrt_expanded_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/l2_sqrt_expanded_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/l2_sqrt_expanded_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/l2_sqrt_expanded_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_sqrt_expanded_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/l2_sqrt_expanded_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/detail/l2_sqrt_unexpanded_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/l2_sqrt_unexpanded_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_sqrt_unexpanded_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/l2_sqrt_unexpanded_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/l2_sqrt_unexpanded_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/detail/l2_unexpanded_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/l2_unexpanded_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_unexpanded_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/l2_unexpanded_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/l2_unexpanded_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/l2_unexpanded_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_unexpanded_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/l2_unexpanded_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/l2_unexpanded_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/l2_unexpanded_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/l2_unexpanded_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/l2_unexpanded_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/detail/lp_unexpanded_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/lp_unexpanded_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/lp_unexpanded_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/lp_unexpanded_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/lp_unexpanded_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/lp_unexpanded_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/lp_unexpanded_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/lp_unexpanded_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/lp_unexpanded_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/lp_unexpanded_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/lp_unexpanded_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/lp_unexpanded_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/detail/russel_rao_double_double_double_int.cu b/cpp/src/distance/distance/specializations/detail/russel_rao_double_double_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/russel_rao_double_double_double_int.cu rename to cpp/src/distance/distance/specializations/detail/russel_rao_double_double_double_int.cu diff --git a/cpp/src/distance/specializations/detail/russel_rao_float_float_float_int.cu b/cpp/src/distance/distance/specializations/detail/russel_rao_float_float_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/detail/russel_rao_float_float_float_int.cu rename to cpp/src/distance/distance/specializations/detail/russel_rao_float_float_float_int.cu diff --git a/cpp/src/distance/specializations/detail/russel_rao_float_float_float_uint32.cu b/cpp/src/distance/distance/specializations/detail/russel_rao_float_float_float_uint32.cu similarity index 100% rename from cpp/src/distance/specializations/detail/russel_rao_float_float_float_uint32.cu rename to cpp/src/distance/distance/specializations/detail/russel_rao_float_float_float_uint32.cu diff --git a/cpp/src/distance/specializations/fused_l2_nn_double_int.cu b/cpp/src/distance/distance/specializations/fused_l2_nn_double_int.cu similarity index 100% rename from cpp/src/distance/specializations/fused_l2_nn_double_int.cu rename to cpp/src/distance/distance/specializations/fused_l2_nn_double_int.cu diff --git a/cpp/src/distance/specializations/fused_l2_nn_double_int64.cu b/cpp/src/distance/distance/specializations/fused_l2_nn_double_int64.cu similarity index 100% rename from cpp/src/distance/specializations/fused_l2_nn_double_int64.cu rename to cpp/src/distance/distance/specializations/fused_l2_nn_double_int64.cu diff --git a/cpp/src/distance/specializations/fused_l2_nn_float_int.cu b/cpp/src/distance/distance/specializations/fused_l2_nn_float_int.cu similarity index 100% rename from cpp/src/distance/specializations/fused_l2_nn_float_int.cu rename to cpp/src/distance/distance/specializations/fused_l2_nn_float_int.cu diff --git a/cpp/src/distance/specializations/fused_l2_nn_float_int64.cu b/cpp/src/distance/distance/specializations/fused_l2_nn_float_int64.cu similarity index 100% rename from cpp/src/distance/specializations/fused_l2_nn_float_int64.cu rename to cpp/src/distance/distance/specializations/fused_l2_nn_float_int64.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_build.cu b/cpp/src/distance/neighbors/ivfpq_build.cu similarity index 53% rename from cpp/src/nn/specializations/detail/ivfpq_build.cu rename to cpp/src/distance/neighbors/ivfpq_build.cu index 9ff22a3729..20119b5178 100644 --- a/cpp/src/nn/specializations/detail/ivfpq_build.cu +++ b/cpp/src/distance/neighbors/ivfpq_build.cu @@ -15,46 +15,47 @@ */ #include -#include +#include -namespace raft::neighbors::ivf_pq { +namespace raft::runtime::neighbors::ivf_pq { -#define RAFT_INST_BUILD_EXTEND(T, IdxT) \ - auto build(const handle_t& handle, \ - const index_params& params, \ - const T* dataset, \ - IdxT n_rows, \ - uint32_t dim) \ - ->index \ - { \ - return build(handle, params, dataset, n_rows, dim); \ - } \ - auto extend(const handle_t& handle, \ - const index& orig_index, \ - const T* new_vectors, \ - const IdxT* new_indices, \ - IdxT n_rows) \ - ->index \ - { \ - return extend(handle, orig_index, new_vectors, new_indices, n_rows); \ - } \ - \ - void build(const handle_t& handle, \ - const index_params& params, \ - const T* dataset, \ - IdxT n_rows, \ - uint32_t dim, \ - index* idx) \ - { \ - *idx = build(handle, params, dataset, n_rows, dim); \ - } \ - void extend(const handle_t& handle, \ - index* idx, \ - const T* new_vectors, \ - const IdxT* new_indices, \ - IdxT n_rows) \ - { \ - extend(handle, idx, new_vectors, new_indices, n_rows); \ +#define RAFT_INST_BUILD_EXTEND(T, IdxT) \ + auto build(const handle_t& handle, \ + const raft::neighbors::ivf_pq::index_params& params, \ + const T* dataset, \ + IdxT n_rows, \ + uint32_t dim) \ + ->raft::neighbors::ivf_pq::index \ + { \ + return raft::neighbors::ivf_pq::build(handle, params, dataset, n_rows, dim); \ + } \ + auto extend(const handle_t& handle, \ + const raft::neighbors::ivf_pq::index& orig_index, \ + const T* new_vectors, \ + const IdxT* new_indices, \ + IdxT n_rows) \ + ->raft::neighbors::ivf_pq::index \ + { \ + return raft::neighbors::ivf_pq::extend( \ + handle, orig_index, new_vectors, new_indices, n_rows); \ + } \ + \ + void build(const handle_t& handle, \ + const raft::neighbors::ivf_pq::index_params& params, \ + const T* dataset, \ + IdxT n_rows, \ + uint32_t dim, \ + raft::neighbors::ivf_pq::index* idx) \ + { \ + *idx = raft::neighbors::ivf_pq::build(handle, params, dataset, n_rows, dim); \ + } \ + void extend(const handle_t& handle, \ + raft::neighbors::ivf_pq::index* idx, \ + const T* new_vectors, \ + const IdxT* new_indices, \ + IdxT n_rows) \ + { \ + raft::neighbors::ivf_pq::extend(handle, idx, new_vectors, new_indices, n_rows); \ } RAFT_INST_BUILD_EXTEND(float, uint64_t); @@ -63,4 +64,4 @@ RAFT_INST_BUILD_EXTEND(uint8_t, uint64_t); #undef RAFT_INST_BUILD_EXTEND -} // namespace raft::neighbors::ivf_pq +} // namespace raft::runtime::neighbors::ivf_pq diff --git a/cpp/src/nn/specializations/detail/ivfpq_search.cu b/cpp/src/distance/neighbors/ivfpq_search.cu similarity index 67% rename from cpp/src/nn/specializations/detail/ivfpq_search.cu rename to cpp/src/distance/neighbors/ivfpq_search.cu index 80bf589803..3bd1f6ed68 100644 --- a/cpp/src/nn/specializations/detail/ivfpq_search.cu +++ b/cpp/src/distance/neighbors/ivfpq_search.cu @@ -16,22 +16,23 @@ #include #include -#include +#include -namespace raft::neighbors::ivf_pq { +namespace raft::runtime::neighbors::ivf_pq { -#define RAFT_SEARCH_INST(T, IdxT) \ - void search(const handle_t& handle, \ - const search_params& params, \ - const index& idx, \ - const T* queries, \ - uint32_t n_queries, \ - uint32_t k, \ - IdxT* neighbors, \ - float* distances, \ - rmm::mr::device_memory_resource* mr) \ - { \ - search(handle, params, idx, queries, n_queries, k, neighbors, distances, mr); \ +#define RAFT_SEARCH_INST(T, IdxT) \ + void search(const handle_t& handle, \ + const raft::neighbors::ivf_pq::search_params& params, \ + const raft::neighbors::ivf_pq::index& idx, \ + const T* queries, \ + uint32_t n_queries, \ + uint32_t k, \ + IdxT* neighbors, \ + float* distances, \ + rmm::mr::device_memory_resource* mr) \ + { \ + raft::neighbors::ivf_pq::search( \ + handle, params, idx, queries, n_queries, k, neighbors, distances, mr); \ } RAFT_SEARCH_INST(float, uint64_t); @@ -40,4 +41,4 @@ RAFT_SEARCH_INST(uint8_t, uint64_t); #undef RAFT_INST_SEARCH -} // namespace raft::neighbors::ivf_pq +} // namespace raft::runtime::neighbors::ivf_pq diff --git a/cpp/src/nn/specializations/refine.cu b/cpp/src/distance/neighbors/refine.cu similarity index 56% rename from cpp/src/nn/specializations/refine.cu rename to cpp/src/distance/neighbors/refine.cu index 3dbb218705..82e7ebe5ff 100644 --- a/cpp/src/nn/specializations/refine.cu +++ b/cpp/src/distance/neighbors/refine.cu @@ -16,31 +16,31 @@ #include -namespace raft::neighbors { +namespace raft::runtime::neighbors { -#define RAFT_INST_REFINE(IDX_T, DATA_T) \ - void refine(raft::handle_t const& handle, \ - raft::device_matrix_view dataset, \ - raft::device_matrix_view queries, \ - raft::device_matrix_view neighbor_candidates, \ - raft::device_matrix_view indices, \ - raft::device_matrix_view distances, \ - distance::DistanceType metric) \ - { \ - detail::refine_device( \ - handle, dataset, queries, neighbor_candidates, indices, distances, metric); \ - } \ - \ - void refine(raft::handle_t const& handle, \ - raft::host_matrix_view dataset, \ - raft::host_matrix_view queries, \ - raft::host_matrix_view neighbor_candidates, \ - raft::host_matrix_view indices, \ - raft::host_matrix_view distances, \ - distance::DistanceType metric) \ - { \ - detail::refine_host( \ - dataset, queries, neighbor_candidates, indices, distances, metric); \ +#define RAFT_INST_REFINE(IDX_T, DATA_T) \ + void refine(raft::handle_t const& handle, \ + raft::device_matrix_view dataset, \ + raft::device_matrix_view queries, \ + raft::device_matrix_view neighbor_candidates, \ + raft::device_matrix_view indices, \ + raft::device_matrix_view distances, \ + distance::DistanceType metric) \ + { \ + raft::neighbors::detail::refine_device( \ + handle, dataset, queries, neighbor_candidates, indices, distances, metric); \ + } \ + \ + void refine(raft::handle_t const& handle, \ + raft::host_matrix_view dataset, \ + raft::host_matrix_view queries, \ + raft::host_matrix_view neighbor_candidates, \ + raft::host_matrix_view indices, \ + raft::host_matrix_view distances, \ + distance::DistanceType metric) \ + { \ + raft::neighbors::detail::refine_host( \ + dataset, queries, neighbor_candidates, indices, distances, metric); \ } RAFT_INST_REFINE(uint64_t, float); @@ -49,4 +49,4 @@ RAFT_INST_REFINE(uint64_t, int8_t); #undef RAFT_INST_REFINE -} // namespace raft::neighbors +} // namespace raft::runtime::neighbors diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_float_fast.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_fast.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_float_fast.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_fast.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_float_no_basediff.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_no_basediff.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_float_no_basediff.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_no_basediff.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_float_no_smem_lut.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_no_smem_lut.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_float_no_smem_lut.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_float_no_smem_lut.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_fast.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_fast.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_fast.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_fast.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_no_basediff.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_no_basediff.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_no_basediff.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_no_basediff.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_no_smem_lut.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_no_smem_lut.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8s_no_smem_lut.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8s_no_smem_lut.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_fast.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_fast.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_fast.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_fast.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_no_basediff.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_no_basediff.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_no_basediff.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_no_basediff.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_no_smem_lut.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_no_smem_lut.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_fp8u_no_smem_lut.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_fp8u_no_smem_lut.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_half_fast.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_fast.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_half_fast.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_fast.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_half_no_basediff.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_no_basediff.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_half_no_basediff.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_no_basediff.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_compute_similarity_half_no_smem_lut.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_no_smem_lut.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_compute_similarity_half_no_smem_lut.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_compute_similarity_half_no_smem_lut.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_search_float_int64_t.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_search_float_int64_t.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_search_float_int64_t.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_search_float_int64_t.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_search_float_uint32_t.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_search_float_uint32_t.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_search_float_uint32_t.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_search_float_uint32_t.cu diff --git a/cpp/src/nn/specializations/detail/ivfpq_search_float_uint64_t.cu b/cpp/src/distance/neighbors/specializations/detail/ivfpq_search_float_uint64_t.cu similarity index 100% rename from cpp/src/nn/specializations/detail/ivfpq_search_float_uint64_t.cu rename to cpp/src/distance/neighbors/specializations/detail/ivfpq_search_float_uint64_t.cu diff --git a/cpp/src/random/specializations/common.cuh b/cpp/src/distance/random/common.cuh similarity index 96% rename from cpp/src/random/specializations/common.cuh rename to cpp/src/distance/random/common.cuh index d854087714..3bd57fc80d 100644 --- a/cpp/src/random/specializations/common.cuh +++ b/cpp/src/distance/random/common.cuh @@ -15,7 +15,7 @@ */ #include -#include +#include #define FUNC_DEF(IdxT, ProbT) \ void rmat_rectangular_gen(raft::handle_t const& handle, \ diff --git a/cpp/src/random/specializations/rmat_rectangular_generator_int64_double.cu b/cpp/src/distance/random/rmat_rectangular_generator_int64_double.cu similarity index 90% rename from cpp/src/random/specializations/rmat_rectangular_generator_int64_double.cu rename to cpp/src/distance/random/rmat_rectangular_generator_int64_double.cu index 4985a64927..1b8fb8bd6d 100644 --- a/cpp/src/random/specializations/rmat_rectangular_generator_int64_double.cu +++ b/cpp/src/distance/random/rmat_rectangular_generator_int64_double.cu @@ -16,8 +16,8 @@ #include "common.cuh" -namespace raft::random::runtime { +namespace raft::runtime::random { FUNC_DEF(int64_t, double); -} // namespace raft::random::runtime +} // namespace raft::runtime::random diff --git a/cpp/src/random/specializations/rmat_rectangular_generator_int64_float.cu b/cpp/src/distance/random/rmat_rectangular_generator_int64_float.cu similarity index 90% rename from cpp/src/random/specializations/rmat_rectangular_generator_int64_float.cu rename to cpp/src/distance/random/rmat_rectangular_generator_int64_float.cu index f42e039bae..249e8c2ffb 100644 --- a/cpp/src/random/specializations/rmat_rectangular_generator_int64_float.cu +++ b/cpp/src/distance/random/rmat_rectangular_generator_int64_float.cu @@ -16,8 +16,8 @@ #include "common.cuh" -namespace raft::random::runtime { +namespace raft::runtime::random { FUNC_DEF(int64_t, float); -} // namespace raft::random::runtime +} // namespace raft::runtime::random diff --git a/cpp/src/random/specializations/rmat_rectangular_generator_int_double.cu b/cpp/src/distance/random/rmat_rectangular_generator_int_double.cu similarity index 90% rename from cpp/src/random/specializations/rmat_rectangular_generator_int_double.cu rename to cpp/src/distance/random/rmat_rectangular_generator_int_double.cu index c29d140f09..3333b87983 100644 --- a/cpp/src/random/specializations/rmat_rectangular_generator_int_double.cu +++ b/cpp/src/distance/random/rmat_rectangular_generator_int_double.cu @@ -16,8 +16,8 @@ #include "common.cuh" -namespace raft::random::runtime { +namespace raft::runtime::random { FUNC_DEF(int, double); -} // namespace raft::random::runtime +} // namespace raft::runtime::random diff --git a/cpp/src/random/specializations/rmat_rectangular_generator_int_float.cu b/cpp/src/distance/random/rmat_rectangular_generator_int_float.cu similarity index 90% rename from cpp/src/random/specializations/rmat_rectangular_generator_int_float.cu rename to cpp/src/distance/random/rmat_rectangular_generator_int_float.cu index b07ede6a58..db8d024c04 100644 --- a/cpp/src/random/specializations/rmat_rectangular_generator_int_float.cu +++ b/cpp/src/distance/random/rmat_rectangular_generator_int_float.cu @@ -16,8 +16,8 @@ #include "common.cuh" -namespace raft::random::runtime { +namespace raft::runtime::random { FUNC_DEF(int, float); -} // namespace raft::random::runtime +} // namespace raft::runtime::random diff --git a/cpp/test/random/multi_variable_gaussian.cu b/cpp/test/random/multi_variable_gaussian.cu index 51a79ae04a..f9f79e6845 100644 --- a/cpp/test/random/multi_variable_gaussian.cu +++ b/cpp/test/random/multi_variable_gaussian.cu @@ -65,7 +65,7 @@ enum Correlation : unsigned char { template struct MVGInputs { T tolerance; - typename multi_variable_gaussian::Decomposer method; + typename detail::multi_variable_gaussian::Decomposer method; Correlation corr; int dim, nPoints; unsigned long long int seed; @@ -139,7 +139,7 @@ class MVGTest : public ::testing::TestWithParam> { raft::update_device(x_d.data(), x.data(), dim, stream); // initializing the mvg - mvg = new multi_variable_gaussian(handle, dim, method); + mvg = new detail::multi_variable_gaussian(handle, dim, method); std::size_t o = mvg->get_workspace_size(); // give the workspace area to mvg @@ -199,9 +199,9 @@ class MVGTest : public ::testing::TestWithParam> { std::vector P, x, X; rmm::device_uvector workspace_d, P_d, x_d, X_d, Rand_cov, Rand_mean; int dim, nPoints; - typename multi_variable_gaussian::Decomposer method; + typename detail::multi_variable_gaussian::Decomposer method; Correlation corr; - multi_variable_gaussian* mvg = NULL; + detail::multi_variable_gaussian* mvg = NULL; T tolerance; raft::handle_t handle; }; // end of MVGTest class @@ -209,11 +209,11 @@ class MVGTest : public ::testing::TestWithParam> { template class MVGMdspanTest : public ::testing::TestWithParam> { private: - static auto old_enum_to_new_enum(typename multi_variable_gaussian::Decomposer method) + static auto old_enum_to_new_enum(typename detail::multi_variable_gaussian::Decomposer method) { - if (method == multi_variable_gaussian::chol_decomp) { + if (method == detail::multi_variable_gaussian::chol_decomp) { return multi_variable_gaussian_decomposition_method::CHOLESKY; - } else if (method == multi_variable_gaussian::jacobi) { + } else if (method == detail::multi_variable_gaussian::jacobi) { return multi_variable_gaussian_decomposition_method::JACOBI; } else { return multi_variable_gaussian_decomposition_method::QR; @@ -280,7 +280,7 @@ class MVGMdspanTest : public ::testing::TestWithParam> { rmm::mr::device_memory_resource* mem_resource_ptr = rmm::mr::get_current_device_resource(); ASSERT_TRUE(mem_resource_ptr != nullptr); - raft::random::compute_multi_variable_gaussian( + raft::random::multi_variable_gaussian( handle, *mem_resource_ptr, x_view, P_view, X_view, method); // saving the mean of the randoms in Rand_mean @@ -336,60 +336,65 @@ class MVGMdspanTest : public ::testing::TestWithParam> { // Declare your inputs const std::vector> inputsf = { {0.3f, - multi_variable_gaussian::Decomposer::chol_decomp, + detail::multi_variable_gaussian::Decomposer::chol_decomp, Correlation::CORRELATED, 5, 30000, 6ULL}, {0.1f, - multi_variable_gaussian::Decomposer::chol_decomp, + detail::multi_variable_gaussian::Decomposer::chol_decomp, Correlation::UNCORRELATED, 5, 30000, 6ULL}, {0.25f, - multi_variable_gaussian::Decomposer::jacobi, + detail::multi_variable_gaussian::Decomposer::jacobi, Correlation::CORRELATED, 5, 30000, 6ULL}, {0.1f, - multi_variable_gaussian::Decomposer::jacobi, + detail::multi_variable_gaussian::Decomposer::jacobi, Correlation::UNCORRELATED, 5, 30000, 6ULL}, - {0.2f, multi_variable_gaussian::Decomposer::qr, Correlation::CORRELATED, 5, 30000, 6ULL}, + {0.2f, + detail::multi_variable_gaussian::Decomposer::qr, + Correlation::CORRELATED, + 5, + 30000, + 6ULL}, // { 0.2f, multi_variable_gaussian::Decomposer::qr, // Correlation::UNCORRELATED, 5, 30000, 6ULL} }; const std::vector> inputsd = { {0.25, - multi_variable_gaussian::Decomposer::chol_decomp, + detail::multi_variable_gaussian::Decomposer::chol_decomp, Correlation::CORRELATED, 10, 3000000, 6ULL}, {0.1, - multi_variable_gaussian::Decomposer::chol_decomp, + detail::multi_variable_gaussian::Decomposer::chol_decomp, Correlation::UNCORRELATED, 10, 3000000, 6ULL}, {0.25, - multi_variable_gaussian::Decomposer::jacobi, + detail::multi_variable_gaussian::Decomposer::jacobi, Correlation::CORRELATED, 10, 3000000, 6ULL}, {0.1, - multi_variable_gaussian::Decomposer::jacobi, + detail::multi_variable_gaussian::Decomposer::jacobi, Correlation::UNCORRELATED, 10, 3000000, 6ULL}, {0.2, - multi_variable_gaussian::Decomposer::qr, + detail::multi_variable_gaussian::Decomposer::qr, Correlation::CORRELATED, 10, 3000000, diff --git a/cpp/test/random/sample_without_replacement.cu b/cpp/test/random/sample_without_replacement.cu index 482b35168a..355df1fcc1 100644 --- a/cpp/test/random/sample_without_replacement.cu +++ b/cpp/test/random/sample_without_replacement.cu @@ -17,6 +17,7 @@ #include "../test_utils.h" #include #include +#include #include #include #include diff --git a/docs/source/cpp_api.rst b/docs/source/cpp_api.rst index 569fd64061..337ed8d720 100644 --- a/docs/source/cpp_api.rst +++ b/docs/source/cpp_api.rst @@ -14,7 +14,7 @@ C++ API Reference cpp_api/matrix.rst cpp_api/mdspan.rst cpp_api/neighbors.rst - cpp_api/solver.rst cpp_api/random.rst + cpp_api/solver.rst cpp_api/sparse.rst cpp_api/stats.rst \ No newline at end of file diff --git a/docs/source/cpp_api/cluster.rst b/docs/source/cpp_api/cluster.rst index 6fdc1c696f..777977a488 100644 --- a/docs/source/cpp_api/cluster.rst +++ b/docs/source/cpp_api/cluster.rst @@ -11,7 +11,7 @@ fundamental clustering algorithms which are, themselves, considered reusable bui K-Means ####### -Header: `raft/cluster/kmeans.cuh` +``#include `` .. doxygennamespace:: raft::cluster::kmeans :project: RAFT @@ -22,7 +22,7 @@ Header: `raft/cluster/kmeans.cuh` Hierarchical Clustering ####################### -Header: `raft/cluster/single_linkage.cuh` +``#include `` .. doxygennamespace:: raft::cluster::hierarchy :project: RAFT @@ -33,7 +33,7 @@ Header: `raft/cluster/single_linkage.cuh` Spectral Clustering ################### -Header: `raft/spectral/partition.cuh` +``#include `` .. doxygennamespace:: raft::spectral :project: RAFT diff --git a/docs/source/cpp_api/core.rst b/docs/source/cpp_api/core.rst index 68965053de..8bf9051739 100644 --- a/docs/source/cpp_api/core.rst +++ b/docs/source/cpp_api/core.rst @@ -14,7 +14,7 @@ expose in public APIs. handle_t ######## -Header: `raft/core/handle.hpp` +#include .. doxygenclass:: raft::handle_t :project: RAFT @@ -24,16 +24,17 @@ Header: `raft/core/handle.hpp` Interruptible ############# -Header: `raft/core/interupptible.hpp` +``#include `` .. doxygenclass:: raft::interruptible :project: RAFT :members: + NVTX #### -Header: `raft/core/nvtx.hpp` +``#include `` .. doxygennamespace:: raft::common::nvtx :project: RAFT @@ -44,7 +45,7 @@ Header: `raft/core/nvtx.hpp` Key-Value Pair ############## -Header: `raft/core/kvp.hpp` +``#include `` .. doxygenstruct:: raft::KeyValuePair :project: RAFT @@ -54,7 +55,7 @@ Header: `raft/core/kvp.hpp` logger ###### -Header: `raft/core/logger.hpp` +``#include `` .. doxygenclass:: raft::logger :project: RAFT @@ -64,7 +65,7 @@ Header: `raft/core/logger.hpp` Multi-node Multi-GPU #################### -Header: `raft/core/comms.hpp` +``#include `` .. doxygennamespace:: raft::comms :project: RAFT diff --git a/docs/source/cpp_api/distance.rst b/docs/source/cpp_api/distance.rst index e77e311cdc..20b312a804 100644 --- a/docs/source/cpp_api/distance.rst +++ b/docs/source/cpp_api/distance.rst @@ -8,12 +8,39 @@ distances have been highly optimized and support a wide assortment of different :language: c++ :class: highlight +Distance Types +############## -Distance -######## +``#include `` + +namespace *raft::distance* + +.. doxygenenum:: raft::distance::DistanceType + :project: RAFT + + +Pairwise Distance +################# + +``#include `` + +namespace *raft::distance* -Header: `raft/distance/distance.cuh` +.. doxygengroup:: distance_mdspan + :project: RAFT + :members: + :content-only: + + +Fused 1-Nearest Neighbors +######################### -.. doxygennamespace:: raft::distance +``#include `` + +namespace *raft::distance* + +.. doxygengroup:: fused_l2_nn :project: RAFT :members: + :content-only: + diff --git a/docs/source/cpp_api/linalg.rst b/docs/source/cpp_api/linalg.rst index 081eb40298..3cd928c9db 100644 --- a/docs/source/cpp_api/linalg.rst +++ b/docs/source/cpp_api/linalg.rst @@ -10,8 +10,13 @@ hide the complexities of lower-level C-based libraries provided in the CUDA tool :language: c++ :class: highlight +.. toctree:: + :maxdepth: 2 + :caption: Contents: -.. doxygennamespace:: raft::linalg - :project: RAFT - :members: - :content-only: + linalg_arithmetic.rst + linalg_blas.rst + linalg_map_reduce.rst + linalg_matrix.rst + linalg_matrix_vector.rst + linalg_solver.rst \ No newline at end of file diff --git a/docs/source/cpp_api/linalg_arithmetic.rst b/docs/source/cpp_api/linalg_arithmetic.rst new file mode 100644 index 0000000000..496c30a796 --- /dev/null +++ b/docs/source/cpp_api/linalg_arithmetic.rst @@ -0,0 +1,122 @@ +Arithmetic +========== + +This page provides C++ class references for the publicly-exposed elements of the `raft/linalg` (dense) linear algebra headers. +In addition to providing highly optimized arithmetic and matrix/vector operations, RAFT provides a consistent user experience +by providing common BLAS routines, standard linear system solvers, factorization and eigenvalue solvers. Some of these routines +hide the complexities of lower-level C-based libraries provided in the CUDA toolkit + +.. role:: py(code) + :language: c++ + :class: highlight + + +Addition +-------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: add_dense + :project: RAFT + :members: + :content-only: + + +Binary Op +--------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: binary_op + :project: RAFT + :members: + :content-only: + +Division +-------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: divide + :project: RAFT + :members: + :content-only: + +Multiplication +-------------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: multiply + :project: RAFT + :members: + :content-only: + +Power +----- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: power + :project: RAFT + :members: + :content-only: + +Square Root +----------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: sqrt + :project: RAFT + :members: + :content-only: + +Subtraction +----------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: sub + :project: RAFT + :members: + :content-only: + +Ternary Op +---------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: ternary_op + :project: RAFT + :members: + :content-only: + +Unary Op +-------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: unary_op + :project: RAFT + :members: + :content-only: + diff --git a/docs/source/cpp_api/linalg_blas.rst b/docs/source/cpp_api/linalg_blas.rst new file mode 100644 index 0000000000..9dfd106ad9 --- /dev/null +++ b/docs/source/cpp_api/linalg_blas.rst @@ -0,0 +1,60 @@ +BLAS Routines +============= + +This page provides C++ class references for the publicly-exposed elements of the `raft/linalg` (dense) linear algebra headers. +In addition to providing highly optimized arithmetic and matrix/vector operations, RAFT provides a consistent user experience +by providing common BLAS routines, standard linear system solvers, factorization and eigenvalue solvers. Some of these routines +hide the complexities of lower-level C-based libraries provided in the CUDA toolkit + +.. role:: py(code) + :language: c++ + :class: highlight + +axpy +---- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: axpy + :project: RAFT + :members: + :content-only: + +dot +--- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: dot + :project: RAFT + :members: + :content-only: + +gemm +---- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: gemm + :project: RAFT + :members: + :content-only: + +gemv +---- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: gemv + :project: RAFT + :members: + :content-only: + diff --git a/docs/source/cpp_api/linalg_map_reduce.rst b/docs/source/cpp_api/linalg_map_reduce.rst new file mode 100644 index 0000000000..64b2a8f519 --- /dev/null +++ b/docs/source/cpp_api/linalg_map_reduce.rst @@ -0,0 +1,132 @@ +Mapping and Reduction +===================== + +This page provides C++ class references for the publicly-exposed elements of the `raft/linalg` (dense) linear algebra headers. +In addition to providing highly optimized arithmetic and matrix/vector operations, RAFT provides a consistent user experience +by providing common BLAS routines, standard linear system solvers, factorization and eigenvalue solvers. Some of these routines +hide the complexities of lower-level C-based libraries provided in the CUDA toolkit + +.. role:: py(code) + :language: c++ + :class: highlight + +Coalesced Reduction +------------------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: coalesced_reduction + :project: RAFT + :members: + :content-only: + +Map +--- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: map + :project: RAFT + :members: + :content-only: + +Map Reduce +---------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: map_reduce + :project: RAFT + :members: + :content-only: + +Mean Squared Error +------------------ + + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: mean_squared_error + :project: RAFT + :members: + :content-only: + +Norm +---- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: norm + :project: RAFT + :members: + :content-only: + +Normalize +--------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: normalize + :project: RAFT + :members: + :content-only: + +Reduction +--------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: reduction + :project: RAFT + :members: + :content-only: + +Reduce Cols By Key +------------------ + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: reduce_cols_by_key + :project: RAFT + :members: + :content-only: + +Reduce Rows By Key +------------------ + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: reduce_rows_by_key + :project: RAFT + :members: + :content-only: + +Strided Reduction +----------------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: strided_reduction + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/linalg_matrix.rst b/docs/source/cpp_api/linalg_matrix.rst new file mode 100644 index 0000000000..983adf5898 --- /dev/null +++ b/docs/source/cpp_api/linalg_matrix.rst @@ -0,0 +1,24 @@ +Matrix Operations +================= + +This page provides C++ class references for the publicly-exposed elements of the `raft/linalg` (dense) linear algebra headers. +In addition to providing highly optimized arithmetic and matrix/vector operations, RAFT provides a consistent user experience +by providing common BLAS routines, standard linear system solvers, factorization and eigenvalue solvers. Some of these routines +hide the complexities of lower-level C-based libraries provided in the CUDA toolkit + +.. role:: py(code) + :language: c++ + :class: highlight + +Transpose +--------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: transpose + :project: RAFT + :members: + :content-only: + diff --git a/docs/source/cpp_api/linalg_matrix_vector.rst b/docs/source/cpp_api/linalg_matrix_vector.rst new file mode 100644 index 0000000000..72c696fe70 --- /dev/null +++ b/docs/source/cpp_api/linalg_matrix_vector.rst @@ -0,0 +1,37 @@ +Matrix-Vector Operations +======================== + +This page provides C++ class references for the publicly-exposed elements of the `raft/linalg` (dense) linear algebra headers. +In addition to providing highly optimized arithmetic and matrix/vector operations, RAFT provides a consistent user experience +by providing common BLAS routines, standard linear system solvers, factorization and eigenvalue solvers. Some of these routines +hide the complexities of lower-level C-based libraries provided in the CUDA toolkit + +.. role:: py(code) + :language: c++ + :class: highlight + +Arithmetic +---------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: matrix_vector + :project: RAFT + :members: + :content-only: + + +Operations +---------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: matrix_vector_op + :project: RAFT + :members: + :content-only: + diff --git a/docs/source/cpp_api/linalg_solver.rst b/docs/source/cpp_api/linalg_solver.rst new file mode 100644 index 0000000000..d11e5f7801 --- /dev/null +++ b/docs/source/cpp_api/linalg_solver.rst @@ -0,0 +1,71 @@ +Linear Algebra Solvers +====================== + +This page provides C++ class references for the publicly-exposed elements of the `raft/linalg` (dense) linear algebra headers. +In addition to providing highly optimized arithmetic and matrix/vector operations, RAFT provides a consistent user experience +by providing common BLAS routines, standard linear system solvers, factorization and eigenvalue solvers. Some of these routines +hide the complexities of lower-level C-based libraries provided in the CUDA toolkit + +.. role:: py(code) + :language: c++ + :class: highlight + +Eigen Decomposition +------------------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: eig + :project: RAFT + :members: + :content-only: + +QR Decomposition +---------------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: qr + :project: RAFT + :members: + :content-only: + +Randomized Singular-Value Decomposition +--------------------------------------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: rsvd + :project: RAFT + :members: + :content-only: + +Singular-Value Decomposition +---------------------------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: svd + :project: RAFT + :members: + :content-only: + +Least Squares +------------- + +``#include `` + +namespace *raft::linalg* + +.. doxygengroup:: lstsq + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/matrix.rst b/docs/source/cpp_api/matrix.rst index b032281a1c..17953bc128 100644 --- a/docs/source/cpp_api/matrix.rst +++ b/docs/source/cpp_api/matrix.rst @@ -9,7 +9,12 @@ headers cover many operations on matrices that are otherwise not covered by `raf :class: highlight -.. doxygennamespace:: raft::matrix - :project: RAFT - :members: - :content-only: +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + matrix_arithmetic.rst + matrix_manipulation.rst + matrix_ordering.rst + matrix_reduction.rst + matrix_selection.rst \ No newline at end of file diff --git a/docs/source/cpp_api/matrix_arithmetic.rst b/docs/source/cpp_api/matrix_arithmetic.rst new file mode 100644 index 0000000000..c1fae55e83 --- /dev/null +++ b/docs/source/cpp_api/matrix_arithmetic.rst @@ -0,0 +1,83 @@ +Matrix Arithmetic +================= + +This page provides C++ class references for the publicly-exposed elements of the `raft/matrix` headers. The `raft/matrix` +headers cover many operations on matrices that are otherwise not covered by `raft/linalg`. + +.. role:: py(code) + :language: c++ + :class: highlight + + +Line-wise Operation +------------------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: linewise_op + :project: RAFT + :members: + :content-only: + +Power +----- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_power + :project: RAFT + :members: + :content-only: + +Ratio +----- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_ratio + :project: RAFT + :members: + :content-only: + +Reciprocal +---------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_reciprocal + :project: RAFT + :members: + :content-only: + +Sign-flip +--------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_sign_flip + :project: RAFT + :members: + :content-only: + + +Square Root +----------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_sqrt + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/matrix_manipulation.rst b/docs/source/cpp_api/matrix_manipulation.rst new file mode 100644 index 0000000000..f976e3ccd1 --- /dev/null +++ b/docs/source/cpp_api/matrix_manipulation.rst @@ -0,0 +1,47 @@ +Matrix Manipulation +=================== + +This page provides C++ class references for the publicly-exposed elements of the `raft/matrix` headers. The `raft/matrix` +headers cover many operations on matrices that are otherwise not covered by `raft/linalg`. + +.. role:: py(code) + :language: c++ + :class: highlight + +Initialization +-------------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_init + :project: RAFT + :members: + :content-only: + + +Reverse +------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_reverse + :project: RAFT + :members: + :content-only: + +Threshold +--------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_threshold + :project: RAFT + :members: + :content-only: + diff --git a/docs/source/cpp_api/matrix_ordering.rst b/docs/source/cpp_api/matrix_ordering.rst new file mode 100644 index 0000000000..52275ba5b4 --- /dev/null +++ b/docs/source/cpp_api/matrix_ordering.rst @@ -0,0 +1,45 @@ +Matrix Ordering +=============== + +This page provides C++ class references for the publicly-exposed elements of the `raft/matrix` headers. The `raft/matrix` +headers cover many operations on matrices that are otherwise not covered by `raft/linalg`. + +.. role:: py(code) + :language: c++ + :class: highlight + +Argmax +------ + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: argmax + :project: RAFT + :members: + :content-only: + +Argmin +------ + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: argmin + :project: RAFT + :members: + :content-only: + +Column-wise Sort +---------------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: col_wise_sort + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/matrix_reduction.rst b/docs/source/cpp_api/matrix_reduction.rst new file mode 100644 index 0000000000..fc1a1082aa --- /dev/null +++ b/docs/source/cpp_api/matrix_reduction.rst @@ -0,0 +1,22 @@ +Matrix Reductions +================= + +This page provides C++ class references for the publicly-exposed elements of the `raft/matrix` headers. The `raft/matrix` +headers cover many operations on matrices that are otherwise not covered by `raft/linalg`. + +.. role:: py(code) + :language: c++ + :class: highlight + + +Matrix Norm +----------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_norm + :project: RAFT + :members: + :content-only: \ No newline at end of file diff --git a/docs/source/cpp_api/matrix_selection.rst b/docs/source/cpp_api/matrix_selection.rst new file mode 100644 index 0000000000..d58f1542ec --- /dev/null +++ b/docs/source/cpp_api/matrix_selection.rst @@ -0,0 +1,72 @@ +Matrix Selection +================ + +This page provides C++ class references for the publicly-exposed elements of the `raft/matrix` headers. The `raft/matrix` +headers cover many operations on matrices that are otherwise not covered by `raft/linalg`. + +.. role:: py(code) + :language: c++ + :class: highlight + + +Copy +---- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_copy + :project: RAFT + :members: + :content-only: + +Diagonal +-------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_diagonal + :project: RAFT + :members: + :content-only: + + +Gather +------ + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_gather + :project: RAFT + :members: + :content-only: + + +Slicing +------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_slice + :project: RAFT + :members: + :content-only: + +Triangular +---------- + +``#include `` + +namespace *raft::matrix* + +.. doxygengroup:: matrix_triangular + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/mdspan.rst b/docs/source/cpp_api/mdspan.rst index 511ead8573..af38247c01 100644 --- a/docs/source/cpp_api/mdspan.rst +++ b/docs/source/cpp_api/mdspan.rst @@ -8,339 +8,11 @@ This page provides C++ class references for the RAFT's 1d span and multi-dimensi :class: highlight -Representation -############## - - -Layouts -------- - -.. doxygentypedef:: raft::row_major - :project: RAFT - -.. doxygentypedef:: raft::col_major - :project: RAFT - - -Shapes ------- - -.. doxygentypedef:: raft::matrix_extent - :project: RAFT - -.. doxygentypedef:: raft::vector_extent - :project: RAFT - -.. doxygentypedef:: raft::scalar_extent - :project: RAFT - -.. doxygentypedef:: raft::extent_3d - :project: RAFT - -.. doxygentypedef:: raft::extent_4d - :project: RAFT - -.. doxygentypedef:: raft::extent_5d - :project: RAFT - -.. doxygenfunction:: raft::flatten(mdspan_type mds) - :project: RAFT - -.. doxygenfunction:: raft:: flatten(const array_interface_type& mda) - :project: RAFT - -.. doxygenfunction:: raft::reshape(mdspan_type mds, extents new_shape) - :project: RAFT - -.. doxygenfunction:: raft::reshape(const array_interface_type& mda, extents new_shape) - :project: RAFT - - -Accessors ---------- - -.. doxygenstruct:: raft::host_device_accessor - :project: RAFT - :members: - -.. doxygentypedef:: raft::host_accessor - :project: RAFT - -.. doxygentypedef:: raft::device_accessor - :project: RAFT - -.. doxygentypedef:: raft::managed_accessor - :project: RAFT - - - - -mdarray -####### - -.. doxygenclass:: raft::mdarray - :project: RAFT - :members: - -.. doxygenclass:: raft::array_interface - :project: RAFT - :members: - -.. doxygenstruct:: raft::is_array_interface - :project: RAFT - :members: - -.. doxygentypedef:: raft::is_array_interface_t - :project RAFT - -Device Vocabulary ------------------ - -.. doxygentypedef:: raft::device_mdarray - :project: RAFT - -.. doxygentypedef:: raft::device_matrix - :project: RAFT - -.. doxygentypedef:: raft::device_vector - :project: RAFT - -.. doxygentypedef:: raft::device_scalar - :project: RAFT - - -Device Factories ----------------- - -.. doxygenfunction:: raft::make_device_matrix - :project: RAFT - -.. doxygenfunction:: raft::make_device_vector - :project: RAFT - -.. doxygenfunction:: raft::make_device_scalar - :project: RAFT - - -Host Vocabulary ---------------- - -.. doxygentypedef:: raft::host_matrix - :project: RAFT - -.. doxygentypedef:: raft::host_vector - :project: RAFT - -.. doxygentypedef:: raft::host_scalar - :project: RAFT - - -Host Factories --------------- - -.. doxygenfunction:: raft::make_host_matrix - :project: RAFT - -.. doxygenfunction:: raft::make_host_vector - :project: RAFT - -.. doxygenfunction:: raft::make_device_scalar - :project: RAFT - -mdspan -###### - -.. doxygentypedef:: raft::mdspan - :project: RAFT - -.. doxygenfunction:: raft::make_mdspan - :project: RAFT - -.. doxygenfunction:: raft::make_extents - :project: RAFT - -.. doxygenfunction:: raft::make_strided_layout(Extents extents, Strides strides) - :project: RAFT - -.. doxygenfunction:: raft::unravel_index - :project: RAFT - - -Device Vocabulary ------------------ - -.. doxygentypedef:: raft::device_mdspan - :project: RAFT - -.. doxygenstruct:: raft::is_device_mdspan - :project: RAFT - -.. doxygentypedef:: raft::is_device_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::is_input_device_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::is_output_device_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::enable_if_device_mdspan - :project: RAFT - -.. doxygentypedef:: raft::enable_if_input_device_mdspan - :project: RAFT - -.. doxygentypedef:: raft::enable_if_output_device_mdspan - :project: RAFT - -.. doxygentypedef:: raft::device_matrix_view - :project: RAFT - -.. doxygentypedef:: raft::device_vector_view - :project: RAFT - -.. doxygentypedef:: raft::device_scalar_view - :project: RAFT - - -Device Factories ----------------- - -.. doxygenfunction:: raft::make_device_matrix_view - :project: RAFT - -.. doxygenfunction:: raft::make_device_vector_view(ElementType* ptr, IndexType n) - :project: RAFT - -.. doxygenfunction:: raft::make_device_scalar_view - :project: RAFT - - -Managed Vocabulary ------------------- - -..doxygentypedef:: raft::managed_mdspan - :project: RAFT - -.. doxygenstruct:: raft::is_managed_mdspan - :project: RAFT - -.. doxygentypedef:: raft::is_managed_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::is_input_managed_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::is_output_managed_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::enable_if_managed_mdspan - :project: RAFT - -.. doxygentypedef:: raft::enable_if_input_managed_mdspan - :project: RAFT - -.. doxygentypedef:: raft::enable_if_output_managed_mdspan - :project: RAFT - - -Managed Factories ------------------ - -.. doxygenfunction:: make_managed_mdspan(ElementType* ptr, extents exts) - - -Host Vocabulary ---------------- - -.. doxygentypedef:: raft::host_mdspan - :project: RAFT - -.. doxygenstruct:: raft::is_host_mdspan - :project: RAFT - -.. doxygentypedef:: raft::is_host_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::is_input_host_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::is_output_host_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::enable_if_host_mdspan - :project: RAFT - -.. doxygentypedef:: raft::enable_if_input_host_mdspan - :project: RAFT - -.. doxygentypedef:: raft::enable_if_output_host_mdspan - :project: RAFT - -.. doxygentypedef:: raft::host_matrix_view - :project: RAFT - -.. doxygentypedef:: raft::host_vector_view - :project: RAFT - -.. doxygentypedef:: raft::host_scalar_view - :project: RAFT - -Host Factories --------------- - -.. doxygenfunction:: raft::make_host_matrix_view - :project: RAFT - -.. doxygenfunction:: raft::make_host_vector_view - :project: RAFT - -.. doxygenfunction:: raft::make_device_scalar_view - :project: RAFT - - -Validation Routines -------------------- - -.. doxygenstruct:: raft::is_mdspan - :project: RAFT - :members: - -.. doxygentypedef:: raft::is_mdspan_t - :project: RAFT - -.. doxygenstruct:: raft::is_input_mdspan - :project: RAFT - :members: - -.. doxygentypedef:: raft::is_input_mdspan_t - :project: RAFT - -.. doxygenstruct:: raft::is_output_mdspan - :project: RAFT - :members: - -.. doxygentypedef:: raft::is_output_mdspan_t - :project: RAFT - -.. doxygentypedef:: raft::enable_if_mdspan - :project: RAFT - -.. doxygentypedef:: raft::enable_if_input_mdspan - :project: RAFT - -.. doxygentypedef:: raft::enable_if_output_mdspan - :project: RAFT - -span -#### - -.. doxygentypedef:: raft::device_span - :project: RAFT - -.. doxygentypedef:: raft::host_span - :project: RAFT - -.. doxygenclass:: raft::span - :project: RAFT - :members: +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + mdspan_representation.rst + mdspan_mdspan.rst + mdspan_mdarray.rst + mdspan_span.rst diff --git a/docs/source/cpp_api/mdspan_mdarray.rst b/docs/source/cpp_api/mdspan_mdarray.rst new file mode 100644 index 0000000000..2194060914 --- /dev/null +++ b/docs/source/cpp_api/mdspan_mdarray.rst @@ -0,0 +1,87 @@ +mdarray: Multi-dimensional Owning Container +=========================================== + +This page provides C++ class references for the RAFT's 1d span and multi-dimension owning (mdarray) and non-owning (mdspan) APIs. These headers can be found in the `raft/core` directory. + +.. role:: py(code) + :language: c++ + :class: highlight + +``#include `` + +.. doxygenclass:: raft::mdarray + :project: RAFT + :members: + +.. doxygenclass:: raft::array_interface + :project: RAFT + :members: + +.. doxygenstruct:: raft::is_array_interface + :project: RAFT + :members: + +.. doxygentypedef:: raft::is_array_interface_t + :project RAFT + +Device Vocabulary +----------------- + +``#include `` + +.. doxygentypedef:: raft::device_mdarray + :project: RAFT + +.. doxygentypedef:: raft::device_matrix + :project: RAFT + +.. doxygentypedef:: raft::device_vector + :project: RAFT + +.. doxygentypedef:: raft::device_scalar + :project: RAFT + + +Device Factories +---------------- + +``#include `` + +.. doxygenfunction:: raft::make_device_matrix + :project: RAFT + +.. doxygenfunction:: raft::make_device_vector + :project: RAFT + +.. doxygenfunction:: raft::make_device_scalar + :project: RAFT + + +Host Vocabulary +--------------- + +``#include `` + +.. doxygentypedef:: raft::host_matrix + :project: RAFT + +.. doxygentypedef:: raft::host_vector + :project: RAFT + +.. doxygentypedef:: raft::host_scalar + :project: RAFT + + +Host Factories +-------------- + +``#include `` + +.. doxygenfunction:: raft::make_host_matrix + :project: RAFT + +.. doxygenfunction:: raft::make_host_vector + :project: RAFT + +.. doxygenfunction:: raft::make_device_scalar + :project: RAFT diff --git a/docs/source/cpp_api/mdspan_mdspan.rst b/docs/source/cpp_api/mdspan_mdspan.rst new file mode 100644 index 0000000000..b34fda16bb --- /dev/null +++ b/docs/source/cpp_api/mdspan_mdspan.rst @@ -0,0 +1,207 @@ +mdspan: Multi-dimensional Non-owning View +========================================== + +This page provides C++ class references for the RAFT's 1d span and multi-dimensional owning (mdarray) and non-owning (mdspan) APIs. These headers can be found in the `raft/core` directory. + +.. role:: py(code) + :language: c++ + :class: highlight + +``#include `` + +.. doxygentypedef:: raft::mdspan + :project: RAFT + +.. doxygenfunction:: raft::make_mdspan + :project: RAFT + +.. doxygenfunction:: raft::make_extents + :project: RAFT + +.. doxygenfunction:: raft::make_strided_layout(Extents extents, Strides strides) + :project: RAFT + +.. doxygenfunction:: raft::unravel_index + :project: RAFT + + +Device Vocabulary +----------------- + +``#include `` + +.. doxygentypedef:: raft::device_mdspan + :project: RAFT + +.. doxygenstruct:: raft::is_device_mdspan + :project: RAFT + +.. doxygentypedef:: raft::is_device_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::is_input_device_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::is_output_device_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::enable_if_device_mdspan + :project: RAFT + +.. doxygentypedef:: raft::enable_if_input_device_mdspan + :project: RAFT + +.. doxygentypedef:: raft::enable_if_output_device_mdspan + :project: RAFT + +.. doxygentypedef:: raft::device_matrix_view + :project: RAFT + +.. doxygentypedef:: raft::device_vector_view + :project: RAFT + +.. doxygentypedef:: raft::device_scalar_view + :project: RAFT + + +Device Factories +---------------- + +``#include `` + +.. doxygenfunction:: raft::make_device_matrix_view + :project: RAFT + +.. doxygenfunction:: raft::make_device_vector_view(ElementType* ptr, IndexType n) + :project: RAFT + +.. doxygenfunction:: raft::make_device_scalar_view + :project: RAFT + + +Managed Vocabulary +------------------ + +``#include `` + +..doxygentypedef:: raft::managed_mdspan + :project: RAFT + +.. doxygenstruct:: raft::is_managed_mdspan + :project: RAFT + +.. doxygentypedef:: raft::is_managed_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::is_input_managed_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::is_output_managed_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::enable_if_managed_mdspan + :project: RAFT + +.. doxygentypedef:: raft::enable_if_input_managed_mdspan + :project: RAFT + +.. doxygentypedef:: raft::enable_if_output_managed_mdspan + :project: RAFT + + +Managed Factories +----------------- + +``#include `` + +.. doxygenfunction:: make_managed_mdspan(ElementType* ptr, extents exts) + :project: RAFT + + +Host Vocabulary +--------------- + +``#include `` + +.. doxygentypedef:: raft::host_mdspan + :project: RAFT + +.. doxygenstruct:: raft::is_host_mdspan + :project: RAFT + +.. doxygentypedef:: raft::is_host_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::is_input_host_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::is_output_host_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::enable_if_host_mdspan + :project: RAFT + +.. doxygentypedef:: raft::enable_if_input_host_mdspan + :project: RAFT + +.. doxygentypedef:: raft::enable_if_output_host_mdspan + :project: RAFT + +.. doxygentypedef:: raft::host_matrix_view + :project: RAFT + +.. doxygentypedef:: raft::host_vector_view + :project: RAFT + +.. doxygentypedef:: raft::host_scalar_view + :project: RAFT + +Host Factories +-------------- + +``#include `` + +.. doxygenfunction:: raft::make_host_matrix_view + :project: RAFT + +.. doxygenfunction:: raft::make_host_vector_view + :project: RAFT + +.. doxygenfunction:: raft::make_device_scalar_view + :project: RAFT + + +Validation Routines +------------------- + +``#include `` + +.. doxygenstruct:: raft::is_mdspan + :project: RAFT + :members: + +.. doxygentypedef:: raft::is_mdspan_t + :project: RAFT + +.. doxygenstruct:: raft::is_input_mdspan + :project: RAFT + :members: + +.. doxygentypedef:: raft::is_input_mdspan_t + :project: RAFT + +.. doxygenstruct:: raft::is_output_mdspan + :project: RAFT + :members: + +.. doxygentypedef:: raft::is_output_mdspan_t + :project: RAFT + +.. doxygentypedef:: raft::enable_if_mdspan + :project: RAFT + +.. doxygentypedef:: raft::enable_if_input_mdspan + :project: RAFT + +.. doxygentypedef:: raft::enable_if_output_mdspan + :project: RAFT diff --git a/docs/source/cpp_api/mdspan_representation.rst b/docs/source/cpp_api/mdspan_representation.rst new file mode 100644 index 0000000000..d71c23dcba --- /dev/null +++ b/docs/source/cpp_api/mdspan_representation.rst @@ -0,0 +1,76 @@ +Multi-dimensional Representation +================================ + +This page provides C++ class references for the RAFT's 1d span and multi-dimension owning (mdarray) and non-owning (mdspan) APIs. These headers can be found in the `raft/core` directory. + +.. role:: py(code) + :language: c++ + :class: highlight + +Data Layouts +------------- + +``#include `` + +.. doxygentypedef:: raft::row_major + :project: RAFT + +.. doxygentypedef:: raft::col_major + :project: RAFT + + +Shapes +------ + +``#include `` + +.. doxygentypedef:: raft::matrix_extent + :project: RAFT + +.. doxygentypedef:: raft::vector_extent + :project: RAFT + +.. doxygentypedef:: raft::scalar_extent + :project: RAFT + +.. doxygentypedef:: raft::extent_3d + :project: RAFT + +.. doxygentypedef:: raft::extent_4d + :project: RAFT + +.. doxygentypedef:: raft::extent_5d + :project: RAFT + +.. doxygenfunction:: raft::flatten(mdspan_type mds) + :project: RAFT + +.. doxygenfunction:: raft:: flatten(const array_interface_type& mda) + :project: RAFT + +.. doxygenfunction:: raft::reshape(mdspan_type mds, extents new_shape) + :project: RAFT + +.. doxygenfunction:: raft::reshape(const array_interface_type& mda, extents new_shape) + :project: RAFT + + +Accessors +--------- + +``#include `` + +.. doxygenstruct:: raft::host_device_accessor + :project: RAFT + :members: + +.. doxygentypedef:: raft::host_accessor + :project: RAFT + +.. doxygentypedef:: raft::device_accessor + :project: RAFT + +.. doxygentypedef:: raft::managed_accessor + :project: RAFT + + diff --git a/docs/source/cpp_api/mdspan_span.rst b/docs/source/cpp_api/mdspan_span.rst new file mode 100644 index 0000000000..e633e38445 --- /dev/null +++ b/docs/source/cpp_api/mdspan_span.rst @@ -0,0 +1,25 @@ +span: One-dimensional Non-owning View +===================================== + +This page provides C++ class references for the RAFT's 1d span and multi-dimension owning (mdarray) and non-owning (mdspan) APIs. These headers can be found in the `raft/core` directory. + +.. role:: py(code) + :language: c++ + :class: highlight + +``#include `` + +.. doxygenclass:: raft::span + :project: RAFT + :members: + +``#include `` + +.. doxygentypedef:: raft::device_span + :project: RAFT + +``#include `` + +.. doxygentypedef:: raft::host_span + :project: RAFT + diff --git a/docs/source/cpp_api/neighbors.rst b/docs/source/cpp_api/neighbors.rst index 93eecf68b4..afe3fd6263 100644 --- a/docs/source/cpp_api/neighbors.rst +++ b/docs/source/cpp_api/neighbors.rst @@ -11,9 +11,11 @@ This page provides C++ class references for the publicly-exposed elements of the Brute-force ----------- -Header: `raft/neighbors/brute_force.cuh` +``#include `` -.. doxygennamespace:: raft::neighbors::brute_force +namespace *raft::neighbors::brute_force* + +.. doxygengroup:: brute_force_knn :project: RAFT :members: :content-only: @@ -22,9 +24,11 @@ Header: `raft/neighbors/brute_force.cuh` IVF-Flat -------- -Header: `raft/neighbors/ivf_flat.cuh` +``#include `` + +namespace *raft::neighbors::ivf_flat* -.. doxygennamespace:: raft::neighbors::ivf_flat +.. doxygengroup:: ivf_flat :project: RAFT :members: :content-only: @@ -33,20 +37,23 @@ Header: `raft/neighbors/ivf_flat.cuh` IVF-PQ -------- -Header: `raft/neighbors/ivf_pq.cuh` +``#include `` -.. doxygennamespace:: raft::neighbors::ivf_pq +namespace *raft::neighbors::ivf_pq* + +.. doxygengroup:: ivf_pq :project: RAFT :members: :content-only: - Epsilon Neighborhood -------------------- -Header: `raft/neighbors/epsilon_neighborhood.cuh` +``#include `` -.. doxygennamespace:: raft::neighbors::epsilon_neighborhood +namespace *raft::neighbors::epsilon_neighborhood* + +.. doxygengroup:: epsilon_neighbors :project: RAFT :members: :content-only: @@ -55,9 +62,13 @@ Header: `raft/neighbors/epsilon_neighborhood.cuh` Random Ball Cover ----------------- -Header: `raft/neighbors/ball_cover.cuh` +``#include `` + +namespace *raft::neighbors::ball_cover* -.. doxygennamespace:: raft::neighbors::ball_cover +.. doxygengroup:: random_ball_cover :project: RAFT :members: :content-only: + + diff --git a/docs/source/cpp_api/random.rst b/docs/source/cpp_api/random.rst index 353f783ed4..bfff60def5 100644 --- a/docs/source/cpp_api/random.rst +++ b/docs/source/cpp_api/random.rst @@ -7,105 +7,22 @@ This page provides C++ class references for the publicly-exposed elements of the :language: c++ :class: highlight -Header: `raft/random/rng_state.hpp` +Random State +############ -.. doxygenstruct:: raft::random::RngState - :project: RAFT - :members: - - -Data Generation -############### - -make_blobs ----------- - -Header: `raft/random/make_blobs.cuh` - -.. doxygenfunction:: raft::random::make_blobs(raft::handle_t const& handle, raft::device_matrix_view out, raft::device_vector_view labels, IdxT n_clusters, std::optional> centers, std::optional> const cluster_std, const DataT cluster_std_scalar, bool shuffle, DataT center_box_min, DataT center_box_max, uint64_t seed, GeneratorType type) - :project: RAFT - -make_regression ---------------- - -Header: `raft/random/make_regression.cuh` - -.. doxygenfunction:: raft::random::make_regression(const raft::handle_t& handle, raft::device_matrix_view out, raft::device_matrix_view values, IdxT n_informative, std::optional> coef, DataT bias, IdxT effective_rank, DataT tail_strength, DataT noise, bool shuffle, uint64_t seed, GeneratorType type) - :project: RAFT - -rmat ----- +``#include `` -Header: `raft/random/rmat_rectangular_generator.cuh` - -.. doxygenfunction:: raft::random::rmat_rectangular_gen(const raft::handle_t& handle, raft::random::RngState& r, raft::device_vector_view theta, raft::device_mdspan, raft::row_major> out, raft::device_vector_view out_src, raft::device_vector_view out_dst, IdxT r_scale, IdxT c_scale) - :project: RAFT - - -Random Sampling -############### - -Distributions -------------- - -Header: `raft/random/rng.cuh` - -.. doxygenfunction:: raft::random::uniform(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType start, OutputValueType end) - :project: RAFT - -.. doxygenfunction:: raft::random::uniformInt(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType start, OutputValueType end) - :project: RAFT - -.. doxygenfunction:: raft::random::normal(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType sigma) - :project: RAFT - -.. doxygenfunction:: raft::random::normalInt(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType sigma) - :project: RAFT +namespace *raft::random* -.. doxygenfunction:: raft::random::normalTable(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view mu_vec, std::variant, OutputValueType> sigma, raft::device_matrix_view out) - :project: RAFT - -.. doxygenfunction:: raft::random::fill(const raft::handle_t& handle, RngState& rng_state, OutputValueType val, raft::device_vector_view out) - :project: RAFT - -.. doxygenfunction:: raft::random::bernoulli(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, Type prob) - :project: RAFT - -.. doxygenfunction:: raft::random::scaled_bernoulli(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType prob, OutputValueType scale) - :project: RAFT - -.. doxygenfunction:: raft::random::gumbel(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType beta) - :project: RAFT - -.. doxygenfunction:: raft::random::lognormal(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType sigma) - :project: RAFT - -.. doxygenfunction:: raft::random::logistic(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType scale) - :project: RAFT - -.. doxygenfunction:: raft::random::exponential(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType lambda) - :project: RAFT - -.. doxygenfunction:: raft::random::rayleigh(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType sigma) - :project: RAFT - -.. doxygenfunction:: raft::random::laplace(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType scale) - :project: RAFT - - -Sampling Without Replacement ----------------------------- - -Header: `raft/random/rng.cuh` - -.. doxygengroup:: sample_without_replacement +.. doxygenstruct:: raft::random::RngState :project: RAFT :members: - :content-only: - -Header: `raft/random/permute.cuh` - -.. doxygenfunction:: raft::random::permute(const raft::handle_t& handle, raft::device_matrix_view in, std::optional> permsOut, std::optional> out) - :project: RAFT +.. toctree:: + :maxdepth: 2 + :caption: Contents: + random_datagen.rst + random_sampling_univariate.rst + random_samling_multivariable.rst + random_sampling_without_replacement.rst diff --git a/docs/source/cpp_api/random_datagen.rst b/docs/source/cpp_api/random_datagen.rst new file mode 100644 index 0000000000..0075f1b076 --- /dev/null +++ b/docs/source/cpp_api/random_datagen.rst @@ -0,0 +1,48 @@ +Data Generation +=============== + +This page provides C++ class references for the publicly-exposed elements of the random package. + +.. role:: py(code) + :language: c++ + :class: highlight + +make_blobs +---------- + +``#include `` + +namespace *raft::random* +2 +.. doxygengroup:: make_blobs + :project: RAFT + :members: + :content-only: + + + +make_regression +--------------- + +``#include `` + +namespace *raft::random* + +.. doxygengroup:: make_regression + :project: RAFT + :members: + :content-only: + + +rmat +---- + +``#include `` + +namespace *raft::random* + +.. doxygengroup:: rmat + :project: RAFT + :members: + :content-only: + diff --git a/docs/source/cpp_api/random_sampling_multivariable.rst b/docs/source/cpp_api/random_sampling_multivariable.rst new file mode 100644 index 0000000000..39950285d0 --- /dev/null +++ b/docs/source/cpp_api/random_sampling_multivariable.rst @@ -0,0 +1,21 @@ +Multi-Variable Random Sampling +============================== + +This page provides C++ class references for the publicly-exposed elements of the random package. + +.. role:: py(code) + :language: c++ + :class: highlight + + +Multi-Variable Gaussian +----------------------- + +``#include `` + +namespace *raft::random* + +.. doxygengroup:: multi_variable_gaussian + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/random_sampling_univariate.rst b/docs/source/cpp_api/random_sampling_univariate.rst new file mode 100644 index 0000000000..7a08f58dad --- /dev/null +++ b/docs/source/cpp_api/random_sampling_univariate.rst @@ -0,0 +1,59 @@ +Univariate Random Sampling +========================== + +This page provides C++ class references for the publicly-exposed elements of the random package. + +.. role:: py(code) + :language: c++ + :class: highlight + +``#include `` + +namespace *raft::random* + +.. doxygenfunction:: raft::random::uniform(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType start, OutputValueType end) + :project: RAFT + +.. doxygenfunction:: raft::random::uniformInt(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType start, OutputValueType end) + :project: RAFT + +.. doxygenfunction:: raft::random::normal(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType sigma) + :project: RAFT + +.. doxygenfunction:: raft::random::normalInt(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType sigma) + :project: RAFT + +.. doxygenfunction:: raft::random::normalTable(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view mu_vec, std::variant, OutputValueType> sigma, raft::device_matrix_view out) + :project: RAFT + +.. doxygenfunction:: raft::random::fill(const raft::handle_t& handle, RngState& rng_state, OutputValueType val, raft::device_vector_view out) + :project: RAFT + +.. doxygenfunction:: raft::random::bernoulli(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, Type prob) + :project: RAFT + +.. doxygenfunction:: raft::random::scaled_bernoulli(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType prob, OutputValueType scale) + :project: RAFT + +.. doxygenfunction:: raft::random::gumbel(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType beta) + :project: RAFT + +.. doxygenfunction:: raft::random::lognormal(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType sigma) + :project: RAFT + +.. doxygenfunction:: raft::random::logistic(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType scale) + :project: RAFT + +.. doxygenfunction:: raft::random::exponential(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType lambda) + :project: RAFT + +.. doxygenfunction:: raft::random::rayleigh(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType sigma) + :project: RAFT + +.. doxygenfunction:: raft::random::laplace(const raft::handle_t& handle, RngState& rng_state, raft::device_vector_view out, OutputValueType mu, OutputValueType scale) + :project: RAFT + +.. doxygenfunction:: raft::random::discrete + :project: RAFT + + diff --git a/docs/source/cpp_api/random_sampling_without_replacement.rst b/docs/source/cpp_api/random_sampling_without_replacement.rst new file mode 100644 index 0000000000..ea78d312b7 --- /dev/null +++ b/docs/source/cpp_api/random_sampling_without_replacement.rst @@ -0,0 +1,28 @@ +Sampling Without Replacement +============================ + +This page provides C++ class references for the publicly-exposed elements of the random package. + +.. role:: py(code) + :language: c++ + :class: highlight + +``#include `` + +namespace *raft::random* + +.. doxygengroup:: sample_without_replacement + :project: RAFT + :members: + :content-only: + +``#include `` + +namespace *raft::random* + +.. doxygengroup:: permute + :project: RAFT + :members: + :content-only: + + diff --git a/docs/source/cpp_api/solver.rst b/docs/source/cpp_api/solver.rst index d03f3bb1eb..4b939eef49 100644 --- a/docs/source/cpp_api/solver.rst +++ b/docs/source/cpp_api/solver.rst @@ -11,7 +11,7 @@ This page provides C++ class references for the publicly-exposed elements of the Linear Assignment Problem ######################### -Header: `raft/solver/linear_assignment.cuh` +``#include `` .. doxygenclass:: raft::solver::LinearAssignmentProblem :project: RAFT @@ -20,7 +20,7 @@ Header: `raft/solver/linear_assignment.cuh` Minimum Spanning Tree ##################### -Header: `raft/sparse/solver/mst.cuh` +``#include `` .. doxygenfunction:: raft::sparse::solver::mst :project: RAFT diff --git a/docs/source/cpp_api/sparse.rst b/docs/source/cpp_api/sparse.rst index ea29dbebd0..2e2bae6253 100644 --- a/docs/source/cpp_api/sparse.rst +++ b/docs/source/cpp_api/sparse.rst @@ -8,42 +8,13 @@ This page provides C++ class references for the publicly-exposed elements of the :class: highlight -Conversion -########## +.. toctree:: + :maxdepth: 2 + :caption: Contents: -.. doxygennamespace:: raft::sparse::convert - :project: RAFT - :members: - :content-only: + sparse_distance.rst + sparse_linalg.rst + sparse_matrix.rst + sparse_neighbors.rst + sparse_solver.rst -Distance -######## - -.. doxygennamespace:: raft::sparse::distance - :project: RAFT - :members: - :content-only: - -Linear Algebra -############## - -.. doxygennamespace:: raft::sparse::linalg - :project: RAFT - :members: - :content-only: - -Matrix Operations -################# - -.. doxygennamespace:: raft::sparse::op - :project: RAFT - :members: - :content-only: - -Neighbors -######### - -.. doxygennamespace:: raft::sparse::neighbors - :project: RAFT - :members: - :content-only: diff --git a/docs/source/cpp_api/sparse_distance.rst b/docs/source/cpp_api/sparse_distance.rst new file mode 100644 index 0000000000..e85e43695d --- /dev/null +++ b/docs/source/cpp_api/sparse_distance.rst @@ -0,0 +1,7 @@ +Sparse Distance +=============== + +.. doxygennamespace:: raft::sparse::distance + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/sparse_linalg.rst b/docs/source/cpp_api/sparse_linalg.rst new file mode 100644 index 0000000000..6b20ee6c61 --- /dev/null +++ b/docs/source/cpp_api/sparse_linalg.rst @@ -0,0 +1,7 @@ +Sparse Linear Algebra +===================== + +.. doxygennamespace:: raft::sparse::linalg + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/sparse_matrix.rst b/docs/source/cpp_api/sparse_matrix.rst new file mode 100644 index 0000000000..18c5fea269 --- /dev/null +++ b/docs/source/cpp_api/sparse_matrix.rst @@ -0,0 +1,7 @@ +Sparse Matrix Operations +======================== + +.. doxygennamespace:: raft::sparse::op + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/sparse_neighbors.rst b/docs/source/cpp_api/sparse_neighbors.rst new file mode 100644 index 0000000000..9610913da6 --- /dev/null +++ b/docs/source/cpp_api/sparse_neighbors.rst @@ -0,0 +1,7 @@ +Sparse Neighbors +================ + +.. doxygennamespace:: raft::sparse::neighbors + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/sparse_solver.rst b/docs/source/cpp_api/sparse_solver.rst new file mode 100644 index 0000000000..d6df5493a3 --- /dev/null +++ b/docs/source/cpp_api/sparse_solver.rst @@ -0,0 +1,7 @@ +Sparse Solvers +============== + +.. doxygennamespace:: raft::sparse::solver + :project: RAFT + :members: + :content-only: diff --git a/docs/source/cpp_api/stats.rst b/docs/source/cpp_api/stats.rst index f795b9e84c..e96f627f81 100644 --- a/docs/source/cpp_api/stats.rst +++ b/docs/source/cpp_api/stats.rst @@ -7,8 +7,319 @@ This page provides C++ class references for the publicly-exposed elements of the :language: c++ :class: highlight +Summary Statistics +################## -.. doxygennamespace:: raft::stats +Covariance +---------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_cov + :project: RAFT + :members: + :content-only: + +Histogram +--------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_histogram + :project: RAFT + :members: + :content-only: + +Mean +---- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_mean + :project: RAFT + :members: + :content-only: + +Mean Center +----------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_mean_center + :project: RAFT + :members: + :content-only: + +Mean Variance +------------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_mean_var + :project: RAFT + :members: + :content-only: + +Min/Max +------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_minmax + :project: RAFT + :members: + :content-only: + +Standard Deviation +------------------ + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_stddev + :project: RAFT + :members: + :content-only: + +Sum +--- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_sum + :project: RAFT + :members: + :content-only: + +Weighted Average +---------------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_weighted_mean + :project: RAFT + :members: + :content-only: + + +Information Theory & Probability +################################ + +Contingency Matrix +------------------ + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: contingency_matrix + :project: RAFT + :members: + :content-only: + +Entropy +------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_entropy + :project: RAFT + :members: + :content-only: + + +KL-Divergence +------------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: kl_divergence + :project: RAFT + :members: + :content-only: + +Mutual Information +------------------ + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_mutual_info + :project: RAFT + :members: + :content-only: + + +Regression Model Scoring +######################## + +Information Criterion +--------------------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_information_criterion + :project: RAFT + :members: + :content-only: + +R2 Score +-------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_r2_score + :project: RAFT + :members: + :content-only: + + +Regression Metrics +------------------ + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_regression_metrics + :project: RAFT + :members: + :content-only: + + +Classification Model Scoring +############################ + +Accuracy +-------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_accuracy + :project: RAFT + :members: + :content-only: + + +Clustering Model Scoring +######################## + +Adjusted Rand Index +------------------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_adj_rand_index + :project: RAFT + :members: + :content-only: + +Completeness Score +------------------ + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_completeness + :project: RAFT + :members: + :content-only: + +Cluster Dispersion +------------------ + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_cluster_dispersion + :project: RAFT + :members: + :content-only: + + +Rand Index +---------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_rand_index + :project: RAFT + :members: + :content-only: + +Silhouette Score +---------------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_silhouette_score + :project: RAFT + :members: + :content-only: + + +V Measure +--------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_vmeasure + :project: RAFT + :members: + :content-only: + + + + +Neighborhood Model Scoring +########################## + +Trustworthiness +--------------- + +``#include `` + +namespace *raft::stats* + +.. doxygengroup:: stats_trustworthiness :project: RAFT :members: :content-only: diff --git a/docs/source/pylibraft_api.rst b/docs/source/pylibraft_api.rst index 5c44c5f419..6d07c89311 100644 --- a/docs/source/pylibraft_api.rst +++ b/docs/source/pylibraft_api.rst @@ -7,8 +7,8 @@ PyLibRAFT API Reference .. toctree:: :maxdepth: 4 - pylibraft_api/common.rst pylibraft_api/cluster.rst + pylibraft_api/common.rst pylibraft_api/distance.rst pylibraft_api/neighbors.rst - pylibraft_api/random.rst \ No newline at end of file + pylibraft_api/random.rst diff --git a/docs/source/pylibraft_api/cluster.rst b/docs/source/pylibraft_api/cluster.rst index 1a5aabf48a..c70fd46b2a 100644 --- a/docs/source/pylibraft_api/cluster.rst +++ b/docs/source/pylibraft_api/cluster.rst @@ -10,3 +10,4 @@ This page provides pylibraft class references for the publicly-exposed elements .. autofunction:: pylibraft.cluster.compute_new_centroids + diff --git a/docs/source/pylibraft_api/common.rst b/docs/source/pylibraft_api/common.rst index 4070243b22..812543f868 100644 --- a/docs/source/pylibraft_api/common.rst +++ b/docs/source/pylibraft_api/common.rst @@ -25,7 +25,9 @@ Interruptible ############# .. autofunction:: pylibraft.common.interruptible.cuda_interruptible + .. autofunction:: pylibraft.common.interruptible.synchronize + .. autofunction:: pylibraft.common.interruptible.cuda_yield diff --git a/docs/source/pylibraft_api/neighbors.rst b/docs/source/pylibraft_api/neighbors.rst index 7112a3878c..14046fa97a 100644 --- a/docs/source/pylibraft_api/neighbors.rst +++ b/docs/source/pylibraft_api/neighbors.rst @@ -8,11 +8,13 @@ This page provides pylibraft class references for the publicly-exposed elements :class: highlight .. autoclass:: pylibraft.neighbors.ivf_pq.IndexParams + :members: .. autofunction:: pylibraft.neighbors.ivf_pq.build .. autofunction:: pylibraft.neighbors.ivf_pq.extend .. autoclass:: pylibraft.neighbors.ivf_pq.SearchParams + :members: .. autofunction:: pylibraft.neighbors.ivf_pq.search diff --git a/docs/source/quick_start.md b/docs/source/quick_start.md index 60071f2461..d8cc5ce08b 100644 --- a/docs/source/quick_start.md +++ b/docs/source/quick_start.md @@ -134,7 +134,6 @@ n_features = 50 in1 = cp.random.random_sample((n_samples, n_features), dtype=cp.float32) in2 = cp.random.random_sample((n_samples, n_features), dtype=cp.float32) -output = cp.empty((n_samples, n_samples), dtype=cp.float32) -pairwise_distance(in1, in2, output, metric="euclidean") +output = pairwise_distance(in1, in2, metric="euclidean") ``` diff --git a/python/pylibraft/pylibraft/cpp/__init__.pxd b/python/pylibraft/pylibraft/cluster/cpp/__init__.pxd similarity index 100% rename from python/pylibraft/pylibraft/cpp/__init__.pxd rename to python/pylibraft/pylibraft/cluster/cpp/__init__.pxd diff --git a/python/pylibraft/pylibraft/cpp/__init__.py b/python/pylibraft/pylibraft/cluster/cpp/__init__.py similarity index 100% rename from python/pylibraft/pylibraft/cpp/__init__.py rename to python/pylibraft/pylibraft/cluster/cpp/__init__.py diff --git a/python/pylibraft/pylibraft/cpp/kmeans.pxd b/python/pylibraft/pylibraft/cluster/cpp/kmeans.pxd similarity index 79% rename from python/pylibraft/pylibraft/cpp/kmeans.pxd rename to python/pylibraft/pylibraft/cluster/cpp/kmeans.pxd index 9eb35bd71e..40f84cad40 100644 --- a/python/pylibraft/pylibraft/cpp/kmeans.pxd +++ b/python/pylibraft/pylibraft/cluster/cpp/kmeans.pxd @@ -24,14 +24,14 @@ from cython.operator cimport dereference as deref from libc.stdint cimport uintptr_t from libcpp cimport bool, nullptr +from pylibraft.cluster.cpp.kmeans_types cimport KMeansParams +from pylibraft.common.cpp.mdspan cimport * +from pylibraft.common.cpp.optional cimport optional from pylibraft.common.handle cimport handle_t -from pylibraft.cpp.kmeans_types cimport KMeansParams -from pylibraft.cpp.mdspan cimport * -from pylibraft.cpp.optional cimport optional -cdef extern from "raft_distance/kmeans.hpp" \ - namespace "raft::cluster::kmeans::runtime": +cdef extern from "raft_runtime/cluster/kmeans.hpp" \ + namespace "raft::runtime::cluster::kmeans": cdef void update_centroids( const handle_t& handle, @@ -78,17 +78,17 @@ cdef extern from "raft_distance/kmeans.hpp" \ cdef void fit( const handle_t & handle, const KMeansParams& params, - device_matrix_view[const float, int] X, - optional[device_vector_view[const float, int]] sample_weight, - device_matrix_view[float, int] inertia, + device_matrix_view[float, int, row_major] X, + optional[device_vector_view[float, int]] sample_weight, + device_matrix_view[float, int, row_major] inertia, host_scalar_view[float, int] inertia, host_scalar_view[int, int] n_iter) except + cdef void fit( const handle_t & handle, const KMeansParams& params, - device_matrix_view[const double, int] X, - optional[device_vector_view[const double, int]] sample_weight, - device_matrix_view[double, int] inertia, + device_matrix_view[double, int, row_major] X, + optional[device_vector_view[double, int]] sample_weight, + device_matrix_view[double, int, row_major] inertia, host_scalar_view[double, int] inertia, host_scalar_view[int, int] n_iter) except + diff --git a/python/pylibraft/pylibraft/cpp/kmeans_types.pxd b/python/pylibraft/pylibraft/cluster/cpp/kmeans_types.pxd similarity index 96% rename from python/pylibraft/pylibraft/cpp/kmeans_types.pxd rename to python/pylibraft/pylibraft/cluster/cpp/kmeans_types.pxd index 869d2cb5fd..12cecd4336 100644 --- a/python/pylibraft/pylibraft/cpp/kmeans_types.pxd +++ b/python/pylibraft/pylibraft/cluster/cpp/kmeans_types.pxd @@ -17,7 +17,7 @@ from libcpp cimport bool from pylibraft.distance.distance_type cimport DistanceType -from pylibraft.random.rng_state cimport RngState +from pylibraft.random.cpp.rng_state cimport RngState cdef extern from "raft/cluster/kmeans_types.hpp" \ diff --git a/python/pylibraft/pylibraft/cluster/kmeans.pyx b/python/pylibraft/pylibraft/cluster/kmeans.pyx index 3432ebe0a0..7d336ab58d 100644 --- a/python/pylibraft/pylibraft/cluster/kmeans.pyx +++ b/python/pylibraft/pylibraft/cluster/kmeans.pyx @@ -31,19 +31,19 @@ from pylibraft.common import Handle, cai_wrapper from pylibraft.common.handle import auto_sync_handle from pylibraft.common.handle cimport handle_t -from pylibraft.random.rng_state cimport RngState +from pylibraft.random.cpp.rng_state cimport RngState from pylibraft.common.input_validation import * from pylibraft.distance import DISTANCE_TYPES -from pylibraft.common.handle cimport handle_t -from pylibraft.cpp cimport kmeans as cpp_kmeans, kmeans_types -from pylibraft.cpp.kmeans cimport ( +from pylibraft.cluster.cpp cimport kmeans as cpp_kmeans, kmeans_types +from pylibraft.cluster.cpp.kmeans cimport ( cluster_cost as cpp_cluster_cost, update_centroids, ) -from pylibraft.cpp.mdspan cimport * -from pylibraft.cpp.optional cimport optional +from pylibraft.common.cpp.mdspan cimport * +from pylibraft.common.cpp.optional cimport optional +from pylibraft.common.handle cimport handle_t def is_c_cont(cai, dt): @@ -89,39 +89,37 @@ def compute_new_centroids(X, Examples -------- - .. code-block:: python - - import cupy as cp - - from pylibraft.common import Handle - from pylibraft.cluster.kmeans import compute_new_centroids - - # A single RAFT handle can optionally be reused across - # pylibraft functions. - handle = Handle() - - n_samples = 5000 - n_features = 50 - n_clusters = 3 - - X = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - - centroids = cp.random.random_sample((n_clusters, n_features), - dtype=cp.float32) - - labels = cp.random.randint(0, high=n_clusters, size=n_samples, - dtype=cp.int32) - - new_centroids = cp.empty((n_clusters, n_features), dtype=cp.float32) - - compute_new_centroids( - X, centroids, labels, new_centroids, handle=handle - ) - - # pylibraft functions are often asynchronous so the - # handle needs to be explicitly synchronized - handle.sync() + >>> import cupy as cp + >>> + >>> from pylibraft.common import Handle + >>> from pylibraft.cluster.kmeans import compute_new_centroids + >>> + >>> # A single RAFT handle can optionally be reused across + >>> # pylibraft functions. + >>> handle = Handle() + >>> + >>> n_samples = 5000 + >>> n_features = 50 + >>> n_clusters = 3 + >>> + >>> X = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> + >>> centroids = cp.random.random_sample((n_clusters, n_features), + >>> dtype=cp.float32) + >>> + >>> labels = cp.random.randint(0, high=n_clusters, size=n_samples, + >>> dtype=cp.int32) + >>> + >>> new_centroids = cp.empty((n_clusters, n_features), dtype=cp.float32) + >>> + >>> compute_new_centroids( + >>> X, centroids, labels, new_centroids, handle=handle + >>> ) + >>> + >>> # pylibraft functions are often asynchronous so the + >>> # handle needs to be explicitly synchronized + >>> handle.sync() """ x_cai = X.__cuda_array_interface__ @@ -495,11 +493,11 @@ def fit( cpp_kmeans.fit( deref(h), params.c_obj, - make_device_matrix_view( - X_cai.data, + make_device_matrix_view[double, int, row_major]( + X_cai.data, X_cai.shape[0], X_cai.shape[1]), d_sample_weights, - make_device_matrix_view( + make_device_matrix_view[double, int, row_major]( centroids_cai.data, centroids_cai.shape[0], centroids_cai.shape[1]), make_host_scalar_view[double, int](&d_inertia), @@ -515,11 +513,11 @@ def fit( cpp_kmeans.fit( deref(h), params.c_obj, - make_device_matrix_view( - X_cai.data, + make_device_matrix_view[float, int, row_major]( + X_cai.data, X_cai.shape[0], X_cai.shape[1]), f_sample_weights, - make_device_matrix_view( + make_device_matrix_view[float, int, row_major]( centroids_cai.data, centroids_cai.shape[0], centroids_cai.shape[1]), make_host_scalar_view[float, int](&f_inertia), diff --git a/python/pylibraft/pylibraft/common/cpp/__init__.pxd b/python/pylibraft/pylibraft/common/cpp/__init__.pxd new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/pylibraft/pylibraft/common/cpp/__init__.py b/python/pylibraft/pylibraft/common/cpp/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/pylibraft/pylibraft/common/mdspan.pxd b/python/pylibraft/pylibraft/common/cpp/mdspan.pxd similarity index 61% rename from python/pylibraft/pylibraft/common/mdspan.pxd rename to python/pylibraft/pylibraft/common/cpp/mdspan.pxd index e0cd6fb12f..d4d0dd8f35 100644 --- a/python/pylibraft/pylibraft/common/mdspan.pxd +++ b/python/pylibraft/pylibraft/common/cpp/mdspan.pxd @@ -13,13 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # + # cython: profile=False # distutils: language = c++ # cython: embedsignature = True # cython: language_level = 3 import pylibraft.common.handle - from cython.operator cimport dereference as deref @@ -27,21 +27,38 @@ cdef extern from "raft/thirdparty/mdspan/include/experimental/__p0009_bits/layou cdef cppclass layout_right: pass + cdef cppclass layout_left: + pass + cdef extern from "raft/core/mdspan_types.hpp" \ namespace "raft": ctypedef layout_right row_major + ctypedef layout_left col_major -cdef extern from "raft/core/device_mdspan.hpp" \ - namespace "raft" nogil: +cdef extern from "raft/core/device_mdspan.hpp" namespace "raft" nogil: + + cdef cppclass device_vector_view[ElementType, IndexType]: + pass + + cdef cppclass device_scalar_view[ElementType, IndexType]: + pass - cdef cppclass device_matrix_view[ElementType, IndexType, LayoutPolicy]: + cdef cppclass device_matrix_view[ElementType, IndexType, LayoutType]: pass cdef device_matrix_view[ElementType, IndexType, LayoutPolicy] \ make_device_matrix_view[ElementType, IndexType, LayoutPolicy]( - ElementType* ptr, IndexType n_rows, IndexType n_cols) + ElementType* ptr, IndexType n_rows, IndexType n_cols) except + + + cdef device_vector_view[ElementType, IndexType] \ + make_device_vector_view[ElementType, IndexType]( + ElementType* ptr, IndexType n) except + + + cdef device_scalar_view[ElementType, IndexType] \ + make_device_vector_view[ElementType, IndexType]( + ElementType* ptr) except + cdef extern from "raft/core/host_mdspan.hpp" \ @@ -50,6 +67,20 @@ cdef extern from "raft/core/host_mdspan.hpp" \ cdef cppclass host_matrix_view[ElementType, IndexType, LayoutPolicy]: pass + cdef cppclass host_vector_view[ElementType, IndexType]: + pass + + cdef cppclass host_scalar_view[ElementType, IndexType]: + pass + cdef host_matrix_view[ElementType, IndexType, LayoutPolicy] \ make_host_matrix_view[ElementType, IndexType, LayoutPolicy]( - ElementType* ptr, IndexType n_rows, IndexType n_cols) + ElementType* ptr, IndexType n_rows, IndexType n_cols) except + + + cdef host_vector_view[ElementType, IndexType] \ + make_host_vector_view[ElementType, IndexType]( + ElementType* ptr, IndexType n) except + + + cdef host_scalar_view[ElementType, IndexType] \ + make_host_scalar_view[ElementType, IndexType]( + ElementType *ptr) except + diff --git a/python/pylibraft/pylibraft/cpp/optional.pxd b/python/pylibraft/pylibraft/common/cpp/optional.pxd similarity index 100% rename from python/pylibraft/pylibraft/cpp/optional.pxd rename to python/pylibraft/pylibraft/common/cpp/optional.pxd diff --git a/python/pylibraft/pylibraft/common/cuda.pyx b/python/pylibraft/pylibraft/common/cuda.pyx index 606860dbe9..7400c8550f 100644 --- a/python/pylibraft/pylibraft/common/cuda.pyx +++ b/python/pylibraft/pylibraft/common/cuda.pyx @@ -50,12 +50,10 @@ cdef class Stream: Examples -------- - .. code-block:: python - - from pylibraft.common.cuda import Stream - stream = Stream() - stream.sync() - del stream # optional! + >>> from pylibraft.common.cuda import Stream + >>> stream = Stream() + >>> stream.sync() + >>> del stream # optional! """ def __cinit__(self): cdef cudaStream_t stream diff --git a/python/pylibraft/pylibraft/common/handle.pyx b/python/pylibraft/pylibraft/common/handle.pyx index c14c22f5aa..f662f5bd70 100644 --- a/python/pylibraft/pylibraft/common/handle.pyx +++ b/python/pylibraft/pylibraft/common/handle.pyx @@ -37,19 +37,17 @@ cdef class Handle: Examples -------- - .. code-block:: python - - from raft.common import Stream, Handle - stream = Stream() - handle = Handle(stream) - - # call algos here - - # final sync of all work launched in the stream of this handle - # this is same as `raft.cuda.Stream.sync()` call, but safer in case - # the default stream inside the `handle_t` is being used - handle.sync() - del handle # optional! + >>> from raft.common import Stream, Handle + >>> stream = Stream() + >>> handle = Handle(stream) + >>> + >>> # call algos here + >>> + >>> # final sync of all work launched in the stream of this handle + >>> # this is same as `raft.cuda.Stream.sync()` call, but safer in case + >>> # the default stream inside the `handle_t` is being used + >>> handle.sync() + >>> del handle # optional! """ def __cinit__(self, stream: Stream = None, n_streams=0): diff --git a/python/pylibraft/pylibraft/common/interruptible.pyx b/python/pylibraft/pylibraft/common/interruptible.pyx index fc2e6d9e1f..c7f738f2e5 100644 --- a/python/pylibraft/pylibraft/common/interruptible.pyx +++ b/python/pylibraft/pylibraft/common/interruptible.pyx @@ -38,20 +38,15 @@ def cuda_interruptible(): Use this on a long-running C++ function imported via cython: - .. code-block:: python - - with cuda_interruptible(): - my_long_running_function(...) + >>> with cuda_interruptible(): + >>> my_long_running_function(...) It's also recommended to release the GIL during the call, to make sure the handler has a chance to run: - .. code-block:: python - - with cuda_interruptible(): - with nogil: - my_long_running_function(...) - + >>> with cuda_interruptible(): + >>> with nogil: + >>> my_long_running_function(...) ''' cdef shared_ptr[interruptible] token = get_token() diff --git a/python/pylibraft/pylibraft/cpp/mdspan.pxd b/python/pylibraft/pylibraft/cpp/mdspan.pxd deleted file mode 100644 index da6cac478d..0000000000 --- a/python/pylibraft/pylibraft/cpp/mdspan.pxd +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (c) 2022, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# cython: profile=False -# distutils: language = c++ -# cython: embedsignature = True -# cython: language_level = 3 - - -cdef extern from "raft/core/device_mdspan.hpp" namespace "raft" nogil: - cdef cppclass device_vector_view[T, IndexType]: - pass - - cdef cppclass device_matrix_view[T, IndexType]: - pass - - cdef cppclass host_scalar_view[T, IndexType]: - pass - - cdef device_vector_view[T, IndexType] \ - make_device_vector_view[T, IndexType](T * ptr, - IndexType n) except + - - cdef device_matrix_view[T, IndexType] \ - make_device_matrix_view[T, IndexType](T * ptr, - IndexType rows, - IndexType cols) except + - - cdef host_scalar_view[T, IndexType] \ - make_host_scalar_view[T, IndexType](T * ptr) except + diff --git a/python/pylibraft/pylibraft/distance/fused_l2_nn.pyx b/python/pylibraft/pylibraft/distance/fused_l2_nn.pyx index 3f30e6d0a8..e22afa99bf 100644 --- a/python/pylibraft/pylibraft/distance/fused_l2_nn.pyx +++ b/python/pylibraft/pylibraft/distance/fused_l2_nn.pyx @@ -32,8 +32,8 @@ from pylibraft.common.handle import auto_sync_handle from pylibraft.common.handle cimport handle_t -cdef extern from "raft_distance/fused_l2_min_arg.hpp" \ - namespace "raft::distance::runtime": +cdef extern from "raft_runtime/distance/fused_l2_nn.hpp" \ + namespace "raft::runtime::distance": void fused_l2_nn_min_arg( const handle_t &handle, @@ -73,53 +73,49 @@ def fused_l2_nn_argmin(X, Y, out=None, sqrt=True, handle=None): -------- To compute the 1-nearest neighbors argmin: - .. code-block:: python - - import cupy as cp - from pylibraft.common import Handle - from pylibraft.distance import fused_l2_nn_argmin - n_samples = 5000 - n_clusters = 5 - n_features = 50 - in1 = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - in2 = cp.random.random_sample((n_clusters, n_features), - dtype=cp.float32) - # A single RAFT handle can optionally be reused across - # pylibraft functions. - handle = Handle() - ... - output = fused_l2_nn_argmin(in1, in2, output, handle=handle) - ... - # pylibraft functions are often asynchronous so the - # handle needs to be explicitly synchronized - handle.sync() + >>> import cupy as cp + >>> from pylibraft.common import Handle + >>> from pylibraft.distance import fused_l2_nn_argmin + >>> n_samples = 5000 + >>> n_clusters = 5 + >>> n_features = 50 + >>> in1 = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> in2 = cp.random.random_sample((n_clusters, n_features), + >>> dtype=cp.float32) + >>> # A single RAFT handle can optionally be reused across + >>> # pylibraft functions. + >>> handle = Handle() + >>> ... + >>> output = fused_l2_nn_argmin(in1, in2, output, handle=handle) + >>> ... + >>> # pylibraft functions are often asynchronous so the + >>> # handle needs to be explicitly synchronized + >>> handle.sync() The output can also be computed in-place on a preallocated array: - .. code-block:: python - - import cupy as cp - from pylibraft.common import Handle - from pylibraft.distance import fused_l2_nn_argmin - n_samples = 5000 - n_clusters = 5 - n_features = 50 - in1 = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - in2 = cp.random.random_sample((n_clusters, n_features), - dtype=cp.float32) - output = cp.empty((n_samples, 1), dtype=cp.int32) - # A single RAFT handle can optionally be reused across - # pylibraft functions. - handle = Handle() - ... - fused_l2_nn_argmin(in1, in2, out=output, handle=handle) - ... - # pylibraft functions are often asynchronous so the - # handle needs to be explicitly synchronized - handle.sync() + >>> import cupy as cp + >>> from pylibraft.common import Handle + >>> from pylibraft.distance import fused_l2_nn_argmin + >>> n_samples = 5000 + >>> n_clusters = 5 + >>> n_features = 50 + >>> in1 = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> in2 = cp.random.random_sample((n_clusters, n_features), + >>> dtype=cp.float32) + >>> output = cp.empty((n_samples, 1), dtype=cp.int32) + >>> # A single RAFT handle can optionally be reused across + >>> # pylibraft functions. + >>> handle = Handle() + >>> ... + >>> fused_l2_nn_argmin(in1, in2, out=output, handle=handle) + >>> ... + >>> # pylibraft functions are often asynchronous so the + >>> # handle needs to be explicitly synchronized + >>> handle.sync() """ diff --git a/python/pylibraft/pylibraft/distance/pairwise_distance.pyx b/python/pylibraft/pylibraft/distance/pairwise_distance.pyx index 76e70e3926..8296d5bc09 100644 --- a/python/pylibraft/pylibraft/distance/pairwise_distance.pyx +++ b/python/pylibraft/pylibraft/distance/pairwise_distance.pyx @@ -34,8 +34,8 @@ from pylibraft.common.handle cimport handle_t from pylibraft.common import cai_wrapper, device_ndarray -cdef extern from "raft_distance/pairwise_distance.hpp" \ - namespace "raft::distance::runtime": +cdef extern from "raft_runtime/distance/pairwise_distance.hpp" \ + namespace "raft::runtime::distance": cdef void pairwise_distance(const handle_t &handle, float *x, @@ -118,63 +118,52 @@ def distance(X, Y, out=None, metric="euclidean", p=2.0, handle=None): -------- To compute pairwise distances on cupy arrays: - .. code-block:: python - - import cupy as cp - from pylibraft.common import Handle - from pylibraft.distance import pairwise_distance - n_samples = 5000 - n_features = 50 - in1 = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - in2 = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) + >>> import cupy as cp + >>> from pylibraft.common import Handle + >>> from pylibraft.distance import pairwise_distance + >>> n_samples = 5000 + >>> n_features = 50 + >>> in1 = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> in2 = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) A single RAFT handle can optionally be reused across pylibraft functions. - .. code-block:: python - - handle = Handle() - output = pairwise_distance(in1, in2, metric="euclidean", handle=handle) + >>> handle = Handle() + >>> output = pairwise_distance(in1, in2, metric="euclidean", handle=handle) pylibraft functions are often asynchronous so the handle needs to be explicitly synchronized - .. code-block:: python - - handle.sync() + >>> handle.sync() It's also possible to write to a pre-allocated output array: - .. code-block:: python - - import cupy as cp - from pylibraft.common import Handle - from pylibraft.distance import pairwise_distance - n_samples = 5000 - n_features = 50 - in1 = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - in2 = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - output = cp.empty((n_samples, n_samples), dtype=cp.float32) + >>> import cupy as cp + >>> from pylibraft.common import Handle + >>> from pylibraft.distance import pairwise_distance + >>> n_samples = 5000 + >>> n_features = 50 + >>> in1 = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> in2 = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> output = cp.empty((n_samples, n_samples), dtype=cp.float32) A single RAFT handle can optionally be reused across pylibraft functions. - .. code-block:: python - - handle = Handle() - pairwise_distance(in1, in2, out=output, - metric="euclidean", handle=handle) + >>> + >>> handle = Handle() + >>> pairwise_distance(in1, in2, out=output, + >>> metric="euclidean", handle=handle) pylibraft functions are often asynchronous so the handle needs to be explicitly synchronized - .. code-block:: python - - handle.sync() + >>> handle.sync() """ x_cai = cai_wrapper(X) diff --git a/python/pylibraft/pylibraft/neighbors/ivf_pq/cpp/__init__.pxd b/python/pylibraft/pylibraft/neighbors/ivf_pq/cpp/__init__.pxd new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/pylibraft/pylibraft/neighbors/ivf_pq/cpp/__init__.py b/python/pylibraft/pylibraft/neighbors/ivf_pq/cpp/__init__.py new file mode 100644 index 0000000000..273b4497cc --- /dev/null +++ b/python/pylibraft/pylibraft/neighbors/ivf_pq/cpp/__init__.py @@ -0,0 +1,14 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/python/pylibraft/pylibraft/neighbors/ivf_pq/c_ivf_pq.pxd b/python/pylibraft/pylibraft/neighbors/ivf_pq/cpp/c_ivf_pq.pxd similarity index 97% rename from python/pylibraft/pylibraft/neighbors/ivf_pq/c_ivf_pq.pxd rename to python/pylibraft/pylibraft/neighbors/ivf_pq/cpp/c_ivf_pq.pxd index 9728495bf8..2f1354c475 100644 --- a/python/pylibraft/pylibraft/neighbors/ivf_pq/c_ivf_pq.pxd +++ b/python/pylibraft/pylibraft/neighbors/ivf_pq/cpp/c_ivf_pq.pxd @@ -104,8 +104,8 @@ cdef extern from "raft/neighbors/ivf_pq_types.hpp" \ cudaDataType_t internal_distance_dtype -cdef extern from "raft/neighbors/specializations/ivf_pq_specialization.hpp" \ - namespace "raft::neighbors::ivf_pq" nogil: +cdef extern from "raft_runtime/neighbors/ivf_pq.hpp" \ + namespace "raft::runtime::neighbors::ivf_pq" nogil: cdef void build(const handle_t& handle, const index_params& params, diff --git a/python/pylibraft/pylibraft/neighbors/ivf_pq/ivf_pq.pyx b/python/pylibraft/pylibraft/neighbors/ivf_pq/ivf_pq.pyx index 75b7cd3abb..d98d0432da 100644 --- a/python/pylibraft/pylibraft/neighbors/ivf_pq/ivf_pq.pyx +++ b/python/pylibraft/pylibraft/neighbors/ivf_pq/ivf_pq.pyx @@ -46,8 +46,11 @@ from rmm._lib.memory_resource cimport ( device_memory_resource, ) -cimport pylibraft.neighbors.ivf_pq.c_ivf_pq as c_ivf_pq -from pylibraft.neighbors.ivf_pq.c_ivf_pq cimport index_params, search_params +cimport pylibraft.neighbors.ivf_pq.cpp.c_ivf_pq as c_ivf_pq +from pylibraft.neighbors.ivf_pq.cpp.c_ivf_pq cimport ( + index_params, + search_params, +) def _get_metric(metric): @@ -317,39 +320,37 @@ def build(IndexParams index_params, dataset, handle=None): Examples -------- - .. code-block:: python - - import cupy as cp - - from pylibraft.common import Handle - from pylibraft.neighbors import ivf_pq - - n_samples = 50000 - n_features = 50 - n_queries = 1000 - - dataset = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - handle = Handle() - index_params = ivf_pq.IndexParams( - n_lists=1024, - metric="l2_expanded", - pq_dim=10) - index = ivf_pq.build(index_params, dataset, handle=handle) - - # Search using the built index - queries = cp.random.random_sample((n_queries, n_features), - dtype=cp.float32) - k = 10 - distances, neighbors = ivf_pq.search(ivf_pq.SearchParams(), index, - queries, k, handle=handle) - - distances = cp.asarray(distances) - neighbors = cp.asarray(neighbors) - - # pylibraft functions are often asynchronous so the - # handle needs to be explicitly synchronized - handle.sync() + >>> import cupy as cp + >>> + >>> from pylibraft.common import Handle + >>> from pylibraft.neighbors import ivf_pq + >>> + >>> n_samples = 50000 + >>> n_features = 50 + >>> n_queries = 1000 + >>> + >>> dataset = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> handle = Handle() + >>> index_params = ivf_pq.IndexParams( + >>> n_lists=1024, + >>> metric="l2_expanded", + >>> pq_dim=10) + >>> index = ivf_pq.build(index_params, dataset, handle=handle) + >>> + >>> # Search using the built index + >>> queries = cp.random.random_sample((n_queries, n_features), + >>> dtype=cp.float32) + >>> k = 10 + >>> distances, neighbors = ivf_pq.search(ivf_pq.SearchParams(), index, + >>> queries, k, handle=handle) + >>> + >>> distances = cp.asarray(distances) + >>> neighbors = cp.asarray(neighbors) + >>> + >>> # pylibraft functions are often asynchronous so the + >>> # handle needs to be explicitly synchronized + >>> handle.sync() """ dataset_cai = cai_wrapper(dataset) @@ -423,42 +424,40 @@ def extend(Index index, new_vectors, new_indices, handle=None): Examples -------- - .. code-block:: python - - import cupy as cp - - from pylibraft.common import Handle - from pylibraft.neighbors import ivf_pq - - n_samples = 50000 - n_features = 50 - n_queries = 1000 - - dataset = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - handle = Handle() - index = ivf_pq.build(ivf_pq.IndexParams(), dataset, handle=handle) - - n_rows = 100 - more_data = cp.random.random_sample((n_rows, n_features), - dtype=cp.float32) - indices = index.size + cp.arange(n_rows, dtype=cp.uint64) - index = ivf_pq.extend(index, more_data, indices) - - # Search using the built index - queries = cp.random.random_sample((n_queries, n_features), - dtype=cp.float32) - k = 10 - distances, neighbors = ivf_pq.search(ivf_pq.SearchParams(), - index, queries, - k, handle=handle) - - # pylibraft functions are often asynchronous so the - # handle needs to be explicitly synchronized - handle.sync() - - distances = cp.asarray(distances) - neighbors = cp.asarray(neighbors) + >>> import cupy as cp + >>> + >>> from pylibraft.common import Handle + >>> from pylibraft.neighbors import ivf_pq + >>> + >>> n_samples = 50000 + >>> n_features = 50 + >>> n_queries = 1000 + >>> + >>> dataset = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> handle = Handle() + >>> index = ivf_pq.build(ivf_pq.IndexParams(), dataset, handle=handle) + >>> + >>> n_rows = 100 + >>> more_data = cp.random.random_sample((n_rows, n_features), + >>> dtype=cp.float32) + >>> indices = index.size + cp.arange(n_rows, dtype=cp.uint64) + >>> index = ivf_pq.extend(index, more_data, indices) + >>> + >>> # Search using the built index + >>> queries = cp.random.random_sample((n_queries, n_features), + >>> dtype=cp.float32) + >>> k = 10 + >>> distances, neighbors = ivf_pq.search(ivf_pq.SearchParams(), + >>> index, queries, + >>> k, handle=handle) + >>> + >>> # pylibraft functions are often asynchronous so the + >>> # handle needs to be explicitly synchronized + >>> handle.sync() + >>> + >>> distances = cp.asarray(distances) + >>> neighbors = cp.asarray(neighbors) """ if not index.trained: raise ValueError("Index need to be built before calling extend.") @@ -602,51 +601,49 @@ def search(SearchParams search_params, Examples -------- - .. code-block:: python - - import cupy as cp - - from pylibraft.common import Handle - from pylibraft.neighbors import ivf_pq - - n_samples = 50000 - n_features = 50 - n_queries = 1000 - dataset = cp.random.random_sample((n_samples, n_features), - dtype=cp.float32) - - # Build index - handle = Handle() - index = ivf_pq.build(ivf_pq.IndexParams(), dataset, handle=handle) - - # Search using the built index - queries = cp.random.random_sample((n_queries, n_features), - dtype=cp.float32) - k = 10 - search_params = ivf_pq.SearchParams( - n_probes=20, - lut_dtype=ivf_pq.np.float16, - internal_distance_dtype=ivf_pq.np.float32 - ) - - # Using a pooling allocator reduces overhead of temporary array - # creation during search. This is useful if multiple searches - # are performad with same query size. - mr = rmm.mr.PoolMemoryResource( - rmm.mr.CudaMemoryResource(), - initial_pool_size=2**29, - maximum_pool_size=2**31 - ) - distances, neighbors = ivf_pq.search(search_params, index, queries, - k, memory_resource=mr, - handle=handle) - - # pylibraft functions are often asynchronous so the - # handle needs to be explicitly synchronized - handle.sync() - - neighbors = cp.asarray(neighbors) - distances = cp.asarray(distances) + >>> import cupy as cp + >>> + >>> from pylibraft.common import Handle + >>> from pylibraft.neighbors import ivf_pq + >>> + >>> n_samples = 50000 + >>> n_features = 50 + >>> n_queries = 1000 + >>> dataset = cp.random.random_sample((n_samples, n_features), + >>> dtype=cp.float32) + >>> + >>> # Build index + >>> handle = Handle() + >>> index = ivf_pq.build(ivf_pq.IndexParams(), dataset, handle=handle) + >>> + >>> # Search using the built index + >>> queries = cp.random.random_sample((n_queries, n_features), + >>> dtype=cp.float32) + >>> k = 10 + >>> search_params = ivf_pq.SearchParams( + >>> n_probes=20, + >>> lut_dtype=ivf_pq.np.float16, + >>> internal_distance_dtype=ivf_pq.np.float32 + >>> ) + >>> + >>> # Using a pooling allocator reduces overhead of temporary array + >>> # creation during search. This is useful if multiple searches + >>> # are performad with same query size. + >>> mr = rmm.mr.PoolMemoryResource( + >>> rmm.mr.CudaMemoryResource(), + >>> initial_pool_size=2**29, + >>> maximum_pool_size=2**31 + >>> ) + >>> distances, neighbors = ivf_pq.search(search_params, index, queries, + >>> k, memory_resource=mr, + >>> handle=handle) + >>> + >>> # pylibraft functions are often asynchronous so the + >>> # handle needs to be explicitly synchronized + >>> handle.sync() + >>> + >>> neighbors = cp.asarray(neighbors) + >>> distances = cp.asarray(distances) """ if not index.trained: diff --git a/python/pylibraft/pylibraft/neighbors/refine.pyx b/python/pylibraft/pylibraft/neighbors/refine.pyx index 2d8d4196e3..206fe15dfb 100644 --- a/python/pylibraft/pylibraft/neighbors/refine.pyx +++ b/python/pylibraft/pylibraft/neighbors/refine.pyx @@ -46,23 +46,26 @@ from pylibraft.distance.distance_type cimport DistanceType import pylibraft.neighbors.ivf_pq as ivf_pq from pylibraft.neighbors.ivf_pq.ivf_pq import _get_metric -cimport pylibraft.neighbors.ivf_pq.c_ivf_pq as c_ivf_pq -from pylibraft.common.mdspan cimport ( +cimport pylibraft.neighbors.ivf_pq.cpp.c_ivf_pq as c_ivf_pq +from pylibraft.common.cpp.mdspan cimport ( device_matrix_view, host_matrix_view, make_device_matrix_view, make_host_matrix_view, row_major, ) -from pylibraft.neighbors.ivf_pq.c_ivf_pq cimport index_params, search_params +from pylibraft.neighbors.ivf_pq.cpp.c_ivf_pq cimport ( + index_params, + search_params, +) # We omit the const qualifiers in the interface for refine, because cython # has an issue parsing it (https://github.com/cython/cython/issues/4180). -cdef extern from "raft/neighbors/specializations/refine.hpp" \ - namespace "raft::neighbors" nogil: +cdef extern from "raft_runtime/neighbors/refine.hpp" \ + namespace "raft::runtime::neighbors" nogil: - cdef void c_refine "raft::neighbors::refine" ( + cdef void c_refine "raft::runtime::neighbors::refine" ( const handle_t& handle, device_matrix_view[float, uint64_t, row_major] dataset, device_matrix_view[float, uint64_t, row_major] queries, @@ -71,7 +74,7 @@ cdef extern from "raft/neighbors/specializations/refine.hpp" \ device_matrix_view[float, uint64_t, row_major] distances, DistanceType metric) except + - cdef void c_refine "raft::neighbors::refine" ( + cdef void c_refine "raft::runtime::neighbors::refine" ( const handle_t& handle, device_matrix_view[uint8_t, uint64_t, row_major] dataset, device_matrix_view[uint8_t, uint64_t, row_major] queries, @@ -80,7 +83,7 @@ cdef extern from "raft/neighbors/specializations/refine.hpp" \ device_matrix_view[float, uint64_t, row_major] distances, DistanceType metric) except + - cdef void c_refine "raft::neighbors::refine" ( + cdef void c_refine "raft::runtime::neighbors::refine" ( const handle_t& handle, device_matrix_view[int8_t, uint64_t, row_major] dataset, device_matrix_view[int8_t, uint64_t, row_major] queries, @@ -89,7 +92,7 @@ cdef extern from "raft/neighbors/specializations/refine.hpp" \ device_matrix_view[float, uint64_t, row_major] distances, DistanceType metric) except + - cdef void c_refine "raft::neighbors::refine" ( + cdef void c_refine "raft::runtime::neighbors::refine" ( const handle_t& handle, host_matrix_view[float, uint64_t, row_major] dataset, host_matrix_view[float, uint64_t, row_major] queries, @@ -98,7 +101,7 @@ cdef extern from "raft/neighbors/specializations/refine.hpp" \ host_matrix_view[float, uint64_t, row_major] distances, DistanceType metric) except + - cdef void c_refine "raft::neighbors::refine" ( + cdef void c_refine "raft::runtime::neighbors::refine" ( const handle_t& handle, host_matrix_view[uint8_t, uint64_t, row_major] dataset, host_matrix_view[uint8_t, uint64_t, row_major] queries, @@ -107,7 +110,7 @@ cdef extern from "raft/neighbors/specializations/refine.hpp" \ host_matrix_view[float, uint64_t, row_major] distances, DistanceType metric) except + - cdef void c_refine "raft::neighbors::refine" ( + cdef void c_refine "raft::runtime::neighbors::refine" ( const handle_t& handle, host_matrix_view[int8_t, uint64_t, row_major] dataset, host_matrix_view[int8_t, uint64_t, row_major] queries, diff --git a/python/pylibraft/pylibraft/random/cpp/__init__.pxd b/python/pylibraft/pylibraft/random/cpp/__init__.pxd new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/pylibraft/pylibraft/random/cpp/__init__.py b/python/pylibraft/pylibraft/random/cpp/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/pylibraft/pylibraft/random/rng_state.pxd b/python/pylibraft/pylibraft/random/cpp/rng_state.pxd similarity index 100% rename from python/pylibraft/pylibraft/random/rng_state.pxd rename to python/pylibraft/pylibraft/random/cpp/rng_state.pxd diff --git a/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx b/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx index ef785a900b..dbc2e25a29 100644 --- a/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx +++ b/python/pylibraft/pylibraft/random/rmat_rectangular_generator.pyx @@ -29,12 +29,11 @@ from pylibraft.common.handle import auto_sync_handle from libcpp cimport bool from pylibraft.common.handle cimport handle_t +from pylibraft.random.cpp.rng_state cimport RngState -from .rng_state cimport RngState - -cdef extern from "raft_distance/random/rmat_rectangular_generator.hpp" \ - namespace "raft::random::runtime": +cdef extern from "raft_runtime/random/rmat_rectangular_generator.hpp" \ + namespace "raft::runtime::random": cdef void rmat_rectangular_gen(const handle_t &handle, int* out, @@ -98,30 +97,28 @@ def rmat(out, theta, r_scale, c_scale, seed=12345, handle=None): Examples -------- - .. code-block:: python - - import cupy as cp - - from pylibraft.common import Handle - from pylibraft.random import rmat - - n_edges = 5000 - r_scale = 16 - c_scale = 14 - theta_len = max(r_scale, c_scale) * 4 - - out = cp.empty((n_edges, 2), dtype=cp.int32) - theta = cp.random.random_sample(theta_len, dtype=cp.float32) - - # A single RAFT handle can optionally be reused across - # pylibraft functions. - handle = Handle() - ... - rmat(out, theta, r_scale, c_scale, handle=handle) - ... - # pylibraft functions are often asynchronous so the - # handle needs to be explicitly synchronized - handle.sync() + >>> import cupy as cp + >>> + >>> from pylibraft.common import Handle + >>> from pylibraft.random import rmat + >>> + >>> n_edges = 5000 + >>> r_scale = 16 + >>> c_scale = 14 + >>> theta_len = max(r_scale, c_scale) * 4 + >>> + >>> out = cp.empty((n_edges, 2), dtype=cp.int32) + >>> theta = cp.random.random_sample(theta_len, dtype=cp.float32) + >>> + >>> # A single RAFT handle can optionally be reused across + >>> # pylibraft functions. + >>> handle = Handle() + >>> ... + >>> rmat(out, theta, r_scale, c_scale, handle=handle) + >>> ... + >>> # pylibraft functions are often asynchronous so the + >>> # handle needs to be explicitly synchronized + >>> handle.sync() """ if theta is None: