包装:GNU C
我正在尝试将功能iceemdan()添加到开源软件包libeemd(https://bitbucket.org/luukko/libeemd)中。它会编译,但会产生错误的结果。 iceemdan()基于ceemdan()和eemd()在同一包中。首先,简化代码:
libeemd_error_code iceemdan(double const* restrict input, size_t N,
double* restrict output, size_t M,
unsigned int ensemble_size, double noise_strength, unsigned int
S_number, unsigned int num_siftings, unsigned long int rng_seed) {
...
// Initialize output data to zero
memset(output, 0x00, M*N*sizeof(double));
// Storage for white noise modes
double* wnmodes = malloc(M*ensemble_size*N*sizeof(double));
...
for (size_t en_i=0; en_i<ensemble_size; en_i++) {
...
// Provide a pointer to the wnnodes vector where these modes will be stored
double* const wn = &wnmodes[en_i*M*N];
double* r_i = malloc(M*N*sizeof(double));
memset(r_i, 0x00, M*N*sizeof(double));
// Generate white noise
...
// Extract white noise modes to r_i
emd_err = _emd(w->x, w->emd_w, r_i, M, S_number, num_siftings);
...
array_copy(r_i, N, wn);
...
}
...
// Lots more processing
}
iceemdan()的参数* output包含输出。第一个memset()将其初始化为0。* wnnodes有效地包含* output的ensemble_size版本(在for循环中定义的* r_i)。每次迭代都首先初始化r_i,即集合成员i的* output和wn版本,这是指向wnnodes中存储r_i的位置的指针。 array_copy()将r_i复制到wn。
这是array_copy的定义:
inline static void array_copy(double const* restrict src, size_t n, double* restrict dest) {
memcpy(dest, src, n*sizeof(double));
}
问题在于wnnodes最终会出现ensemble_size的废话副本。它的第一行有零,_emd不能用非零数据产生。我怀疑问题在于wn的定义。我试图从其定义中删除“&”,但出现错误。对于有经验的人来说,这可能非常明显。