12 #include <type_traits>
22 template <
typename threshold_t,
typename index_t,
typename metadata_storage_t,
typename offset_t>
26 sizeof(metadata_storage_t) +
sizeof(offset_t));
28 if (total > result) { result =
index_type{16}; }
29 if (total > result) { result =
index_type{32}; }
30 if (total > result) { result =
index_type{64}; }
31 if (total > result) { result =
index_type{128}; }
32 if (total > result) { result =
index_type{256}; }
33 if (total > result) { result = total; }
78 typename metadata_storage_t,
80 struct alignas(detail::get_node_alignment<threshold_t, index_t, metadata_storage_t, offset_t>())
83 auto constexpr
static const layout = layout_v;
107 #pragma GCC diagnostic push
108 #pragma GCC diagnostic ignored "-Wnarrowing"
110 bool is_leaf_node =
true,
111 bool default_to_distant_child =
false,
112 bool is_categorical_node =
false,
118 distant_child_offset,
119 construct_metadata(is_leaf_node, default_to_distant_child, is_categorical_node, feature)}}
124 bool is_leaf_node =
true,
125 bool default_to_distant_child =
false,
126 bool is_categorical_node =
false,
132 distant_child_offset,
133 construct_metadata(is_leaf_node, default_to_distant_child, is_categorical_node, feature)}}
136 #pragma GCC diagnostic pop
141 return aligned_data.inner_data.metadata & FEATURE_MASK;
146 return !bool(aligned_data.inner_data.distant_offset);
151 return bool(aligned_data.inner_data.metadata & DEFAULT_DISTANT_MASK);
156 return bool(aligned_data.inner_data.metadata & CATEGORICAL_MASK);
173 return aligned_data.inner_data.stored_value.value;
177 HOST DEVICE auto const&
index()
const {
return aligned_data.inner_data.stored_value.index; }
182 template <
bool has_vector_leaves>
185 if constexpr (has_vector_leaves) {
186 return aligned_data.inner_data.stored_value.index;
188 return aligned_data.inner_data.stored_value.value;
199 auto constexpr
static const LEAF_BIT =
203 auto constexpr
static const DEFAULT_DISTANT_MASK =
207 auto constexpr
static const FEATURE_MASK =
211 auto static constexpr construct_metadata(
bool is_leaf_node =
true,
212 bool default_to_distant_child =
false,
213 bool is_categorical_node =
false,
217 (is_leaf_node << LEAF_BIT) + (default_to_distant_child << DEFAULT_DISTANT_BIT) +
218 (is_categorical_node << CATEGORICAL_BIT) + (feature & FEATURE_MASK));
221 auto static constexpr
const byte_size =
222 detail::get_node_alignment<threshold_t, index_t, metadata_storage_t, offset_t>();
224 struct inner_data_type {
225 value_type stored_value;
231 union aligned_data_type {
232 inner_data_type inner_data;
233 char spacer_data[byte_size];
236 aligned_data_type aligned_data;
#define DEVICE
Definition: gpu_support.hpp:24
#define HOST
Definition: gpu_support.hpp:23
math_t max(math_t a, math_t b)
Definition: learning_rate.h:16
constexpr auto get_node_alignment()
Definition: node.hpp:23
tree_layout
Definition: tree_layout.hpp:8
@ layered_children_together
uint32_t index_type
Definition: index_type.hpp:9
Definition: dbscan.hpp:18
HOST DEVICE constexpr auto output() const
Definition: node.hpp:183
constexpr static auto const layout
Definition: node.hpp:83
threshold_t threshold_type
Definition: node.hpp:85
HOST DEVICE constexpr auto is_categorical() const
Definition: node.hpp:154
HOST constexpr DEVICE node(index_type index, bool is_leaf_node=true, bool default_to_distant_child=false, bool is_categorical_node=false, metadata_storage_type feature=metadata_storage_type{}, offset_type distant_child_offset=offset_type{})
Definition: node.hpp:123
offset_t offset_type
An alias for offset_t.
Definition: node.hpp:103
HOST constexpr DEVICE node(threshold_type value=threshold_type{}, bool is_leaf_node=true, bool default_to_distant_child=false, bool is_categorical_node=false, metadata_storage_type feature=metadata_storage_type{}, offset_type distant_child_offset=offset_type{})
Definition: node.hpp:109
HOST DEVICE auto const & index() const
Definition: node.hpp:177
metadata_storage_t metadata_storage_type
An alias for metadata_storage_t.
Definition: node.hpp:101
index_t index_type
Definition: node.hpp:87
HOST DEVICE constexpr auto feature_index() const
Definition: node.hpp:139
HOST DEVICE constexpr auto is_leaf() const
Definition: node.hpp:144
HOST DEVICE constexpr auto child_offset(bool condition) const
Definition: node.hpp:159
HOST DEVICE constexpr auto threshold() const
Definition: node.hpp:171
HOST DEVICE constexpr auto default_distant() const
Definition: node.hpp:149
index_t index
Definition: node.hpp:98
threshold_t value
Definition: node.hpp:97