10 #include "../pop/op/node.h"
50 for (
int i = 0;
i <
arity.at(
'f');
i++) {
55 for (
int i = 0;
i <
arity.at(
'c');
i++) {
60 for (
int i = 0;
i <
arity.at(
'b');
i++) {
67 using namespace Pop::Op;
76 void State::update_idx(
char otype, std::map<char, unsigned>&
arity)
79 for (
const auto& a :
arity)
80 idx.at(a.first) -= a.second;
86 return (f.rows() >=
arity.at(
'f') &&
87 c.rows() >=
arity.at(
'c') &&
88 b.rows() >=
arity.at(
'b'));
90 return (f.rows() >=
arity.at(
'f') &&
91 c.rows() >=
arity.at(
'c') &&
92 b.rows() >=
arity.at(
'b') &&
93 z.size() >=
arity.at(
'z'));
99 return (fs.size() >=
arity.at(
'f') &&
100 cs.size() >=
arity.at(
'c') &&
101 bs.size() >=
arity.at(
'b'));
103 return (fs.size() >=
arity.at(
'f') &&
104 cs.size() >=
arity.at(
'c') &&
105 bs.size() >=
arity.at(
'b') &&
106 zs.size() >=
arity.at(
'z'));
109 void State::allocate(
const std::map<char, size_t>& stack_size,
size_t N)
113 dev_c, N*stack_size.at(
'c'),
114 dev_b, N*stack_size.at(
'b'));
122 f.resize(stack_size.at(
'f'),N);
123 c.resize(stack_size.at(
'c'),N);
124 b.resize(stack_size.at(
'b'),N);
130 for (
unsigned r = 0 ;
r < f.rows(); ++
r)
134 f.row(
r) = (
isnan(f.row(
r))).select(0,f.row(
r));
137 for (
unsigned r = 0 ;
r < c.rows(); ++
r)
141 c.row(
r) = (
isnan(c.row(
r))).select(0, c.row(
r));
156 f.conservativeResize(idx.at(
'f'), f.cols());
157 c.conservativeResize(idx.at(
'c'), c.cols());
158 b.conservativeResize(idx.at(
'b'), b.cols());
161 void State::copy_to_host()
169 dev_c, c.data(), N*idx.at(
'c'),
170 dev_b, b.data(), N*idx.at(
'b'));
177 void State::copy_to_host(
float* host_f,
int increment)
182 void State::copy_to_host(
int* host_i,
int increment)
196 for (
int i = 0;
i <
arity.at(
'f');
i++)
198 ArrayXf tmp(state.N);
200 increment = (state.idx.at(
'f') - (
arity.at(
'f') -
i))*state.N;
209 f.push_back(tmp.cast<
float>());
212 for (
int i = 0;
i <
arity.at(
'c');
i++)
214 ArrayXi tmp(state.N);
216 increment = (state.idx.at(
'c') - (
arity.at(
'c') -
i))*state.N;
222 for (
int i = 0;
i <
arity.at(
'b');
i++)
226 increment = (state.idx.at(
'b') - (
arity.at(
'b') -
i))*state.N;
unsigned int size()
returns top element of stack
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
void free_device(float *dev_f, int *dev_c, bool *dev_b)
void copy_from_device(float *dev_f, float *host_f, size_t Sizef)
void dev_allocate(float *&f, size_t Sizef, int *&c, size_t Sizec, bool *&b, size_t Sizeb)
ArrayXb isnan(const ArrayXf &x)
returns true for elements of x that are NaN
std::string trim(std::string str, const std::string &chars)
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
bool check_s(std::map< char, unsigned int > &arity)
Stack< string > bs
boolean node string stack
Stack< std::pair< vector< ArrayXf >, vector< ArrayXf > > > z
longitudinal node stack
bool check(std::map< char, unsigned int > &arity)
checks if arity of node provided satisfies the node names in various string State
Stack< string > cs
categorical node string stack
Stack< ArrayXi > c
categorical stack
Stack< ArrayXf > f
floating node stack
void copy_to_trace(State &state, std::map< char, unsigned int > &arity)