Feat C++ API
A feature engineering automation tool
n_variable.cc
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 
6 #include "n_variable.h"
7 
8 namespace FT{
9 
10  namespace Pop{
11  namespace Op{
12 
13  template <class T>
15  {
16  name = "variable";
17  loc = -1;
18  complexity = 1;
19  }
20 
21  template <class T>
22  NodeVariable<T>::NodeVariable(const size_t& l, char ntype, std::string n)
23  {
24  name = "variable";
25  if (n.empty())
26  variable_name = "x_" + std::to_string(l);
27  else
28  variable_name = n;
29  otype = ntype;
30  complexity = 1;
31  loc = l;
32  }
33 
34  #ifndef USE_CUDA
36  template <class T>
37  void NodeVariable<T>::evaluate(const Data& data, State& state)
38  {
39  state.push<T>(data.X.row(loc).template cast<T>());
40  }
41 
42  #else
43  template <class T>
44  void NodeVariable<T>::evaluate(const Data& data, State& state)
45  {
46  if(otype == 'b')
47  {
48  ArrayXb tmp = data.X.row(loc).cast<bool>();
49  GPU_Variable(state.dev_b, tmp.data(), state.idx[otype], state.N);
50  }
51  else if (otype == 'c')
52  {
53  ArrayXi tmp = data.X.row(loc).cast<int>();
54  GPU_Variable(state.dev_c, tmp.data(), state.idx[otype], state.N);
55  }
56  else
57  {
58  ArrayXf tmp = data.X.row(loc).cast<float>() ;
59  GPU_Variable(state.dev_f, tmp.data(), state.idx[otype], state.N);
60  }
61  }
62  #endif
63 
65  template <class T>
67  {
68  state.push<T>(variable_name);
69  }
70 
71  template <class T>
73 
74  // rnd_clone is just clone_impl() for variable, since rand vars not supported
75  template <class T>
77 
78  template class NodeVariable<bool>;
79  template class NodeVariable<int>;
80  template class NodeVariable<float>;
81  }
82  }
83 }
data holding X, y, and Z data
Definition: data.h:42
MatrixXf & X
Definition: data.h:45
NodeVariable * clone_impl() const override
Definition: n_variable.cc:72
void evaluate(const Data &data, State &state)
Evaluates the node and updates the state states.
Definition: n_variable.cc:37
NodeVariable * rnd_clone_impl() const override
Definition: n_variable.cc:76
void eval_eqn(State &state)
Evaluates the node symbolically.
Definition: n_variable.cc:66
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
Definition: data.h:21
void GPU_Variable(float *dev_x, float *host_x, size_t idx, size_t N)
std::string to_string(const T &value)
template function to convert objects to string for logging
Definition: utils.h:422
main Feat namespace
Definition: data.cc:13
contains various types of State actually used by feat
Definition: state.h:102
void push(Eigen::Array< T, Eigen::Dynamic, 1 > value)
Definition: state.h:123