23 #include <type_traits>
33 template <
typename threshold_t,
typename index_t,
typename metadata_storage_t,
typename offset_t>
37 sizeof(metadata_storage_t) +
sizeof(offset_t));
39 if (total > result) { result =
index_type{16}; }
40 if (total > result) { result =
index_type{32}; }
41 if (total > result) { result =
index_type{64}; }
42 if (total > result) { result =
index_type{128}; }
43 if (total > result) { result =
index_type{256}; }
44 if (total > result) { result = total; }
89 typename metadata_storage_t,
91 struct alignas(detail::get_node_alignment<threshold_t, index_t, metadata_storage_t, offset_t>())
94 auto constexpr
static const layout = layout_v;
118 #pragma GCC diagnostic push
119 #pragma GCC diagnostic ignored "-Wnarrowing"
121 bool is_leaf_node =
true,
122 bool default_to_distant_child =
false,
123 bool is_categorical_node =
false,
129 distant_child_offset,
130 construct_metadata(is_leaf_node, default_to_distant_child, is_categorical_node, feature)}}
135 bool is_leaf_node =
true,
136 bool default_to_distant_child =
false,
137 bool is_categorical_node =
false,
143 distant_child_offset,
144 construct_metadata(is_leaf_node, default_to_distant_child, is_categorical_node, feature)}}
147 #pragma GCC diagnostic pop
152 return aligned_data.inner_data.metadata & FEATURE_MASK;
157 return !bool(aligned_data.inner_data.distant_offset);
162 return bool(aligned_data.inner_data.metadata & DEFAULT_DISTANT_MASK);
167 return bool(aligned_data.inner_data.metadata & CATEGORICAL_MASK);
184 return aligned_data.inner_data.stored_value.value;
188 HOST DEVICE auto const&
index()
const {
return aligned_data.inner_data.stored_value.index; }
193 template <
bool has_vector_leaves>
196 if constexpr (has_vector_leaves) {
197 return aligned_data.inner_data.stored_value.index;
199 return aligned_data.inner_data.stored_value.value;
210 auto constexpr
static const LEAF_BIT =
214 auto constexpr
static const DEFAULT_DISTANT_MASK =
218 auto constexpr
static const FEATURE_MASK =
222 auto static constexpr construct_metadata(
bool is_leaf_node =
true,
223 bool default_to_distant_child =
false,
224 bool is_categorical_node =
false,
228 (is_leaf_node << LEAF_BIT) + (default_to_distant_child << DEFAULT_DISTANT_BIT) +
229 (is_categorical_node << CATEGORICAL_BIT) + (feature & FEATURE_MASK));
232 auto static constexpr
const byte_size =
233 detail::get_node_alignment<threshold_t, index_t, metadata_storage_t, offset_t>();
235 struct inner_data_type {
236 value_type stored_value;
242 union aligned_data_type {
243 inner_data_type inner_data;
244 char spacer_data[byte_size];
247 aligned_data_type aligned_data;
#define DEVICE
Definition: gpu_support.hpp:35
#define HOST
Definition: gpu_support.hpp:34
math_t max(math_t a, math_t b)
Definition: learning_rate.h:27
constexpr auto get_node_alignment()
Definition: node.hpp:34
tree_layout
Definition: tree_layout.hpp:19
@ layered_children_together
uint32_t index_type
Definition: index_type.hpp:20
Definition: dbscan.hpp:29
HOST DEVICE constexpr auto output() const
Definition: node.hpp:194
constexpr static auto const layout
Definition: node.hpp:94
threshold_t threshold_type
Definition: node.hpp:96
HOST DEVICE constexpr auto is_categorical() const
Definition: node.hpp:165
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:134
offset_t offset_type
An alias for offset_t.
Definition: node.hpp:114
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:120
HOST DEVICE auto const & index() const
Definition: node.hpp:188
metadata_storage_t metadata_storage_type
An alias for metadata_storage_t.
Definition: node.hpp:112
index_t index_type
Definition: node.hpp:98
HOST DEVICE constexpr auto feature_index() const
Definition: node.hpp:150
HOST DEVICE constexpr auto is_leaf() const
Definition: node.hpp:155
HOST DEVICE constexpr auto child_offset(bool condition) const
Definition: node.hpp:170
HOST DEVICE constexpr auto threshold() const
Definition: node.hpp:182
HOST DEVICE constexpr auto default_distant() const
Definition: node.hpp:160
index_t index
Definition: node.hpp:109
threshold_t value
Definition: node.hpp:108