本文整理汇总了C++中DM::size2方法的典型用法代码示例。如果您正苦于以下问题:C++ DM::size2方法的具体用法?C++ DM::size2怎么用?C++ DM::size2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DM
的用法示例。
在下文中一共展示了DM::size2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
// A
int ncol = 5, nrow = 5;
vector<int> colind = {0, 3, 6, 8, 10, 12};
vector<int> row = {0, 1, 4, 1, 2, 4, 0, 2, 0, 3, 3, 4};
vector<double> nz = {19, 12, 12, 21, 12, 12, 21, 16, 21, 5, 21, 18};
DM A(Sparsity(nrow, ncol, colind, row), nz);
// Right hand side
DM b = DM::ones(ncol);
// Type of linear systems
enum SymType {UNSYM, SYM, PD};
// All Linear solvers to be tested
struct Test {
string solver;
SymType type;
};
vector<Test> tests;
tests.push_back({"csparse", UNSYM});
tests.push_back({"csparsecholesky", PD});
tests.push_back({"lapacklu", UNSYM});
tests.push_back({"lapackqr", UNSYM});
tests.push_back({"ma27", SYM});
tests.push_back({"symbolicqr", UNSYM});
// Test all combinations
for (auto s : {UNSYM, SYM, PD}) {
DM A_test;
switch (s) {
case UNSYM:
cout << "Unsymmetric linear system" << endl;
A_test = A;
break;
case SYM:
cout << "Symmetric linear system" << endl;
A_test = A + A.T();
break;
case PD:
cout << "Positive definite linear system" << endl;
A_test = mtimes(A.T(), A);
break;
}
for (auto t : tests) {
if (t.type > s) continue; // Cannot be solved
if (!Linsol::has_plugin(t.solver)) {
cout << t.solver << " not available" << endl;
continue;
}
// Create a solver instance
Linsol F("F", t.solver);
// Solve
F.reset(A_test.sparsity());
F.pivoting(A_test.ptr());
F.factorize(A_test.ptr());
DM x = densify(b);
F.solve(x.ptr(), x.size2());
// Print the solution
cout << "solution: " << x << " (" << t.solver << ")" << endl;
}
}
return 0;
}