5 using namespace ptracey;
31 for (
unsigned int i = 0; i <
size; i++) {
118 const std::function<T(T, T)> &fn)
const {
122 auto val = fn(
values[index], value);
123 COMP_CHECK_MSG(val < 0.0, val, 0.0,
124 "operation produces negative value");
140 apply(T value,
const std::function<T(T, T)> &fn)
const {
143 for (std::size_t i = 0; i <
values.size(); i++) {
144 auto val = fn(
values[i], value);
145 COMP_CHECK_MSG(val < 0.0, val, 0.0,
146 "operation produces a negative value");
160 const std::function<T(T, T)> &fn)
const {
166 for (std::size_t i = 0; i <
values.size(); i++) {
168 COMP_CHECK_MSG(val < 0.0, val, 0.0,
169 "operation produces a negative value");
186 apply(s, [](
auto i,
auto j) {
return i + j; });
199 apply(s, [](
auto i,
auto j) {
return i + j; });
207 apply(s, [](
auto i,
auto j) {
return i + j; });
216 apply(s, [](
auto i,
auto j) {
return i + j; });
236 apply(s, [](
auto i,
auto j) {
return i - j; });
250 apply(s, [](
auto i,
auto j) {
return i - j; });
258 apply(s, [](
auto i,
auto j) {
return i - j; });
270 minval <= s, minval, s,
271 "given value would produce negative powers");
273 apply(s, [](
auto this_wave_value,
auto value) {
274 return this_wave_value - value;
283 auto maxval = ss.
max();
285 maxval <= s, maxval, s,
286 "given value would produce negative powers");
288 ss.
apply(s, [](
auto this_wave_value,
auto value) {
289 return value - this_wave_value;
306 apply(s, [](
auto i,
auto j) {
return i * j; });
320 apply(s, [](
auto i,
auto j) {
return i * j; });
329 apply(s, [](
auto i,
auto j) {
return i * j; });
338 apply(s, [](
auto i,
auto j) {
return i * j; });
358 apply(s, [](
auto i,
auto j) {
return i / j; });
372 apply(s, [](
auto i,
auto j) {
return i / j; });
382 apply(s, [](
auto i,
auto j) {
return i / j; });
394 apply(s, [](
auto i,
auto j) {
return i / j; });
412 auto wave = ss * sval;
421 D_CHECK(i < (uint)
values.size());
430 D_CHECK((uint)i <
values.size());
441 for (std::size_t i = 0; i <
values.size(); i++) {
450 return !(*
this == cs);
458 T
reduce(
const std::function<T(T, T)> &fn,
459 T counter_value)
const {
468 [](T counter_value, T element) {
469 return counter_value + element;
476 [](T counter_value, T element) {
477 return counter_value * element;
498 for (
int i = 0; i <
values.size(); i++) {
512 Real high = FLT_MAX) {
513 std::vector<T> csvec;
514 csvec.resize(
values.size());
517 for (
int i = 0; i <
values.size(); i++) {
519 interp<T>(
values[i], start, end, low, high);
528 template <
typename T>
529 inline std::ostream &operator<<(std::ostream &out,
532 for (
auto r : ss.
values) {
533 s <<
"," << std::to_string(r);
535 auto s_str = s.str();
536 out << s_str << std::endl;
Real average() const
find the average value of this wave
Definition: wave.hpp:482
sampled_wave & operator*=(const T &s) const
Definition: wave.hpp:318
std::vector< T > values
holds observed power values of the wave
Definition: wave.hpp:17
friend sampled_wave operator+(const T &s, const sampled_wave &ss)
Definition: wave.hpp:222
sampled_wave apply(T value, const std::function< T(T, T)> &fn) const
Definition: wave.hpp:140
friend sampled_wave operator-(const T &s, const sampled_wave &ss)
subtract every element of given sampled_wave from the value
Definition: wave.hpp:281
a wave sample representing a continuous wave in discreet form
Definition: wave.hpp:12
T sum() const
reduce sampled wave by summation
Definition: wave.hpp:466
sampled_wave operator/(const T &s) const
divide power value from this wave
Definition: wave.hpp:391
bool is_black() const
check if sampled power values contain only 0 value.
Definition: wave.hpp:85
sampled_wave(T val, unsigned int size)
a constant value constructor
Definition: wave.hpp:29
T reduce(const std::function< T(T, T)> &fn, T counter_value) const
reduce power values of this wave to a single value using given function
Definition: wave.hpp:458
sampled_wave & operator/=(const T &s) const
Definition: wave.hpp:369
sampled_wave operator+(const sampled_wave &s) const
add two same sized sampled waves
Definition: wave.hpp:205
sampled_wave apply(const sampled_wave &s, const std::function< T(T, T)> &fn) const
apply a function to same sized wave samples
Definition: wave.hpp:159
friend sampled_wave operator*(const T &s, const sampled_wave &ss)
Definition: wave.hpp:344
sampled_wave operator-(const T &s) const
subtract power value from this wave
Definition: wave.hpp:267
T max() const
gives the maximum value among sampled points
Definition: wave.hpp:50
uint size() const
find the number of samples inside this wave
Definition: wave.hpp:486
sampled_wave operator*(const T &s) const
multiply given power value to all of the elements of the sampled wave.
Definition: wave.hpp:336
sampled_wave apply(unsigned int index, T value, const std::function< T(T, T)> &fn) const
Definition: wave.hpp:117
sampled_wave & operator+=(const T &s) const
Definition: wave.hpp:197
sampled_wave & operator=(const sampled_wave &s)
assign a sample wave to this wave if it does not contain nan values
Definition: wave.hpp:96
bool has_nans() const
check if sampled power values contain nan value.
Definition: wave.hpp:63
T & operator[](uint i)
access to power value at given index. Mostly used for setting a new value for the given index;
Definition: wave.hpp:420
bool operator==(const sampled_wave &cs) const
check if given sampled wave has same power with this one.
Definition: wave.hpp:439
sampled_wave clamp(T low=0.0, T high=FLT_MAX)
clamp power values of this wave to given range We also check if the resulting wave has nan values.
Definition: wave.hpp:496
sampled_wave & operator+=(const sampled_wave &s) const
Definition: wave.hpp:184
sampled_wave operator+(const T &s) const
add given power value to all of the elements of the sampled wave.
Definition: wave.hpp:214
sampled_wave & operator*=(const sampled_wave &s) const
Definition: wave.hpp:304
sampled_wave operator-(const sampled_wave &s) const
subtract two same sized sampled waves
Definition: wave.hpp:256
T product() const
reduce sampled wave by multiplication
Definition: wave.hpp:474
friend sampled_wave operator/(const T &s, const sampled_wave &ss)
divide power value from this wave
Definition: wave.hpp:408
sampled_wave & operator-=(const sampled_wave &s) const
Definition: wave.hpp:234
T operator[](uint i) const
access to power value at given index. Mostly used for reading the value of the given index;
Definition: wave.hpp:429
sampled_wave operator*(const sampled_wave &s) const
multiply two same sized sampled waves
Definition: wave.hpp:327
sampled_wave & operator-=(const T &s) const
Definition: wave.hpp:248
sampled_wave(const std::vector< T > &vals)
directly construct from given values.
Definition: wave.hpp:44
T min() const
gives the minimum value among sampled points
Definition: wave.hpp:57
bool operator!=(const sampled_wave &cs) const
check if given sampled_wave is not equal to this or not
Definition: wave.hpp:449
sampled_wave operator/(const sampled_wave &s) const
divide two same sized sampled waves
Definition: wave.hpp:379
sampled_wave & operator/=(const sampled_wave &s)
Definition: wave.hpp:355
bool has_zeros() const
check if sampled power values contain 0 value.
Definition: wave.hpp:74