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

Update the value storage arry

Always have TEMP_STORAGE as an option, but use same size as the TEST SPACE version
parent 86d991b5
......@@ -523,7 +523,7 @@ void FeatureSpace::generate_feature_space()
if(nn <= _n_rung_store)
{
node_value_arrs::resize_values_arr(nn, _phi.size(), (nn != _max_phi));
node_value_arrs::resize_values_arr(nn, _phi.size());
for(int ff = _start_gen.back(); ff < _phi.size(); ++ff)
{
......@@ -845,7 +845,7 @@ void FeatureSpace::sis(const std::vector<double>& prop)
}
// Resize values array for reparameterization
node_value_arrs::resize_values_arr(0, _start_gen[1], true);
node_value_arrs::resize_values_arr(0, _start_gen[1]);
// Reparameterize based on residuals
#pragma omp parallel
{
......@@ -862,7 +862,7 @@ void FeatureSpace::sis(const std::vector<double>& prop)
// Reset the stored feature values
int max_store = (_n_rung_store == _max_phi) ? _phi.size() : _start_gen[_n_rung_store + 1];
node_value_arrs::resize_values_arr(_n_rung_store, max_store, true);
node_value_arrs::resize_values_arr(_n_rung_store, max_store);
for(int ff = _start_gen[1]; ff < max_store; ++ff)
{
_phi[ff]->set_value();
......
......@@ -258,7 +258,10 @@ public:
return node_value_arrs::get_d_matrix_ptr(_d_mat_ind);
}
if(
(rung() > node_value_arrs::N_RUNGS_STORED) &&
(
(rung() > node_value_arrs::N_RUNGS_STORED) ||
(_arr_ind > node_value_arrs::N_STORE_FEATURES)
) &&
(node_value_arrs::temp_storage_reg(_arr_ind, rung(), offset + is_root, for_comp) != _feat_ind)
)
{
......
......@@ -326,7 +326,7 @@ node_ptr str2node::postfix2node(const std::string postfix_expr, const std::vecto
std::vector<node_ptr> str2node::phi_selected_from_file(const std::string filename, const std::vector<node_ptr> phi_0)
{
node_value_arrs::resize_values_arr(0, phi_0.size(), true);
node_value_arrs::resize_values_arr(0, phi_0.size());
node_value_arrs::initialize_d_matrix_arr();
std::ifstream file_stream;
......@@ -365,7 +365,7 @@ std::vector<node_ptr> str2node::phi_selected_from_file(const std::string filenam
std::vector<node_ptr> str2node::phi_from_file(const std::string filename, const std::vector<node_ptr> phi_0)
{
node_value_arrs::resize_values_arr(0, phi_0.size(), true);
node_value_arrs::resize_values_arr(0, phi_0.size());
std::ifstream file_stream;
file_stream.open(filename, std::ios::in);
......
......@@ -8,7 +8,6 @@ int node_value_arrs::N_RUNGS_STORED = 0;
int node_value_arrs::N_SAMPLES_TEST = 0;
int node_value_arrs::MAX_N_THREADS = omp_get_max_threads();
int node_value_arrs::N_OP_SLOTS = 0;
int node_value_arrs::N_OP_TEST_SLOTS = 0;
int node_value_arrs::N_PARAM_OP_SLOTS = 0;
int node_value_arrs::MAX_RUNG = 0;
......@@ -62,16 +61,15 @@ void node_value_arrs::initialize_values_arr(
N_PRIMARY_FEATURES = n_primary_feat;
MAX_RUNG = max_rung;
N_OP_SLOTS = 2 * (static_cast<int>(std::pow(2, max_rung)) - 1);
N_OP_TEST_SLOTS = 2 * (static_cast<int>(std::pow(2, max_rung)) - 1);
VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES);
TEST_VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES_TEST);
TEMP_STORAGE_ARR = std::vector<double>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES);
TEMP_STORAGE_REG = std::vector<int>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1), -1);
TEMP_STORAGE_ARR = std::vector<double>(MAX_N_THREADS * (N_OP_SLOTS * N_PRIMARY_FEATURES + 1) * N_SAMPLES);
TEMP_STORAGE_REG = std::vector<int>(MAX_N_THREADS * (N_OP_SLOTS * N_PRIMARY_FEATURES + 1), -1);
TEMP_STORAGE_TEST_ARR = std::vector<double>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES_TEST);
TEMP_STORAGE_TEST_REG = std::vector<int>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1), -1);
TEMP_STORAGE_TEST_ARR = std::vector<double>(MAX_N_THREADS * (N_OP_SLOTS * N_PRIMARY_FEATURES + 1) * N_SAMPLES_TEST);
TEMP_STORAGE_TEST_REG = std::vector<int>(MAX_N_THREADS * (N_OP_SLOTS * N_PRIMARY_FEATURES + 1), -1);
if(use_params)
{
......@@ -126,7 +124,7 @@ void node_value_arrs::set_task_sz_test(const std::vector<int> task_sz_test)
TASK_SZ_TEST = task_sz_test;
}
void node_value_arrs::resize_values_arr(const int n_dims, const int n_feat, const bool use_temp)
void node_value_arrs::resize_values_arr(const int n_dims, const int n_feat)
{
if(n_dims > MAX_RUNG)
{
......@@ -143,21 +141,21 @@ void node_value_arrs::resize_values_arr(const int n_dims, const int n_feat, cons
VALUES_ARR.resize(N_STORE_FEATURES * N_SAMPLES);
VALUES_ARR.shrink_to_fit();
if(use_temp)
if(n_dims == 0)
{
N_OP_SLOTS = 2 * (static_cast<int>(std::pow(2, MAX_RUNG - N_RUNGS_STORED)) - 1);
N_PRIMARY_FEATURES = N_STORE_FEATURES;
TEMP_STORAGE_ARR.resize(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES);
TEMP_STORAGE_ARR.resize(MAX_N_THREADS * (N_OP_SLOTS * N_PRIMARY_FEATURES + 1) * N_SAMPLES);
TEMP_STORAGE_ARR.shrink_to_fit();
TEMP_STORAGE_REG.resize(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1), - 1);
TEMP_STORAGE_REG.resize(MAX_N_THREADS * (N_OP_SLOTS * N_PRIMARY_FEATURES + 1), - 1);
TEMP_STORAGE_REG.shrink_to_fit();
}
else
{
N_OP_SLOTS = 0;
TEMP_STORAGE_ARR = {};
TEMP_STORAGE_REG = {};
TEMP_STORAGE_TEST_ARR = std::vector<double>(MAX_N_THREADS * (N_OP_SLOTS * N_PRIMARY_FEATURES + 1) * N_SAMPLES_TEST);
TEMP_STORAGE_TEST_ARR.shrink_to_fit();
TEMP_STORAGE_TEST_REG = std::vector<int>(MAX_N_THREADS * (N_OP_SLOTS * N_PRIMARY_FEATURES + 1), -1);
TEMP_STORAGE_TEST_REG.shrink_to_fit();
}
}
......@@ -169,19 +167,15 @@ double* node_value_arrs::get_value_ptr(
const bool for_comp
)
{
if(rung <= N_RUNGS_STORED)
if((rung <= N_RUNGS_STORED) && (arr_ind < N_STORE_FEATURES))
{
if(arr_ind > N_STORE_FEATURES)
{
throw std::logic_error("Requested arr_ind (" + std::to_string(arr_ind) + ") is too high (max " + std::to_string(N_STORE_FEATURES) +")");
}
return access_value_arr(arr_ind);
}
int op_slot = get_op_slot(rung, offset, for_comp);
temp_storage_reg(arr_ind, op_slot) = feat_ind;
return access_temp_storage(
(arr_ind % N_STORE_FEATURES) + (op_slot % N_OP_SLOTS) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1)
(arr_ind % N_PRIMARY_FEATURES) + (op_slot % N_OP_SLOTS) * N_PRIMARY_FEATURES + omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_SLOTS + 1)
);
}
......@@ -202,10 +196,10 @@ double* node_value_arrs::get_test_value_ptr(
return access_test_value_arr(arr_ind);
}
int op_slot = get_op_test_slot(rung, offset, for_comp);
int op_slot = get_op_slot(rung, offset, for_comp);
temp_storage_test_reg(arr_ind, op_slot) = feat_ind;
return access_temp_storage_test(
(arr_ind % N_PRIMARY_FEATURES) + (op_slot % N_OP_TEST_SLOTS) * N_PRIMARY_FEATURES + omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_TEST_SLOTS + 1)
(arr_ind % N_PRIMARY_FEATURES) + (op_slot % N_OP_SLOTS) * N_PRIMARY_FEATURES + omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_SLOTS + 1)
);
}
......
......@@ -44,7 +44,6 @@ namespace node_value_arrs
extern int N_RUNGS_STORED; //!< Number of rungs with values stored
extern int MAX_N_THREADS; //!< Get the maximum number of threads possible
extern int N_OP_SLOTS; //!< The number of possible operator slots
extern int N_OP_TEST_SLOTS; //!< The number of possible operator slots for the test set
extern int N_PARAM_OP_SLOTS; //!< The maximum number of possible operator slots
extern int MAX_RUNG; //!< The maximum rung for all features
......@@ -114,7 +113,7 @@ namespace node_value_arrs
* @param n_feat number of features to store
* @param use_temp If true keep the temporary_storage
*/
void resize_values_arr(const int n_dims, const int n_feat, const bool use_temp);
void resize_values_arr(const int n_dims, const int n_feat);
/**
* @brief Initialize the parameter storage array
......@@ -164,20 +163,6 @@ namespace node_value_arrs
return std::abs(N_OP_SLOTS / (1 + !for_comp) - static_cast<int>(std::pow(2, MAX_RUNG - rung)) - offset);
}
/**
* @brief Get the operator slot associated with a given rung/offset for the test data
*
* @param rung Rung of the feature
* @param offset Offset used to prevent overwrites
* @param for_comp If true get a slot dedicated to comparing features
*
* @return The operator slot to use
*/
inline int get_op_test_slot(const int rung, const int offset, const bool for_comp)
{
return std::abs(N_OP_TEST_SLOTS / (1 + !for_comp) - static_cast<int>(std::pow(2, MAX_RUNG - rung)) - offset);
}
/**
* @brief Get the parameter operator slot associated with a given rung/offset
*
......@@ -203,7 +188,7 @@ namespace node_value_arrs
inline int& temp_storage_reg(const unsigned long int ind, const int op_slot=0)
{
return TEMP_STORAGE_REG[
(ind % N_STORE_FEATURES) + (op_slot % N_OP_SLOTS) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1)
(ind % N_PRIMARY_FEATURES) + (op_slot % N_OP_SLOTS) * N_PRIMARY_FEATURES + omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_SLOTS + 1)
];
}
......@@ -218,7 +203,7 @@ namespace node_value_arrs
inline int& temp_storage_test_reg(const unsigned long int ind, const int op_slot=0)
{
return TEMP_STORAGE_TEST_REG[
(ind % N_PRIMARY_FEATURES) + (op_slot % N_OP_TEST_SLOTS) * N_PRIMARY_FEATURES + omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_TEST_SLOTS + 1)
(ind % N_PRIMARY_FEATURES) + (op_slot % N_OP_SLOTS) * N_PRIMARY_FEATURES + omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_SLOTS + 1)
];
}
......@@ -235,9 +220,9 @@ namespace node_value_arrs
inline int& temp_storage_reg(const unsigned long int ind, const int rung, const int offset, const bool for_comp)
{
return TEMP_STORAGE_REG[
(ind % N_STORE_FEATURES) +
(get_op_slot(rung, offset, for_comp) % N_OP_SLOTS) * N_STORE_FEATURES +
omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1)
(ind % N_PRIMARY_FEATURES) +
(get_op_slot(rung, offset, for_comp) % N_OP_SLOTS) * N_PRIMARY_FEATURES +
omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_SLOTS + 1)
];
}
......@@ -255,8 +240,8 @@ namespace node_value_arrs
{
return TEMP_STORAGE_TEST_REG[
(ind % N_PRIMARY_FEATURES) +
(get_op_test_slot(rung, offset, for_comp) % N_OP_TEST_SLOTS) * N_PRIMARY_FEATURES +
omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_TEST_SLOTS + 1)
(get_op_slot(rung, offset, for_comp) % N_OP_SLOTS) * N_PRIMARY_FEATURES +
omp_get_thread_num() * (N_PRIMARY_FEATURES * N_OP_SLOTS + 1)
];
}
......@@ -392,7 +377,7 @@ namespace node_value_arrs
*/
inline void clear_temp_reg_thread()
{
std::fill_n(TEMP_STORAGE_REG.begin() + (N_STORE_FEATURES * N_OP_SLOTS + 1) * omp_get_thread_num(), N_STORE_FEATURES * N_OP_SLOTS + 1, -1);
std::fill_n(TEMP_STORAGE_REG.begin() + (N_PRIMARY_FEATURES * N_OP_SLOTS + 1) * omp_get_thread_num(), N_PRIMARY_FEATURES * N_OP_SLOTS + 1, -1);
}
/**
......
......@@ -27,7 +27,7 @@ FeatureNode::FeatureNode(unsigned long int feat_ind, std::string expr, np::ndarr
}
else if(feat_ind >= node_value_arrs::N_STORE_FEATURES)
{
node_value_arrs::resize_values_arr(0, node_value_arrs::N_STORE_FEATURES + 1, true);
node_value_arrs::resize_values_arr(0, node_value_arrs::N_STORE_FEATURES + 1);
}
set_value();
......@@ -62,7 +62,7 @@ FeatureNode::FeatureNode(unsigned long int feat_ind, std::string expr, py::list
}
else if(feat_ind >= node_value_arrs::N_STORE_FEATURES)
{
node_value_arrs::resize_values_arr(0, node_value_arrs::N_STORE_FEATURES + 1, true);
node_value_arrs::resize_values_arr(0, node_value_arrs::N_STORE_FEATURES + 1);
}
set_value();
......
......@@ -21,31 +21,21 @@ namespace {
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_TEST_ARR.size(), node_value_arrs::MAX_N_THREADS * (6 * 1 + 1) * 2);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_TEST_REG.size(), node_value_arrs::MAX_N_THREADS * (6 * 1 + 1));
node_value_arrs::resize_values_arr(1, 2, false);
node_value_arrs::resize_values_arr(1, 2);
EXPECT_EQ(node_value_arrs::N_SAMPLES, 5);
EXPECT_EQ(node_value_arrs::N_SAMPLES_TEST, 2);
EXPECT_EQ(node_value_arrs::N_RUNGS_STORED, 1);
EXPECT_EQ(node_value_arrs::N_STORE_FEATURES, 2);
EXPECT_EQ(node_value_arrs::N_OP_SLOTS, 0);
EXPECT_EQ(node_value_arrs::VALUES_ARR.size(), 10);
EXPECT_EQ(node_value_arrs::TEST_VALUES_ARR.size(), 2);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_ARR.size(), 0);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_REG.size(), 0);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_TEST_ARR.size(), 28);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_TEST_REG.size(), 14);
node_value_arrs::resize_values_arr(1, 2, true);
node_value_arrs::resize_values_arr(1, 2);
EXPECT_EQ(node_value_arrs::N_SAMPLES, 5);
EXPECT_EQ(node_value_arrs::N_SAMPLES_TEST, 2);
EXPECT_EQ(node_value_arrs::N_RUNGS_STORED, 1);
EXPECT_EQ(node_value_arrs::N_STORE_FEATURES, 2);
EXPECT_EQ(node_value_arrs::N_OP_SLOTS, 2);
EXPECT_EQ(node_value_arrs::VALUES_ARR.size(), 10);
EXPECT_EQ(node_value_arrs::TEST_VALUES_ARR.size(), 2);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_ARR.size(), node_value_arrs::MAX_N_THREADS * (2 * 2 + 1) * 5);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_REG.size(), node_value_arrs::MAX_N_THREADS * (2 * 2 + 1));
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_TEST_ARR.size(), 28);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_TEST_REG.size(), 14);
node_value_arrs::initialize_d_matrix_arr();
EXPECT_EQ(node_value_arrs::N_SELECTED, 0);
......@@ -65,13 +55,13 @@ namespace {
node_value_arrs::get_test_value_ptr(0, 1, 0, 0)[1] = 1.0;
EXPECT_EQ(node_value_arrs::TEST_VALUES_ARR[1], 1.0);
node_value_arrs::get_value_ptr(10, 141, 2, 0)[1] = 1.0;
node_value_arrs::get_value_ptr(10, 141, 2, 0)[0] = 1.0;
EXPECT_EQ(node_value_arrs::temp_storage_reg(10, 2, 0, false), 141);
EXPECT_EQ(node_value_arrs::access_temp_storage((10 % 2) + omp_get_thread_num() * (2 * 1 + 1))[1], 1.0);
EXPECT_EQ(node_value_arrs::access_temp_storage(node_value_arrs::get_op_slot(2, 0, false))[0], 1.0);
node_value_arrs::get_test_value_ptr(10, 141, 2, 0)[1] = 1.0;
node_value_arrs::get_test_value_ptr(10, 141, 2, 0)[0] = 1.0;
EXPECT_EQ(node_value_arrs::temp_storage_test_reg(10, 2, 0, false), 141);
EXPECT_EQ(node_value_arrs::access_temp_storage_test(node_value_arrs::get_op_test_slot(2, 0, false))[1], 1.0);
EXPECT_EQ(node_value_arrs::access_temp_storage_test(node_value_arrs::get_op_slot(2, 0, false))[0], 1.0);
node_value_arrs::get_d_matrix_ptr(1)[0] = 1.0;
EXPECT_EQ(node_value_arrs::D_MATRIX[5], 1.0);
......@@ -79,9 +69,9 @@ namespace {
#pragma omp parallel
{
std::fill_n(node_value_arrs::TEMP_STORAGE_REG.data() + 5 * omp_get_thread_num(), 5, omp_get_thread_num() + 1);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_REG[5 * omp_get_thread_num()], omp_get_thread_num() + 1);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_REG[7 * omp_get_thread_num()], omp_get_thread_num() + 1);
node_value_arrs::clear_temp_reg_thread();
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_REG[5 * omp_get_thread_num()], -1);
EXPECT_EQ(node_value_arrs::TEMP_STORAGE_REG[7 * omp_get_thread_num()], -1);
}
std::fill_n(node_value_arrs::TEMP_STORAGE_REG.data(), node_value_arrs::TEMP_STORAGE_REG.size(), 2.0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment