Commit efa729e2 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Seperate out parameter and temp storage arrays

Should remove any overwrite issues
parent e49f6ac5
......@@ -515,17 +515,7 @@ void FeatureSpace::generate_feature_space()
if(nn <= _n_rung_store)
{
#ifdef PARAMETERIZE
bool use_temp = (
(nn != _max_phi) ||
(_un_param_operators.size() > 0) ||
(_bin_param_operators.size() > 0) ||
(_com_bin_param_operators.size() > 0)
);
#else
bool use_temp = (nn != _max_phi);
#endif
node_value_arrs::resize_values_arr(nn, _phi.size(), use_temp);
node_value_arrs::resize_values_arr(nn, _phi.size(), (nn != _max_phi));
for(int ff = _start_gen.back(); ff < _phi.size(); ++ff)
{
......
......@@ -232,15 +232,19 @@ public:
*/
virtual double* value_ptr(int offset=-1, const bool for_comp=false) const
{
if(_selected && (offset == -1))
bool is_root = (offset == -1);
if(_selected && is_root)
{
return node_value_arrs::get_d_matrix_ptr(_d_mat_ind);
}
offset += (offset == -1);
if((rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_arr_ind, rung(), offset, for_comp) != _feat_ind))
if(
(rung() > node_value_arrs::N_RUNGS_STORED) &&
(node_value_arrs::temp_storage_reg(_arr_ind, rung(), offset + is_root, for_comp) != _feat_ind)
)
{
set_value(offset, for_comp);
}
offset += is_root;
return node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp);
}
......@@ -257,11 +261,15 @@ public:
virtual double* test_value_ptr(int offset=-1, const bool for_comp=false) const
{
offset += (offset == -1);
if((rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_test_reg(_arr_ind, rung(), offset, for_comp) != _feat_ind))
bool is_root = (offset == -1);
if(
(rung() > node_value_arrs::N_RUNGS_STORED) &&
(node_value_arrs::temp_storage_test_reg(_arr_ind, rung(), offset + is_root, for_comp) != _feat_ind)
)
{
set_test_value(offset, for_comp);
}
offset += is_root;
return node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp);
}
......@@ -478,10 +486,10 @@ public:
{
return node_value_arrs::get_d_matrix_ptr(_d_mat_ind);
}
set_value(params, offset, for_comp, depth);
offset += (offset == -1);
set_value(params, offset, for_comp, depth);
return node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
return node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
/**
......@@ -505,10 +513,10 @@ public:
*/
double* test_value_ptr(const double* params, int offset=-1, const bool for_comp=false, const int depth=0) const
{
offset += (offset == -1);
set_test_value(params, offset, for_comp, depth);
return node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
offset += (offset == -1);
return node_value_arrs::access_param_storage_test(rung(), offset, for_comp);
}
/**
......
......@@ -22,7 +22,7 @@ void generateAbsNode(
}
int offset = -1;
double* val_ptr = feat->value_ptr(2 * offset);
double* val_ptr = feat->value_ptr(offset);
// If the feature is strictly positive absolute values do nothing
if(*std::min_element(val_ptr, val_ptr + feat->n_samp()) > 0.0)
{
......
......@@ -107,7 +107,7 @@ void AbsNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* val_ptr;
......@@ -117,7 +117,7 @@ void AbsNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::abs(_n_samp, vp_0, params[0], params[1], val_ptr);
......@@ -134,11 +134,11 @@ void AbsNode::set_test_value(const double* params, int offset, const bool for_co
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
allowed_op_funcs::abs(
_n_test_samp, vp_0, params[0], params[1], node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)
_n_test_samp, vp_0, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp)
);
}
......
......@@ -137,17 +137,17 @@ void AbsDiffNode::set_value(const double* params, int offset, const bool for_com
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* vp_1;
if(depth < nlopt_wrapper::MAX_PARAM_DEPTH)
{
vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, depth + 1);
vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1);
}
else
{
vp_1 = _feats[1]->value_ptr(2 * offset + 1);
vp_1 = _feats[1]->value_ptr(2 * offset + 1, for_comp);
}
double* val_ptr;
......@@ -157,7 +157,7 @@ void AbsDiffNode::set_value(const double* params, int offset, const bool for_com
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::abs_diff(_n_samp, vp_0, vp_1, params[0], params[1], val_ptr);
......@@ -174,21 +174,21 @@ void AbsDiffNode::set_test_value(const double* params, int offset, const bool fo
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
double* vp_1;
if(depth < nlopt_wrapper::MAX_PARAM_DEPTH)
{
vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, depth + 1);
vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1);
}
else
{
vp_1 = _feats[1]->test_value_ptr(2 * offset + 1);
vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp);
}
allowed_op_funcs::abs_diff(
_n_test_samp, vp_0, vp_1, params[0], params[1], node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)
_n_test_samp, vp_0, vp_1, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp)
);
}
......
......@@ -142,18 +142,26 @@ void AddNode::update_div_mult_leaves(std::map<std::string, double>& div_mult_lea
void AddNode::set_value(int offset, const bool for_comp) const
{
double* val_ptr;
if(_selected && (offset == -1))
bool is_root = (offset == -1);
if(_selected && is_root)
{
offset += (offset == -1);
offset += is_root;
val_ptr = node_value_arrs::get_d_matrix_ptr(_d_mat_ind);
}
else
{
offset += (offset == -1);
offset += is_root;
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp);
}
allowed_op_funcs::add(_n_samp, _feats[0]->value_ptr(2 * offset, for_comp), _feats[1]->value_ptr(2 * offset + 1, for_comp), 1.0, 0.0, val_ptr);
allowed_op_funcs::add(
_n_samp,
_feats[0]->value_ptr(2 * offset, for_comp),
_feats[1]->value_ptr(2 * offset + 1, for_comp),
1.0,
0.0,
val_ptr
);
}
void AddNode::set_test_value(int offset, const bool for_comp) const
......
......@@ -241,7 +241,7 @@ public:
inline std::string get_latex_expr(const double* params, const int depth=1) const
{
return fmt::format(
"\\left({} + {:.3}*{}\\right)",
"\\left({} + {:.3}{}\\right)",
(depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->get_latex_expr(params + _feats[1]->n_params() + 2, depth + 1) : _feats[0]->get_latex_expr()),
params[0],
(depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->get_latex_expr(params + 2, depth + 1) : _feats[0]->get_latex_expr())
......
......@@ -100,17 +100,17 @@ void AddNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* vp_1;
if(depth < nlopt_wrapper::MAX_PARAM_DEPTH)
{
vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, depth + 1);
vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1);
}
else
{
vp_1 = _feats[1]->value_ptr(2 * offset + 1);
vp_1 = _feats[1]->value_ptr(2 * offset + 1, for_comp);
}
double* val_ptr;
......@@ -120,7 +120,7 @@ void AddNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::add(_n_samp, vp_0, vp_1, params[0], params[1], val_ptr);
......@@ -137,17 +137,17 @@ void AddNode::set_test_value(const double* params, int offset, const bool for_co
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
double* vp_1;
if(depth < nlopt_wrapper::MAX_PARAM_DEPTH)
{
vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, depth + 1);
vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1);
}
else
{
vp_1 = _feats[1]->test_value_ptr(2 * offset + 1);
vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp);
}
allowed_op_funcs::add(
......@@ -156,7 +156,7 @@ void AddNode::set_test_value(const double* params, int offset, const bool for_co
vp_1,
params[0],
params[1],
node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)
node_value_arrs::access_param_storage_test(rung(), offset, for_comp)
);
}
......
......@@ -134,7 +134,7 @@ void CbNode::set_value(const double* params, int offset, const bool for_comp, co
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* val_ptr;
......@@ -144,7 +144,7 @@ void CbNode::set_value(const double* params, int offset, const bool for_comp, co
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::cb(_n_samp, vp_0, params[0], params[1], val_ptr);
......@@ -161,15 +161,15 @@ void CbNode::set_test_value(const double* params, int offset, const bool for_com
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
allowed_op_funcs::cb(
_n_test_samp,
_feats[0]->test_value_ptr(params + 2, 2 * offset),
vp_0,
params[0],
params[1],
node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)
node_value_arrs::access_param_storage_test(rung(), offset, for_comp)
);
}
......
......@@ -121,7 +121,7 @@ void CbrtNode::set_value(const double* params, int offset, const bool for_comp,
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* val_ptr;
......@@ -131,7 +131,7 @@ void CbrtNode::set_value(const double* params, int offset, const bool for_comp,
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::cbrt(_n_samp, vp_0, params[0], params[1], val_ptr);
......@@ -147,15 +147,15 @@ void CbrtNode::set_test_value(const double* params, int offset, const bool for_c
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
allowed_op_funcs::cbrt(
_n_test_samp,
_feats[0]->test_value_ptr(params + 2, 2 * offset),
vp_0,
params[0],
params[1],
node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)
node_value_arrs::access_param_storage_test(rung(), offset, for_comp)
);
}
......
......@@ -120,7 +120,7 @@ void CosNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* val_ptr;
......@@ -130,7 +130,7 @@ void CosNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::cos(_n_samp, vp_0, params[0], params[1], val_ptr);
......@@ -147,15 +147,15 @@ void CosNode::set_test_value(const double* params, int offset, const bool for_co
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
allowed_op_funcs::cos(
_n_test_samp,
_feats[0]->test_value_ptr(params + 2, 2 * offset),
vp_0,
params[0],
params[1],
node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)
node_value_arrs::access_param_storage_test(rung(), offset, for_comp)
);
}
......
......@@ -127,17 +127,17 @@ void DivNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* vp_1;
if(depth < nlopt_wrapper::MAX_PARAM_DEPTH)
{
vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, depth + 1);
vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1);
}
else
{
vp_1 = _feats[1]->value_ptr(2 * offset + 1);
vp_1 = _feats[1]->value_ptr(2 * offset + 1, for_comp);
}
double* val_ptr;
......@@ -147,7 +147,7 @@ void DivNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::div(_n_samp, vp_0, vp_1, params[0], params[1], val_ptr);
......@@ -164,17 +164,17 @@ void DivNode::set_test_value(const double* params, int offset, const bool for_co
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
double* vp_1;
if(depth < nlopt_wrapper::MAX_PARAM_DEPTH)
{
vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, depth + 1);
vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1);
}
else
{
vp_1 = _feats[1]->test_value_ptr(2 * offset + 1);
vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp);
}
allowed_op_funcs::div(
_n_test_samp,
......@@ -182,7 +182,7 @@ void DivNode::set_test_value(const double* params, int offset, const bool for_co
vp_1,
params[0],
params[1],
node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)
node_value_arrs::access_param_storage_test(rung(), offset, for_comp)
);
}
......
......@@ -132,7 +132,7 @@ void ExpNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* val_ptr;
......@@ -142,7 +142,7 @@ void ExpNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::exp(_n_samp, vp_0, params[0], params[1], val_ptr);
......@@ -159,15 +159,15 @@ void ExpNode::set_test_value(const double* params, int offset, const bool for_co
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
allowed_op_funcs::exp(
_n_test_samp,
_feats[0]->test_value_ptr(params + 2, 2 * offset),
vp_0,
params[0],
params[1],
node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)
node_value_arrs::access_param_storage_test(rung(), offset, for_comp)
);
}
......
......@@ -128,7 +128,7 @@ void InvNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* val_ptr;
......@@ -138,7 +138,7 @@ void InvNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::inv(_n_samp, vp_0, params[0], params[1], val_ptr);
......@@ -155,10 +155,10 @@ void InvNode::set_test_value(const double* params, int offset, const bool for_co
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
allowed_op_funcs::inv(_n_test_samp, vp_0, params[0], params[1], node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false));
allowed_op_funcs::inv(_n_test_samp, vp_0, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp));
}
void InvNode::set_bounds(double* lb, double* ub, const int depth) const
......
......@@ -156,7 +156,7 @@ void LogNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
vp_0 = _feats[0]->value_ptr(2 * offset);
vp_0 = _feats[0]->value_ptr(2 * offset, for_comp);
}
double* val_ptr;
......@@ -166,7 +166,7 @@ void LogNode::set_value(const double* params, int offset, const bool for_comp, c
}
else
{
val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false);
val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp);
}
allowed_op_funcs::log(_n_samp, vp_0, params[0], params[1], val_ptr);
......@@ -182,15 +182,15 @@ void LogNode::set_test_value(const double* params, int offset, const bool for_co
}
else
{
vp_0 = _feats[0]->test_value_ptr(2 * offset);
vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp);
}
allowed_op_funcs::log(
_n_test_samp,