node.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-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 
17 #pragma once
18 
19 #include <cstdint>
20 #include <string>
21 
22 namespace cuml {
23 namespace genetic {
24 
38 struct node {
43  enum class type : uint32_t {
44  variable = 0,
45  constant,
46 
47  // note: keep the case statements in alphabetical order under each category
48  // of operators.
50  // different binary function types follow
52  add = binary_begin,
53  atan2,
54  div,
55  fdim,
56  max,
57  min,
58  mul,
59  pow,
60  sub,
61  binary_end = sub, // keep this to be the last binary function in the list
62  // different unary function types follow
64  abs = unary_begin,
65  acos,
66  acosh,
67  asin,
68  asinh,
69  atan,
70  atanh,
71  cbrt,
72  cos,
73  cosh,
74  cube,
75  exp,
76  inv,
77  log,
78  neg,
79  rcbrt,
80  rsqrt,
81  sin,
82  sinh,
83  sq,
84  sqrt,
85  tan,
86  tanh,
87  unary_end = tanh, // keep this to be the last unary function in the list
89  }; // enum type
90 
94  explicit node();
95 
101  explicit node(type ft);
102 
108  explicit node(int fid);
109 
115  explicit node(float val);
116 
120  explicit node(const node& src);
121 
129  node& operator=(const node& src);
130 
132  bool is_terminal() const;
133 
135  bool is_nonterminal() const;
136 
138  int arity() const;
139 
148  static type from_str(const std::string& ntype);
149 
151  static const int kInvalidFeatureId;
152 
155  union {
160  int fid;
162  float val;
163  } u;
164 }; // struct node
165 
166 } // namespace genetic
167 } // namespace cuml
Definition: common.h:26
Represents a node in the syntax tree.
Definition: node.h:38
node & operator=(const node &src)
assignment operator
node(int fid)
Construct a variable node.
int fid
Definition: node.h:160
static const int kInvalidFeatureId
Definition: node.h:151
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:154
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:43
node(float val)
Construct a constant node.
float val
Definition: node.h:162
static type from_str(const std::string &ntype)
Helper method to get node type from input string.
node(const node &src)