tmp update

This commit is contained in:
张壹 2024-11-02 22:12:43 +08:00
parent 0f6f755bd5
commit a3f12cb964
3 changed files with 37 additions and 21 deletions

View File

@ -28,4 +28,4 @@ add_example(multinary_ex OFF)
add_example(text_io_ex OFF)
add_example(getoption_ex OFF)
add_example(process_ex OFF)
add_example(array_ex ON)
add_example(array_ex OFF)

View File

@ -260,10 +260,20 @@ void gctl::gauss3d_filter(const array<double> &in_data, array<double> &out_data,
void gctl::moving_window_1d(int data_len, int win_len, int cur_data_idx, array<int> &win_data_idx)
{
if (win_len < 3 || win_len/2 == 0)
{
throw std::runtime_error("[gctl::moving_average] Invalid window size (must be >= 3 and odd).");
}
if (data_len <= win_len)
{
throw std::runtime_error("[gctl::moving_average] The window size must be smaller than the data size).");
}
win_data_idx.resize(win_len);
int ht = win_len/2;
for (size_t j = 0; j < win_len; j++)
for (int j = 0; j < win_len; j++)
{
win_data_idx[j] = cur_data_idx + j - ht;
if (cur_data_idx <= ht) win_data_idx[j] = j;
@ -276,15 +286,21 @@ void gctl::moving_average_1d(const array<double> &in_data, array<double> &out_da
{
if (win_size < 3 || win_size/2 == 0)
{
throw std::runtime_error("Invalid window size (must be >= 3 and odd). From gctl::moving_average(...)");
throw std::runtime_error("[gctl::moving_average] Invalid window size (must be >= 3 and odd).");
}
int d_size = in_data.size();
if (d_size <= win_size)
{
throw std::runtime_error("[gctl::moving_average] The window size must be smaller than the data size).");
}
// Copy the input data to output ones
out_data = in_data;
int id;
double d_sum, c_sum;
int half_k = win_size/2;
int id, d_size = in_data.size();
for (int i = 0; i < d_size; i++)
{
d_sum = c_sum = 0.0;

View File

@ -110,7 +110,7 @@ namespace gctl
double sigma = 0.5, int k_size = 3);
/**
* @brief
* @brief
*
* @param data_len
* @param win_len
@ -120,11 +120,11 @@ namespace gctl
void moving_window_1d(int data_len, int win_len, int cur_data_idx, array<int> &win_data_idx);
/**
* @brief
* @brief
*
* @param in_data
* @param out_data
* @param k_size
* @param in_data
* @param out_data
* @param k_size 3
*/
void moving_average_1d(const array<double> &in_data, array<double> &out_data, int win_size = 3);