node.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2023, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cstdint>
9 #include <string>
10 
11 namespace cuml {
12 namespace genetic {
13 
27 struct node {
32  enum class type : uint32_t {
33  variable = 0,
34  constant,
35 
36  // note: keep the case statements in alphabetical order under each category
37  // of operators.
39  // different binary function types follow
41  add = binary_begin,
42  atan2,
43  div,
44  fdim,
45  max,
46  min,
47  mul,
48  pow,
49  sub,
50  binary_end = sub, // keep this to be the last binary function in the list
51  // different unary function types follow
53  abs = unary_begin,
54  acos,
55  acosh,
56  asin,
57  asinh,
58  atan,
59  atanh,
60  cbrt,
61  cos,
62  cosh,
63  cube,
64  exp,
65  inv,
66  log,
67  neg,
68  rcbrt,
69  rsqrt,
70  sin,
71  sinh,
72  sq,
73  sqrt,
74  tan,
75  tanh,
76  unary_end = tanh, // keep this to be the last unary function in the list
78  }; // enum type
79 
83  explicit node();
84 
90  explicit node(type ft);
91 
97  explicit node(int fid);
98 
104  explicit node(float val);
105 
109  explicit node(const node& src);
110 
118  node& operator=(const node& src);
119 
121  bool is_terminal() const;
122 
124  bool is_nonterminal() const;
125 
127  int arity() const;
128 
137  static type from_str(const std::string& ntype);
138 
140  static const int kInvalidFeatureId;
141 
144  union {
149  int fid;
151  float val;
152  } u;
153 }; // struct node
154 
155 } // namespace genetic
156 } // namespace cuml
Definition: common.h:15
Represents a node in the syntax tree.
Definition: node.h:27
node & operator=(const node &src)
assignment operator
node(int fid)
Construct a variable node.
int fid
Definition: node.h:149
static const int kInvalidFeatureId
Definition: node.h:140
node()
Default constructor for node.
bool is_nonterminal() const
node(type ft)
Construct a function node.
union cuml::genetic::node::@0 u
type t
Definition: node.h:143
bool is_terminal() const
type
All possible types of nodes. For simplicity, all the terminal and non-terminal types are clubbed toge...
Definition: node.h:32
node(float val)
Construct a constant node.
float val
Definition: node.h:151
static type from_str(const std::string &ntype)
Helper method to get node type from input string.
node(const node &src)