Commit 02f266ab authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Resizing ValueArrays now works properly

Possible to resize based off of rung
parent 4e18d8e8
...@@ -64,9 +64,7 @@ void FeatureSpace::generate_feature_space() ...@@ -64,9 +64,7 @@ void FeatureSpace::generate_feature_space()
_n_feat = _phi.size(); _n_feat = _phi.size();
std::array<int, 2> start_end = _mpi_comm->get_start_end_for_iterator(_phi.size() - _start_gen[_start_gen.size()-1], _start_gen[_start_gen.size()-1]); std::array<int, 2> start_end = _mpi_comm->get_start_end_for_iterator(_phi.size() - _start_gen[_start_gen.size()-1], _start_gen[_start_gen.size()-1]);
int feat_ind = _n_feat + node_value_arrs::get_max_number_features(_allowed_ops, 1, start_end[0]); int feat_ind = 0;
next_phi.reserve(node_value_arrs::get_max_number_features(_allowed_ops, 1, start_end[1] - start_end[0]));
for(auto feat_1 = _phi.begin() + start_end[0]; feat_1 != _phi.begin() + start_end[1]; ++feat_1) for(auto feat_1 = _phi.begin() + start_end[0]; feat_1 != _phi.begin() + start_end[1]; ++feat_1)
{ {
...@@ -130,26 +128,30 @@ void FeatureSpace::generate_feature_space() ...@@ -130,26 +128,30 @@ void FeatureSpace::generate_feature_space()
std::vector<std::vector<node_ptr>> next_phi_gathered; std::vector<std::vector<node_ptr>> next_phi_gathered;
mpi::all_gather(*_mpi_comm, next_phi, next_phi_gathered); mpi::all_gather(*_mpi_comm, next_phi, next_phi_gathered);
feat_ind = _phi.size();
for(auto& next_phi_vec : next_phi_gathered) for(auto& next_phi_vec : next_phi_gathered)
{ {
_phi.reserve(_phi.size() + next_phi_vec.size()); _phi.reserve(_phi.size() + next_phi_vec.size());
for(auto& feat : next_phi_vec) for(auto& feat : next_phi_vec)
{
feat->reindex(feat_ind);
_phi.push_back(feat); _phi.push_back(feat);
++feat_ind;
}
} }
} }
if((_n_rung_store > 0) && (_n_rung_store < _max_phi))
// if(0 < _n_rung_store < _max_phi) {
// { node_value_arrs::resize_values_arr(_n_rung_store, _start_gen[_n_rung_store+1], true);
// node_value_arrs::resize_values_arr(_n_rung_store, _start_gen[_n_rung_store+1], true); for(int ff = 0; ff < _start_gen[_n_rung_store + 1]; ++ff)
// for(auto feat = _phi.begin(); feat != _phi.begin() + _start_gen[_n_rung_store+1]; ++feat) _phi[ff]->set_value();
// (*feat)->set_value(); }
// } else if(_n_rung_store > 0)
// else if(_n_rung_store > 0) {
// { node_value_arrs::resize_values_arr(_max_phi, _phi.size(), false);
// node_value_arrs::resize_values_arr(_max_phi, _phi.size(), false); for(int ff = 0; ff < _phi.size(); ++ff)
// for(auto feat = _phi.begin(); feat != _phi.end(); ++feat) _phi[ff]->set_value();
// (*feat)->set_value(); }
// }
_n_feat = _phi.size(); _n_feat = _phi.size();
} }
......
...@@ -57,8 +57,7 @@ public: ...@@ -57,8 +57,7 @@ public:
/** /**
* @brief Set the value for the feature * @brief Set the value for the feature
*/ */
inline void set_value(int offset = -1){std::copy_n(node_value_arrs::PRIMARY_FEAT_ARR.get() + _feat_ind * _n_samp, _n_samp, value_ptr());} inline void set_value(int offset = -1){std::copy_n(node_value_arrs::get_primary_feat_ptr(_feat_ind), _n_samp, value_ptr());}
/** /**
* @brief Check if the feature contains NaN * @brief Check if the feature contains NaN
*/ */
......
...@@ -47,6 +47,14 @@ public: ...@@ -47,6 +47,14 @@ public:
*/ */
Node(const Node &o); Node(const Node &o);
/**
* @brief Reindex the feature
* @details re-index the feature to be continuous
*
* @param ind the new feature index
*/
inline void reindex(int ind){_feat_ind = ind;}
/** /**
* @brief Acesssor function to get the number of samples * @brief Acesssor function to get the number of samples
*/ */
......
...@@ -77,4 +77,9 @@ void node_value_arrs::resize_values_arr(int n_dims, int n_feat, bool use_temp) ...@@ -77,4 +77,9 @@ void node_value_arrs::resize_values_arr(int n_dims, int n_feat, bool use_temp)
TEMP_STORAGE_REG = std::unique_ptr<int[]>(new int[3 * N_STORE_FEATURES]); TEMP_STORAGE_REG = std::unique_ptr<int[]>(new int[3 * N_STORE_FEATURES]);
std::copy_n(std::vector<int>(3*N_STORE_FEATURES, -1).data(), 3*N_STORE_FEATURES, TEMP_STORAGE_REG.get()); std::copy_n(std::vector<int>(3*N_STORE_FEATURES, -1).data(), 3*N_STORE_FEATURES, TEMP_STORAGE_REG.get());
} }
} else
\ No newline at end of file {
TEMP_STORAGE_ARR = nullptr;
TEMP_STORAGE_REG = nullptr;
}
}
#ifndef NODE_VALEU_ARR #ifndef NODE_VALUE_ARR
#define NODE_VALEU_ARR #define NODE_VALUE_ARR
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
...@@ -107,4 +107,4 @@ namespace node_value_arrs ...@@ -107,4 +107,4 @@ namespace node_value_arrs
} }
} }
#endif #endif
\ No newline at end of file
...@@ -137,7 +137,7 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm) ...@@ -137,7 +137,7 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm)
for(int ff = 0; ff < headers.size(); ++ff) for(int ff = 0; ff < headers.size(); ++ff)
{ {
phi_0.push_back(std::make_shared<FeatureNode>(ff, headers[ff], data[ff], units[ff])); phi_0.push_back(std::make_shared<FeatureNode>(ff, headers[ff], data[ff], units[ff]));
std::copy_n(data[ff].begin(), data[ff].size(), node_value_arrs::get_primary_feat_ptr(ff)); std::copy_n(data[ff].data(), data[ff].size(), node_value_arrs::get_primary_feat_ptr(ff));
} }
_feat_space = std::make_shared<FeatureSpace>(comm, phi_0, _opset, _max_rung, _n_sis_select, _max_store_rung); _feat_space = std::make_shared<FeatureSpace>(comm, phi_0, _opset, _max_rung, _n_sis_select, _max_store_rung);
......
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