CLA3P v0.3.1
Compact Linear Algebra Parallel Portable Package
Loading...
Searching...
No Matches
ex05c_solving_linear_systems_auto.cpp
#include <iostream>
#include <cla3p/dense.hpp>
#include <cla3p/linsol.hpp>
#include <cla3p/algebra.hpp>
/*-----------------------------------------------------*/
template <typename T_Rhs>
static void solve_linear_system(const cla3p::dns::RdMatrix& A, const T_Rhs& B)
{
/*
* Decompose A into a product depending on property.
*/
autoSolver.decompose(A);
T_Rhs X = B;
/*
* Overwrite X with the solution (A^{-1} * B).
*/
autoSolver.solve(X);
std::string type_name = "Unknown";
if(std::is_same<T_Rhs, cla3p::dns::RdVector>::value) type_name = "Vector";
if(std::is_same<T_Rhs, cla3p::dns::RdMatrix>::value) type_name = "Matrix";
std::cout << " " << type_name << " rhs::";
std::cout << "Absolute error: " << (B - A * X).evaluate().normOne() << std::endl;
}
/*-----------------------------------------------------*/
int main()
{
/*
* Create a random general matrix.
*/
/*
* Create a random symmetric matrix.
*/
/*
* Create random right hand sides.
*/
std::cout << "General lhs\n";
solve_linear_system(Age, b);
solve_linear_system(Age, B);
std::cout << "\nSymmetric lhs\n";
solve_linear_system(Asy, b);
solve_linear_system(Asy, B);
return 0;
}
/*-----------------------------------------------------*/
The linear solver for dense matrices with automatic method detection.
Definition lapack_auto.hpp:39
void solve(T_Matrix &rhs) const
Performs in-place matrix solution.
void decompose(const T_Matrix &mat)
Performs matrix decomposition.
The property class.
Definition property.hpp:42
static Property SymmetricLower()
Factory method for lower-triangular symmetric property.
static XxMatrix< real_t > random(int_t nr, int_t nc, const Property &pr=Property::General(), T_RScalar lo=T_RScalar(0), T_RScalar hi=T_RScalar(1))
static XxVector< real_t > random(int_t n, T_RScalar lo=T_RScalar(0), T_RScalar hi=T_RScalar(1))
XxMatrix< real_t > RdMatrix
Double precision real matrix.
Definition dense.hpp:55
XxVector< real_t > RdVector
Double precision real vector.
Definition dense.hpp:31