|
9 | 9 | #include <cuvs/neighbors/all_neighbors.hpp> |
10 | 10 | #include <raft/matrix/shift.cuh> |
11 | 11 | #include <raft/util/cudart_utils.hpp> |
| 12 | +#include <unordered_set> |
12 | 13 |
|
13 | 14 | namespace cuvs::neighbors::all_neighbors::detail { |
14 | 15 | using namespace cuvs::neighbors; |
15 | 16 |
|
16 | 17 | GRAPH_BUILD_ALGO check_params_validity(const all_neighbors_params& params, |
17 | 18 | bool do_mutual_reachability_dist) |
18 | 19 | { |
| 20 | + using DT = cuvs::distance::DistanceType; |
| 21 | + |
| 22 | + // InnerProduct is not supported for mutual reachability distance, because mutual reachability |
| 23 | + // distance takes "max" of core distances and pairwise distance. |
| 24 | + static const std::unordered_set<DT> mrd_allowed_metrics = { |
| 25 | + DT::L2Expanded, DT::L2SqrtExpanded, DT::CosineExpanded}; |
| 26 | + |
| 27 | + static const std::unordered_set<DT> bf_allowed_metrics = {DT::L2Expanded, |
| 28 | + DT::L2SqrtExpanded, |
| 29 | + DT::CosineExpanded, |
| 30 | + DT::L1, |
| 31 | + DT::L2Unexpanded, |
| 32 | + DT::L2SqrtUnexpanded, |
| 33 | + DT::InnerProduct, |
| 34 | + DT::Linf, |
| 35 | + DT::Canberra, |
| 36 | + DT::LpUnexpanded, |
| 37 | + DT::CorrelationExpanded, |
| 38 | + DT::JensenShannon}; |
| 39 | + |
| 40 | + static const std::unordered_set<DT> nnd_allowed_metrics = { |
| 41 | + DT::L2Expanded, DT::L2SqrtExpanded, DT::CosineExpanded, DT::InnerProduct}; |
| 42 | + |
19 | 43 | if (std::holds_alternative<graph_build_params::brute_force_params>(params.graph_build_params)) { |
20 | 44 | if (do_mutual_reachability_dist) { |
21 | | - // InnerProduct is not supported for mutual reachability distance, because mutual reachability |
22 | | - // distance takes "max" of core distances and pairwise distance. |
23 | | - auto allowed_metrics = params.metric == cuvs::distance::DistanceType::L2Expanded || |
24 | | - params.metric == cuvs::distance::DistanceType::L2SqrtExpanded || |
25 | | - params.metric == cuvs::distance::DistanceType::CosineExpanded; |
26 | 45 | RAFT_EXPECTS( |
27 | | - allowed_metrics, |
| 46 | + mrd_allowed_metrics.count(params.metric), |
28 | 47 | "Distance metric for all-neighbors build with brute force for computing mutual " |
29 | 48 | "reachability distance should be L2Expanded, L2SqrtExpanded, or CosineExpanded."); |
30 | 49 | } else { |
31 | | - auto allowed_metrics = params.metric == cuvs::distance::DistanceType::L2Expanded || |
32 | | - params.metric == cuvs::distance::DistanceType::L2SqrtExpanded || |
33 | | - params.metric == cuvs::distance::DistanceType::CosineExpanded || |
34 | | - params.metric == cuvs::distance::DistanceType::InnerProduct; |
35 | | - RAFT_EXPECTS(allowed_metrics, |
36 | | - "Distance metric for all-neighbors build with brute force should be L2Expanded, " |
37 | | - "L2SqrtExpanded, CosineExpanded, or InnerProduct."); |
| 50 | + RAFT_EXPECTS( |
| 51 | + bf_allowed_metrics.count(params.metric), |
| 52 | + "Distance metric for all-neighbors build with brute force should be L2Expanded, " |
| 53 | + "L2SqrtExpanded, CosineExpanded, L1, L2Unexpanded, L2SqrtUnexpanded, InnerProduct, Linf, " |
| 54 | + "Canberra, LpUnexpanded, CorrelationExpanded, or JensenShannon."); |
38 | 55 | } |
39 | 56 | return GRAPH_BUILD_ALGO::BRUTE_FORCE; |
40 | 57 | } else if (std::holds_alternative<graph_build_params::nn_descent_params>( |
41 | 58 | params.graph_build_params)) { |
42 | 59 | if (do_mutual_reachability_dist) { |
43 | | - // InnerProduct is not supported for mutual reachability distance, because mutual reachability |
44 | | - // distance takes "max" of core distances and pairwise distance. |
45 | | - auto allowed_metrics = params.metric == cuvs::distance::DistanceType::L2Expanded || |
46 | | - params.metric == cuvs::distance::DistanceType::L2SqrtExpanded || |
47 | | - params.metric == cuvs::distance::DistanceType::CosineExpanded; |
48 | 60 | RAFT_EXPECTS( |
49 | | - allowed_metrics, |
| 61 | + mrd_allowed_metrics.count(params.metric), |
50 | 62 | "Distance metric for all-neighbors build with NN Descent for computing mutual reachability " |
51 | 63 | "distance should be L2Expanded, L2SqrtExpanded, or CosineExpanded."); |
52 | 64 | } else { |
53 | | - auto allowed_metrics = params.metric == cuvs::distance::DistanceType::L2Expanded || |
54 | | - params.metric == cuvs::distance::DistanceType::L2SqrtExpanded || |
55 | | - params.metric == cuvs::distance::DistanceType::CosineExpanded || |
56 | | - params.metric == cuvs::distance::DistanceType::InnerProduct; |
57 | | - RAFT_EXPECTS(allowed_metrics, |
| 65 | + RAFT_EXPECTS(nnd_allowed_metrics.count(params.metric), |
58 | 66 | "Distance metric for all-neighbors build with NN Descent should be L2Expanded, " |
59 | 67 | "L2SqrtExpanded, CosineExpanded, or InnerProduct."); |
60 | 68 | } |
|
0 commit comments