12 #ifndef RTCTK_EXAMPLEDATATASK_COMPUTATION_HPP
13 #define RTCTK_EXAMPLEDATATASK_COMPUTATION_HPP
42 m_n_samples_to_read = to_read;
43 m_n_slopes = n_slopes;
47 m_samples.resize(m_n_samples_to_read);
48 m_avg_slopes.resize(m_n_slopes);
49 m_s2m_matrix.resize(m_n_modes, m_n_slopes);
50 m_avg_modes.resize(m_n_modes);
53 std::fill(m_avg_slopes.begin(), m_avg_slopes.end(), 0.0);
54 std::fill(m_avg_modes.begin(), m_avg_modes.end(), 0.0);
57 LOG4CPLUS_DEBUG(
GetLogger(),
"m_n_slopes: " << m_n_slopes);
58 LOG4CPLUS_DEBUG(
GetLogger(),
"m_n_modes: " << m_n_modes);
59 LOG4CPLUS_DEBUG(
GetLogger(),
"m_n_samples_to_read: " << m_n_samples_to_read);
63 m_s2m_matrix = std::move(s2m_matrix);
65 if (m_n_modes != m_s2m_matrix.GetNrows() || m_n_slopes != m_s2m_matrix.GetNcols()) {
66 std::stringstream err_text;
67 err_text <<
"s2m wrong shape: ";
69 <<
"expected : " << m_n_modes <<
" x " << m_n_slopes;
71 <<
"received : " << m_s2m_matrix.GetNrows() <<
" x "
72 << m_s2m_matrix.GetNcols();
87 m_samples[m_sample_idx++] = sample.
wfs.
slopes;
97 std::chrono::duration<double> elapsed;
105 if (m_sample_idx != m_n_samples_to_read) {
109 LOG4CPLUS_INFO(
GetLogger(),
"Computation::Compute() - samples: " << m_sample_idx);
111 auto time_start = std::chrono::system_clock::now();
113 ComputeAverageSlopes();
115 ComputeAverageModes();
117 auto elapsed = std::chrono::system_clock::now() - time_start;
122 return {m_avg_slopes, m_avg_modes, m_last_sample_id, m_iteration_idx, elapsed};
126 void ComputeAverageSlopes() {
128 for (
unsigned i = 0; i < m_n_samples_to_read; i++) {
129 for (
unsigned j = 0; j < m_n_slopes; j++) {
130 m_avg_slopes[j] += m_samples[i][j];
134 for (
unsigned j = 0; j < m_n_slopes; j++) {
135 m_avg_slopes[j] /=
static_cast<float>(m_n_samples_to_read);
139 void ComputeAverageModes() {
147 m_s2m_matrix.data(), m_avg_slopes.data(), m_avg_modes.data(), m_n_modes, m_n_slopes);
152 my_sgemv(
const float*
mat,
const float* in_vec,
float* out_vec,
uint32_t rows,
uint32_t cols) {
153 for (
uint32_t i = 0; i < rows; ++i) {
154 out_vec[i] = my_dot_product(
mat + i * cols, in_vec, cols);
159 float my_dot_product(
const float* x,
const float* y,
uint32_t n) {
167 unsigned m_last_sample_id;
168 unsigned m_iteration_idx;
169 unsigned m_sample_idx;
173 unsigned m_n_samples_to_read;
175 std::vector<float> m_avg_slopes;
176 std::vector<float> m_avg_modes;
177 std::vector<decltype(decltype(TopicType::wfs)::
slopes)> m_samples;
183 #endif // RTCTK_EXAMPLEDATATASK_COMPUTATION_HPP