Maintenance - Mise à jour mensuelle Lundi 7 Décembre 2021 entre 7h00 et 9h00

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 @@
#include <cstdint>
#include <cstring>
#include <vector>
/*****************************************************************************
*
* Helper macros
......@@ -5004,25 +5002,24 @@ struct flow
output_port_id y[1];
time sigma;
double default_value = 0.0;
std::vector<double> default_data;
std::vector<double> default_sigmas;
double default_samplerate = 44100.0;
double* default_data;
double* default_sigmas;
sz default_size;
double value = 0.0;
std::vector<double> data;
std::vector<double> sigmas;
double samplerate = 44100.0;
double accu_sigma;
sz i;
status initialize(data_array<message, message_id>& /*init*/) noexcept
{
// irt_return_if_fail(default_samplerate > 0.,
// status::model_flow_bad_samplerate);
samplerate = default_samplerate;
sigma = 1.0 / samplerate;
// irt_return_if_fail(default_size > 1, status::model_flow_bad_data);
value = default_value;
data = default_data;
sigmas = default_sigmas;
sigma = 1.0 / default_samplerate;
accu_sigma = 0.;
i = 0;
return status::success;
}
......@@ -5032,32 +5029,32 @@ struct flow
time /*e*/,
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) {
value = data[i];
sigma = sigmas[i];
sigma = default_sigmas[i];
return status::success;
}
}
sigma = time_domain<time>::infinity;
i = default_size - 1;
return status::success;
}
status lambda(
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;
}
message observation(const time /*e*/) const noexcept
{
return message(value);
return message(default_data[i]);
}
};
......
......@@ -156,7 +156,8 @@ private:
{ "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 =
std::lower_bound(std::begin(table),
......@@ -538,7 +539,7 @@ private:
bool read(flow& dyn) noexcept
{
return !!(is >> dyn.default_value);
return !!(is >> dyn.default_samplerate);
}
};
......@@ -902,7 +903,7 @@ private:
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) {
try {
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
<< ' ' << e.what() << endl;
}
......@@ -190,13 +190,13 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera
vector<vector<double>> quantified_sigmas;
// 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 sigma = default_frequency;
double accu_sigma = 0.0;
vector<double> quantified_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);
sigma += default_frequency;
if (prev != q) {
......@@ -212,7 +212,7 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera
prev = q;
}
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_sigmas.push_back(sigma_vector);
......@@ -221,7 +221,7 @@ quantify_data(vector<vector<double>> data, double delta, double default_samplera
return data.empty() ? quantized_data{}
: quantized_data{ quantified_data,
quantified_sigmas,
data[0].size() * default_frequency };
static_cast<double>(data[0].size()) * default_frequency };
}
// Global data
......@@ -293,9 +293,10 @@ make_neuron(irt::simulation* sim, long unsigned int i) noexcept
prod_lif.default_input_coeffs[1] = 0.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_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;
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