使用C++的Octave API构造稀疏矩阵
Sparse matrix construction using Octave API for C++
我正在尝试使用Octave C++API来解决稀疏线性系统。我遇到的问题是,我找不到一种有效的方法来构造稀疏线性系统。
SparseMatrix A;
int dim,nnz;
// dim = dimension
// nnz = number of non-zero entry in the matrix A
/*
somehow assign the values for dim and nnz
*/
A = SparseMatrix ( dim, dim, nnz );
// row index array
int *pidx_r = new int[nnz];
// col index array
int *pidx_c = new int[nnz];
// value array
double *pval = new double[nnz];
// total number of nonzero elements
int tot;
/*
somehow assign values for pidx_r, pidx_c, pval and tot
*/
for ( int i = 0; i < tot; i++ )
A ( pidx_r[i], pidx_c[i] ) = pval[i];
上面的代码描述了我的天真实现,它效率极低,我希望应该有一些成员函数来将值大规模插入稀疏矩阵。
例如,A=SparseMatrix(pidx_r,pidx_c,pval);
然而,我找不到任何成员函数可以这样做。至少,天真的实现似乎是唯一的方法。
假设我已经准备了某种格式的矩阵,我想问是否有任何方法可以使用C++的Octave API有效地构造稀疏矩阵?
我刚刚找到了这个教程,第一段中的方法看起来像你想要的。
链接
@wirew0rm链接中提到的方法琐碎且效率低下。
事实上,我已经找到了一个解决方案,它基本上修改了继承成员SparseMatrixRep的内容。
尽管文件中指出它是不安全的,不推荐使用,但性能得到了显著改善。
相关文章:
- 运行简单的.oct文件时Octave崩溃,我的代码出了什么问题?
- 使 OpenCV 调整大小与 Matlab/Octave 调整大小相同
- 使用 Octave GNU 访问输入/输出文件
- 将 GNU Octave(或 Matlab)矩阵输出到具有 C 数组语法的文件中
- 从Octave CLI构建墨西哥文件
- 尝试从Octave的独立程序示例中编译示例代码,在第一行出现段错误
- C++或 Scilab 或 Octave 或 R 中具有大量数据的统计信息
- 使用 mkoctfile 与 Octave 和 Visual Studio 2010 编译器编译 .mex 或 .oct
- QuantLib bindings for Octave?
- Octave c++ and VS2010
- d - 使用 SWIG 包装 Octave 的 C++ API
- 调用 Octave 内置函数从C++中获取 2 个参数
- C++和Octave的结果对于简单的算术来说是不同的
- C++中的Octave EIG类,算法
- Octave 的 rref(简化行梯队形式)等效于 C++ API
- 如何在C/C++程序中嵌入GNU Octave
- Octave -访问octave_value_list中的值
- 在c++中使用Octave库(dll等)而不安装Octave(只是复制安装文件夹)
- 我如何将octave(matlab克隆)与qt creator集成
- Octave - .m文件编译器