cuML C++ API  23.12
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
specialization_types.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 #include <cstddef>
18 #include <cstdint>
20 #include <type_traits>
21 #include <variant>
22 namespace ML {
23 namespace experimental {
24 namespace fil {
25 namespace detail {
26 
27 /*
28  * A template used solely to help manage the types which will be compiled in
29  * standard cuML FIL
30  *
31  * The relatively simple and human-readable template parameters of this
32  * template are translated into the specific types and values required
33  * to instantiate more complex templates and compile-time checks.
34  *
35  * @tparam layout_v The layout of trees within a model
36  * @tparam double_precision Whether this model should use double-precision
37  * for floating-point evaluation and 64-bit integers for indexes
38  * @tparam large_trees Whether this forest expects more than 2**(16 -3) - 1 =
39  * 8191 features or contains nodes whose child is offset more than 2**16 - 1 = 65535 nodes away.
40  */
41 template <tree_layout layout_v, bool double_precision, bool large_trees>
43  /* The node threshold type to be used based on the template parameters
44  */
45  using threshold_type = std::conditional_t<double_precision, double, float>;
46  /* The type required for specifying indexes to vector leaf outputs or
47  * non-local categorical data.
48  */
49  using index_type = std::conditional_t<double_precision, std::uint64_t, std::uint32_t>;
50  /* The type used to provide metadata storage for nodes */
51  using metadata_type = std::conditional_t<large_trees, std::uint32_t, std::uint16_t>;
52  /* The type used to provide metadata storage for nodes */
53  using offset_type = std::conditional_t<large_trees, std::uint32_t, std::uint16_t>;
54  /* The tree layout (alias for layout_v)*/
55  auto static constexpr const layout = layout_v;
56  /* Whether or not this tree requires double precision (alias for
57  * double_precision)
58  */
59  auto static constexpr const is_double_precision = double_precision;
60  /* Whether or not this forest contains large trees (alias for
61  * large_trees)
62  */
63  auto static constexpr const has_large_trees = large_trees;
64 };
65 
66 /* A variant holding information on all specialization types compiled
67  * in standard cuML FIL
68  */
70  std::variant<specialization_types<tree_layout::depth_first, false, false>,
78 
79 } // namespace detail
80 } // namespace fil
81 } // namespace experimental
82 } // namespace ML
std::variant< specialization_types< tree_layout::depth_first, false, false >, specialization_types< tree_layout::depth_first, false, true >, specialization_types< tree_layout::depth_first, true, false >, specialization_types< tree_layout::depth_first, true, true >, specialization_types< tree_layout::breadth_first, false, false >, specialization_types< tree_layout::breadth_first, false, true >, specialization_types< tree_layout::breadth_first, true, false >, specialization_types< tree_layout::breadth_first, true, true > > specialization_variant
Definition: specialization_types.hpp:77
Definition: dbscan.hpp:27
Definition: specialization_types.hpp:42
static constexpr auto const layout
Definition: specialization_types.hpp:55
std::conditional_t< large_trees, std::uint32_t, std::uint16_t > metadata_type
Definition: specialization_types.hpp:51
std::conditional_t< double_precision, std::uint64_t, std::uint32_t > index_type
Definition: specialization_types.hpp:49
static constexpr auto const is_double_precision
Definition: specialization_types.hpp:59
std::conditional_t< double_precision, double, float > threshold_type
Definition: specialization_types.hpp:45
std::conditional_t< large_trees, std::uint32_t, std::uint16_t > offset_type
Definition: specialization_types.hpp:53
static constexpr auto const has_large_trees
Definition: specialization_types.hpp:63