简体   繁体   English

如何使用CHOLMOD将元素添加到三元组矩阵?

[英]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.

相关问题 使用Cholmod和Cholmod-Extra计算稀疏矩阵的逆 - Calculating the inverse of a sparse matrix using Cholmod and Cholmod-Extra 在 CHOLMOD 或 SuiteSparseQR 中创建稀疏矩阵 - Creating a sparse matrix in CHOLMOD or SuiteSparseQR Eigen:修改稀疏矩阵的三元组列表,而不是使用 coeffRef - Eigen: modify sparse matrix' triplet list, instead of using coeffRef SuiteSparse(4.5.1)的SPQR-调用cholmod_allocate_triplet始终返回NULL - SuiteSparse(4.5.1)'s SPQR - calling to cholmod_allocate_triplet always returns NULL 如何使用指针访问矩阵列的元素 - How to access the elements of a column of a matrix using a pointer 将Eigen矩阵转换为Triplet形式的C ++ - Convert an Eigen matrix to Triplet form C++ 如何将元素添加到二维数组/矩阵的随机位置? - How to add elements into a randomly position of a 2d array/matrix? 如何仅通过向量对的第一个元素或自定义向量三元组使用 std::find? - how to use std::find through ONLY first elements of the vector pair OR a custom vector triplet? 如何在 9*9 矩阵中切换元素 - How to switch elements in a 9*9 matrix Armadillo C ++:如何使用来自另一个矩阵的多个元素修改矩阵的多个数组元素,特别是在立方体结构中? - Armadillo C++: How to modify multiple array elements of a matrix using multiple elements from another matrix, specifically in a cube structure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM