12 #ifndef RTCTK_EXAMPLEDATATASK_COMPUTATION_HPP
13 #define RTCTK_EXAMPLEDATATASK_COMPUTATION_HPP
40 m_n_samples_to_read = to_read;
41 m_n_slopes = n_slopes;
45 m_samples.resize(m_n_samples_to_read);
46 m_avg_slopes.resize(m_n_slopes);
47 m_s2m_matrix.resize(m_n_modes, m_n_slopes);
48 m_avg_modes.resize(m_n_modes);
51 std::fill(m_avg_slopes.begin(), m_avg_slopes.end(), 0.0);
52 std::fill(m_avg_modes.begin(), m_avg_modes.end(), 0.0);
55 LOG4CPLUS_DEBUG(
GetLogger(),
"m_n_slopes: " << m_n_slopes);
56 LOG4CPLUS_DEBUG(
GetLogger(),
"m_n_modes: " << m_n_modes);
57 LOG4CPLUS_DEBUG(
GetLogger(),
"m_n_samples_to_read: " << m_n_samples_to_read);
61 m_s2m_matrix = std::move(s2m_matrix);
63 if (m_n_modes != m_s2m_matrix.GetNrows() || m_n_slopes != m_s2m_matrix.GetNcols()) {
64 std::stringstream err_text;
65 err_text <<
"s2m wrong shape: ";
67 <<
"expected : " << m_n_modes <<
" x " << m_n_slopes;
69 <<
"received : " << m_s2m_matrix.GetNrows() <<
" x "
70 << m_s2m_matrix.GetNcols();
85 m_samples[m_sample_idx++] = sample.
wfs.
slopes;
89 std::vector<float>
const& avg_slopes;
90 std::vector<float>
const& avg_modes;
93 unsigned last_sample_id;
94 unsigned iteration_idx;
95 std::chrono::duration<double> elapsed;
103 if (m_sample_idx != m_n_samples_to_read) {
107 LOG4CPLUS_INFO(
GetLogger(),
"Computation::Compute() - samples: " << m_sample_idx);
109 auto time_start = std::chrono::system_clock::now();
111 ComputeAverageSlopes();
113 ComputeAverageModes();
115 auto elapsed = std::chrono::system_clock::now() - time_start;
120 return {m_avg_slopes, m_avg_modes, m_last_sample_id, m_iteration_idx, elapsed};
124 void ComputeAverageSlopes() {
126 for (
unsigned i = 0; i < m_n_samples_to_read; i++) {
127 for (
unsigned j = 0; j < m_n_slopes; j++) {
128 m_avg_slopes[j] += m_samples[i][j];
132 for (
unsigned j = 0; j < m_n_slopes; j++) {
133 m_avg_slopes[j] /=
static_cast<float>(m_n_samples_to_read);
137 void ComputeAverageModes() {
145 m_s2m_matrix.data(), m_avg_slopes.data(), m_avg_modes.data(), m_n_modes, m_n_slopes);
150 my_sgemv(
const float*
mat,
const float* in_vec,
float* out_vec,
uint32_t rows,
uint32_t cols) {
151 for (
uint32_t i = 0; i < rows; ++i) {
152 out_vec[i] = my_dot_product(
mat + i * cols, in_vec, cols);
157 float my_dot_product(
const float* x,
const float* y,
uint32_t n) {
165 unsigned m_last_sample_id;
166 unsigned m_iteration_idx;
167 unsigned m_sample_idx;
171 unsigned m_n_samples_to_read;
173 std::vector<float> m_avg_slopes;
174 std::vector<float> m_avg_modes;
175 std::vector<decltype(decltype(TopicType::wfs)::
slopes)> m_samples;
179 #endif // RTCTK_EXAMPLEDATATASK_COMPUTATION_HPP