tmp update
This commit is contained in:
parent
0f6f755bd5
commit
a3f12cb964
@ -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)
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user