条件跳转或移动取决于未初始化的值 - 使用 gsl_matrix_set
Conditional jump or move depends on uninitialised value(s) - using gsl_matrix_set
我正尝试在 C 中使用 GSL 库,但 运行 遇到了麻烦。
我正在为我的矩阵和向量分配 space:
A = gsl_matrix_alloc(nr, nc); /* Data matrix */
tau = gsl_vector_alloc(nc); /* required place holder for GSL */
然后我正在初始化A
:
for(i = 0; i < nr; i++){
gsl_matrix_set(A, i, 0, 1.0);
}
for(i = 1; i < nr; i++){
for(j = 0; j < nc; j++){
gsl_matrix_set(A, i, j, 1.0 / (double)(i + j + 1));
}
}
然后我在这一行出错:
gsl_linalg_QR_decomp(A, tau);
出现以下错误:
==901== Conditional jump or move depends on uninitialised value(s)
==901== at 0x3E8920AE0E: cblas_dnrm2 (in /usr/lib64/libgslcblas.so.0.0.0)
==901== by 0x3E88EA779A: gsl_linalg_householder_transform (in /usr/lib64/libgsl.so.0.14.0)
==901== by 0x3E88EA1305: gsl_linalg_QR_decomp (in /usr/lib64/libgsl.so.0.14.0)
==901== by 0x400FF3: GE_FindPoint (hw8.c:145)
==901== by 0x400DF4: main (hw8.c:66)
==901== Uninitialised value was created by a heap allocation
==901== at 0x4A06A2E: malloc (vg_replace_malloc.c:270)
==901== by 0x3E88E4CFD4: gsl_block_alloc (in /usr/lib64/libgsl.so.0.14.0)
==901== by 0x3E88EB1768: gsl_matrix_alloc (in /usr/lib64/libgsl.so.0.14.0)
==901== by 0x400EBB: GE_FindPoint (hw8.c:110)
==901== by 0x400DF4: main (hw8.c:66)
第 110 行指向分配 A
的行:A = gsl_matrix_alloc(nr, nc);
在这种情况下,nc = 3
和 nr = 3840
。什么会导致此错误?
在初始化的第二部分,i
和 j
的起始值不匹配。因此,您为 1 <= i < nr 调用 gsl_matrix_set( A, i, 0, ... )
两次,而您永远不会为 1 <= j < nc.
调用 gsl_matrix_set( A, 0, j, ... )
只需将初始化的那部分更改为
for(i = 0; i < nr; i++){
for(j = 1; j < nc; j++){
gsl_matrix_set(A, i, j, 1.0 / (double)(i + j + 1));
}
}
我正尝试在 C 中使用 GSL 库,但 运行 遇到了麻烦。
我正在为我的矩阵和向量分配 space:
A = gsl_matrix_alloc(nr, nc); /* Data matrix */
tau = gsl_vector_alloc(nc); /* required place holder for GSL */
然后我正在初始化A
:
for(i = 0; i < nr; i++){
gsl_matrix_set(A, i, 0, 1.0);
}
for(i = 1; i < nr; i++){
for(j = 0; j < nc; j++){
gsl_matrix_set(A, i, j, 1.0 / (double)(i + j + 1));
}
}
然后我在这一行出错:
gsl_linalg_QR_decomp(A, tau);
出现以下错误:
==901== Conditional jump or move depends on uninitialised value(s)
==901== at 0x3E8920AE0E: cblas_dnrm2 (in /usr/lib64/libgslcblas.so.0.0.0)
==901== by 0x3E88EA779A: gsl_linalg_householder_transform (in /usr/lib64/libgsl.so.0.14.0)
==901== by 0x3E88EA1305: gsl_linalg_QR_decomp (in /usr/lib64/libgsl.so.0.14.0)
==901== by 0x400FF3: GE_FindPoint (hw8.c:145)
==901== by 0x400DF4: main (hw8.c:66)
==901== Uninitialised value was created by a heap allocation
==901== at 0x4A06A2E: malloc (vg_replace_malloc.c:270)
==901== by 0x3E88E4CFD4: gsl_block_alloc (in /usr/lib64/libgsl.so.0.14.0)
==901== by 0x3E88EB1768: gsl_matrix_alloc (in /usr/lib64/libgsl.so.0.14.0)
==901== by 0x400EBB: GE_FindPoint (hw8.c:110)
==901== by 0x400DF4: main (hw8.c:66)
第 110 行指向分配 A
的行:A = gsl_matrix_alloc(nr, nc);
在这种情况下,nc = 3
和 nr = 3840
。什么会导致此错误?
在初始化的第二部分,i
和 j
的起始值不匹配。因此,您为 1 <= i < nr 调用 gsl_matrix_set( A, i, 0, ... )
两次,而您永远不会为 1 <= j < nc.
gsl_matrix_set( A, 0, j, ... )
只需将初始化的那部分更改为
for(i = 0; i < nr; i++){
for(j = 1; j < nc; j++){
gsl_matrix_set(A, i, j, 1.0 / (double)(i + j + 1));
}
}