10 #include "../pop/cuda-op/state_utils.h"
14 #include <Eigen/Dense>
20 using Eigen::MatrixXf;
21 using Eigen::VectorXf;
24 typedef Eigen::Array<bool,Eigen::Dynamic,1>
ArrayXb;
33 template<
typename type>
48 st = std::vector<type>();
52 void push(type element){ st.push_back(element); }
63 bool empty(){
return st.empty(); }
66 unsigned int size(){
return st.size(); }
69 type&
top(){
return st.back(); }
72 type&
at(
int i){
return st.at(
i); }
82 typename vector<type>::iterator
begin(){
return st.begin(); }
85 typename vector<type>::iterator
end(){
return st.end(); }
88 typename vector<type>::const_iterator
begin()
const{
return st.begin(); }
91 typename vector<type>::const_iterator
end()
const{
return st.end(); }
113 bool check(std::map<char, unsigned int> &
arity);
116 bool check_s(std::map<char, unsigned int> &
arity);
120 return get<Eigen::Array<T,Eigen::Dynamic,1> >();
123 template <
typename T>
void push(Eigen::Array<T,Eigen::Dynamic,1> value)
125 get<T>().push(value);
128 template <
typename T> Eigen::Array<T,Eigen::Dynamic,1>
pop()
130 return get<T>().pop();
138 template <
typename T>
void push(
string value)
140 getStr<T>().push(value);
145 return getStr<T>().pop();
148 template <
typename T>
unsigned int size()
150 return get<T>().size();
165 Eigen::Array<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> f;
166 Eigen::Array<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> c;
167 Eigen::Array<bool, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> b;
177 std::map<char, size_t> idx;
182 void update_idx(
char otype, std::map<char, unsigned>&
arity);
184 bool check(std::map<char, unsigned int> &
arity);
186 bool check_s(std::map<char, unsigned int> &
arity);
188 void allocate(
const std::map<char, size_t>& stack_size,
size_t N);
197 void copy_to_host(
float* host_f,
int increment);
199 void copy_to_host(
int* host_f,
int increment);
208 template <
typename T>
void push(
string value)
210 getStr<T>().push(value);
213 template <
typename T>
string popStr()
215 return getStr<T>().pop();
221 template <>
inline Stack<string>& State::getStr<float>(){
return fs; }
223 template <>
inline Stack<string>& State::getStr<bool>(){
return bs; }
225 template <>
inline Stack<string>& State::getStr<int>(){
return cs; }
237 template <
typename T>
inline vector<Eigen::Array<T,Eigen::Dynamic,1> >&
get()
239 return get<Eigen::Array<T,Eigen::Dynamic,1> >();
242 template <
typename T>
unsigned int size()
244 return get<T>().size();
247 void copy_to_trace(
State& state, std::map<char, unsigned int> &
arity);
250 template <>
inline vector<ArrayXf>& Trace::get(){
return f; }
252 template <>
inline vector<ArrayXb>& Trace::get(){
return b; }
254 template <>
inline vector<ArrayXi>& Trace::get(){
return c; }
template stack class which holds various stack types for feat
type pop()
returns true or false depending on stack is empty or not
type & top()
returns element at particular location in stack
unsigned int size()
returns top element of stack
vector< type >::const_iterator begin() const
returns const iterator of stack
void clear()
clears the stack
std::vector< type > st
vector representing the stack
vector< type >::const_iterator end() const
bool empty()
returns size of stack
void push(type element)
pops element from back of vector and removes it
vector< type >::iterator begin()
returns end iterator of stack
vector< type >::iterator end()
returns const start iterator of stack
Stack()
< constructor initializing the vector
std::string trim(std::string str, const std::string &chars)
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
contains various types of State actually used by feat
Stack< ArrayXb > b
boolean node stack
Stack< string > fs
floating node string stack
Stack< string > zs
longitudinal node string stack
Stack< string > bs
boolean node string stack
Stack< std::pair< vector< ArrayXf >, vector< ArrayXf > > > z
longitudinal node stack
Stack< Eigen::Array< T, Eigen::Dynamic, 1 > > & get()
Eigen::Array< T, Eigen::Dynamic, 1 > pop()
Stack< string > cs
categorical node string stack
Stack< ArrayXi > c
categorical stack
Stack< string > & getStr()
Stack< ArrayXf > f
floating node stack
void push(Eigen::Array< T, Eigen::Dynamic, 1 > value)
used for tracing stack outputs for backprop algorithm.
vector< Eigen::Array< T, Eigen::Dynamic, 1 > > & get()