JayBeams  0.1
Another project to have fun coding.
sum_square.hpp
Go to the documentation of this file.
1 #ifndef jb_testing_sum_square_hpp
2 #define jb_testing_sum_square_hpp
3 
4 #include <jb/fftw/tde_result.hpp>
5 
6 namespace jb {
7 namespace testing {
8 
9 /**
10  * Compute the sum square of a family of timeseries.
11  *
12  * @return tde_result with the square sum of each timeseries
13  *
14  * @tparam container_t type of the collection of timeseries
15  */
16 template <typename container_t>
17 auto sum_square(container_t const& ts) {
18  using array_type = container_t;
19  using element_type =
21  /// Extract T out of std::complex<T>, otherwise simply T.
22  using precision_type =
25 
26  sum2_type sum2(ts);
27  std::size_t nsamples = jb::detail::nsamples(ts);
28  std::size_t num_timeseries = jb::detail::element_count(ts) / nsamples;
29 
30  element_type const* it_ts = ts.data();
31  for (std::size_t i = 0; i != num_timeseries; ++i) {
32  element_type sum2_val = element_type();
33  for (std::size_t j = 0; j != nsamples; ++j, ++it_ts) {
34  sum2_val += *it_ts * (*it_ts);
35  }
36  sum2[i] = std::abs(sum2_val);
37  }
38  return std::move(sum2);
39 }
40 
41 } // namespace testing
42 } // namespace jb
43 
44 #endif // jb_testing_sum_square_hpp
typename container_type::value_type element_type
Define the type of the elements in the container.
A time-delay estimator (TDE) is an algorithm to compare two families of timeseries and return the est...
Definition: tde_result.hpp:37
auto sum_square(container_t const &ts)
Compute the sum square of a family of timeseries.
Definition: sum_square.hpp:17
std::size_t nsamples(container_type const &a)
Count the elements in the last dimension of a vector-like container.
std::size_t element_count(container_type const &a)
Count the number of elements for a vector-like container.
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7