Commit 059ad5f5 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: use pointer instead of vector for flow

parent 636ce9fe
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <vector>
/***************************************************************************** /*****************************************************************************
* *
* Helper macros * Helper macros
...@@ -5004,25 +5002,24 @@ struct flow ...@@ -5004,25 +5002,24 @@ struct flow
output_port_id y[1]; output_port_id y[1];
time sigma; time sigma;
double default_value = 0.0;
std::vector<double> default_data;
std::vector<double> default_sigmas;
double default_samplerate = 44100.0; double default_samplerate = 44100.0;
double* default_data;
double* default_sigmas;
sz default_size;
double value = 0.0; double accu_sigma;
std::vector<double> data; sz i;
std::vector<double> sigmas;
double samplerate = 44100.0;
status initialize(data_array<message, message_id>& /*init*/) noexcept status initialize(data_array<message, message_id>& /*init*/) noexcept
{ {
// irt_return_if_fail(default_samplerate > 0.,
// status::model_flow_bad_samplerate);
samplerate = default_samplerate; // irt_return_if_fail(default_size > 1, status::model_flow_bad_data);
sigma = 1.0 / samplerate;
value = default_value; sigma = 1.0 / default_samplerate;
data = default_data; accu_sigma = 0.;
sigmas = default_sigmas; i = 0;
return status::success; return status::success;
} }
...@@ -5032,32 +5029,32 @@ struct flow ...@@ -5032,32 +5029,32 @@ struct flow
time /*e*/, time /*e*/,
time /*r*/) noexcept time /*r*/) noexcept
{ {
for (; i < default_size; ++i) {
accu_sigma += default_sigmas[i];
double accu_sigma = 0;
for (std::size_t i = { 0 }; i < sigmas.size(); i++) {
accu_sigma += sigmas[i];
if (accu_sigma > t) { if (accu_sigma > t) {
sigma = default_sigmas[i];
value = data[i];
sigma = sigmas[i];
return status::success; return status::success;
} }
} }
sigma = time_domain<time>::infinity;
i = default_size - 1;
return status::success; return status::success;
} }
status lambda( status lambda(
data_array<output_port, output_port_id>& output_ports) noexcept data_array<output_port, output_port_id>& output_ports) noexcept
{ {
output_ports.get(y[0]).messages.emplace_front(value); output_ports.get(y[0]).messages.emplace_front(default_data[i]);
return status::success; return status::success;
} }
message observation(const time /*e*/) const noexcept message observation(const time /*e*/) const noexcept
{ {
return message(value); return message(default_data[i]);
} }
}; };
......
...@@ -156,7 +156,8 @@ private: ...@@ -156,7 +156,8 @@ private:
{ "time_func", dynamics_type::time_func } { "time_func", dynamics_type::time_func }
}; };
static_assert(std::size(table) == dynamics_type_size()); static_assert(std::size(table) ==
static_cast<sz>(dynamics_type_size()));
const auto it = const auto it =
std::lower_bound(std::begin(table), std::lower_bound(std::begin(table),
...@@ -538,7 +539,7 @@ private: ...@@ -538,7 +539,7 @@ private:
bool read(flow& dyn) noexcept bool read(flow& dyn) noexcept
{ {
return !!(is >> dyn.default_value); return !!(is >> dyn.default_samplerate);
} }
}; };
...@@ -902,7 +903,7 @@ private: ...@@ -902,7 +903,7 @@ private:
void write(const flow& dyn) noexcept void write(const flow& dyn) noexcept
{ {
os << "flow " << dyn.default_value << '\n'; os << "flow " << dyn.default_samplerate << '\n';
} }
}; };
......
...@@ -158,7 +158,7 @@ vector<vector<double>> parse2DCsvFile(string inputFileName) { ...@@ -158,7 +158,7 @@ vector<vector<double>> parse2DCsvFile(string inputFileName) {
try { try {
record.push_back(stof(line)); record.push_back(stof(line));
} }
catch (const std::invalid_argument e) { catch (const std::invalid_argument& e) {
cout << "NaN found in file " << inputFileName << " line " << l cout << "NaN found in file " << inputFileName << " line " << l
<< ' ' << e.what() << endl; << ' ' << e.what() << endl;
} }
...@@ -190,13 +190,13 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera ...@@ -190,13 +190,13 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera
vector<vector<double>> quantified_sigmas; vector<vector<double>> quantified_sigmas;
// Loop over all the lines, each ligne will be quantized // Loop over all the lines, each ligne will be quantized
for (int i = 1; i < data.size(); i++) { for (size_t i = 1; i < data.size(); i++) {
double prev = data[i][0]; double prev = data[i][0];
double sigma = default_frequency; double sigma = default_frequency;
double accu_sigma = 0.0; double accu_sigma = 0.0;
vector<double> quantified_vector; vector<double> quantified_vector;
vector<double> sigma_vector; vector<double> sigma_vector;
for (int j = 1; j < data[i].size(); j++) { for (size_t j = 1; j < data[i].size(); j++) {
double q = delta * (static_cast<int>(data[i][j]/delta) + 0.5); double q = delta * (static_cast<int>(data[i][j]/delta) + 0.5);
sigma += default_frequency; sigma += default_frequency;
if (prev != q) { if (prev != q) {
...@@ -212,7 +212,7 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera ...@@ -212,7 +212,7 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera
prev = q; prev = q;
} }
quantified_vector.push_back(quantified_vector[quantified_vector.size() - 1]); quantified_vector.push_back(quantified_vector[quantified_vector.size() - 1]);
sigma_vector.push_back(std::abs(data[i].size() * default_frequency - accu_sigma)); sigma_vector.push_back(std::abs(static_cast<double>(data[i].size()) * default_frequency - accu_sigma));
quantified_data.push_back(quantified_vector); quantified_data.push_back(quantified_vector);
quantified_sigmas.push_back(sigma_vector); quantified_sigmas.push_back(sigma_vector);
...@@ -221,7 +221,7 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera ...@@ -221,7 +221,7 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera
return data.empty() ? quantized_data{} return data.empty() ? quantized_data{}
: quantized_data{ quantified_data, : quantized_data{ quantified_data,
quantified_sigmas, quantified_sigmas,
data[0].size() * default_frequency }; static_cast<double>(data[0].size()) * default_frequency };
} }
// Global data // Global data
...@@ -293,9 +293,10 @@ make_neuron(irt::simulation* sim, long unsigned int i) noexcept ...@@ -293,9 +293,10 @@ make_neuron(irt::simulation* sim, long unsigned int i) noexcept
prod_lif.default_input_coeffs[1] = 0.0; prod_lif.default_input_coeffs[1] = 0.0;
constant_lif.default_value = 1.0; constant_lif.default_value = 1.0;
flow_lif.default_data = sound_data[i]; flow_lif.default_data = sound_data[i].data();
flow_lif.default_samplerate = samplerate; flow_lif.default_samplerate = samplerate;
flow_lif.default_sigmas = sound_data_sigmas[i]; flow_lif.default_sigmas = sound_data_sigmas[i].data();
flow_lif.default_size = sound_data[i].size();
constant_cross_lif.default_value = Vr_lif; constant_cross_lif.default_value = Vr_lif;
integrator_lif.default_current_value = 0.0; integrator_lif.default_current_value = 0.0;
......
Markdown is supported
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