c - C:将包含矩阵的多个向量复制到单个向量中时遇到问题
问题描述
包: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 的定义上。我试图从其定义中删除“&”并得到一个错误。对于有经验的人来说,这可能非常明显。
解决方案
推荐阅读
- java - 如何在百里香中迭代对象列表
- swift - 映射到 AnyPublisher 无效
- php - CodeIgniter 4 - 迁移没有制作数据库表
- javascript - React Native 如何从嵌套数据创建 VictoryPie
- react-native - 如何使反应原生 svg 路径更平滑
- node.js - 无法使用带有 NodeJS、ReactJS 和 Express 的 socket.io 在服务器和客户端之间建立连接
- java - 是否可以并行编译大型 Java 模块?
- python - 将每一行转换为数据框并连接结果
- spring - Spring Boot ResponseEntity 不操纵 HTTP 响应
- python - 从网站抓取数据以获取表格,但我得到一个空表格