[英]How to add elements to a triplet matrix using CHOLMOD?
Can anyone please give me a simple example of how to add elements to a triplet matrix using CHOLMOD . 任何人都可以给我一个简单的例子,说明如何使用CHOLMOD将元素添加到三元组矩阵中。
I have tried something like this: 我试过这样的事情:
cholmod_triplet *A;
int k;
void add_A_entry(int r, int c, double x)
{
((int*)A->i)[k] = r;
((int*)A->j)[k] = c;
((double*)A->x)[k] = x;
k++;
}
int main()
{
k = 0;
cholmod_common com;
cholmod_start(&com);
A = cholmod_allocate_triplet(202, 202, 202*202, -1, CHOLMOD_REAL, &com);
add_A_entry(2, 2, 1.);
add_A_entry(4, 1, 2.);
add_A_entry(2, 10, -1.);
cholmod_print_triplet(A, "A", &com);
cholmod_finish(&com);
return 0;
}
However, this doesn't add any elements to the matrix. 但是,这不会向矩阵添加任何元素。 I simply get the output:
我只是得到输出:
CHOLMOD triplet: A: 202-by-202, nz 0, lower. OK
Of course, I have tried to find the solution both by searching and in the CHOLMOD documentation , but I found no help. 当然,我试图通过搜索和CHOLMOD文档找到解决方案,但我没有找到任何帮助。
cholmod_allocate_triplet()
sets A->nzmax
, which in your case is 202*202. cholmod_allocate_triplet()
设置A->nzmax
,在你的情况下是202 * 202。 That just defines the space available to add triplets. 这只是定义了可用于添加三元组的空间。 The actual number of triplets in the matrix is
A->nnz
, which gets set to zero by cholmod_allocate_triplet()
. 矩阵中三元组的实际数量为
A->nnz
,由cholmod_allocate_triplet()
设置为零。
The A->nnz
should be used instead of your variable k
. 应使用
A->nnz
代替变量k
。
Tim Davis (CHOLMOD author) 蒂姆戴维斯(CHOLMOD作者)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.