Amesos2 - Direct Sparse Solver Interfaces Version of the Day
klu2_simple.cpp File Reference
#include <complex>
#include <iostream>
#include <stdexcept>
#include <vector>
#include "klu2_defaults.hpp"
#include "klu2_analyze.hpp"
#include "klu2_factor.hpp"
#include "klu2_solve.hpp"
#include "klu2_tsolve.hpp"
#include "klu2_free_symbolic.hpp"
#include "klu2_free_numeric.hpp"
Include dependency graph for klu2_simple.cpp:

Macros

#define ASSERT_EQ(a, b)
 Check that a and b are equal.
#define ASSERT_TOL_EQ(a, b, tol)
 Check that a and b are equal to the given asolute tolerance.

Functions

template<typename T, typename tol_t>
void print_and_compare (const std::vector< T > &values_a, const std::vector< T > &values_b, const tol_t tol)
 Print vectors and compare them.
template<typename T, typename D = int, typename tol_t>
void solve_and_check (const tol_t tol)
int main (void)

Data.

This simple example will solve the following linear system:

*
*          Matrix               Solution   Right-hand side
*
* | 2. |  3. |     |    |    |    [ 1 ]       [  8 ]
* | 3. |     |  4. |    | 6. |    [ 2 ]       [ 45 ]
* |    | -1. | -3. | 2. |    |    [ 3 ]     = [ -3 ]
* |    |     |  1. |    |    |    [ 4 ]       [  3 ]
* |    |  4. |  2. |    | 1. |    [ 5 ]       [ 19 ]
*
* 
Warning
The algorithm works with the compressed column storage format (CCS).
const int size = 5
int Ap [] = {0, 2, 5, 9, 10, 12}
 Column offsets.
int Ai [] = { 0 , 1 , 0 , 2 , 4 , 1 , 2 , 3 , 4 , 2 , 1 , 4 }
 Row values.
template<typename T>
auto get_Ax ()
 Get entries values.
template<typename T>
auto get_b ()
 Get right-hand side values.
template<typename T>
auto get_x ()
 Get solution.
template<typename T>
auto get_x_transpose ()
 Get solution for transposed matrix.

Detailed Description

This file contains a standalone test for the KLU2 solver.

Macro Definition Documentation

◆ ASSERT_EQ

#define ASSERT_EQ ( a,
b )
Value:
if(a != b) throw std::runtime_error(#a " is different from " #b);

Check that a and b are equal.

Referenced by print_and_compare().

◆ ASSERT_TOL_EQ

#define ASSERT_TOL_EQ ( a,
b,
tol )
Value:
if( std::abs(a-b) > tol ) throw std::runtime_error(#a " is different from " #b);

Check that a and b are equal to the given asolute tolerance.

Referenced by print_and_compare().

Function Documentation

◆ solve_and_check()

template<typename T, typename D = int, typename tol_t>
void solve_and_check ( const tol_t tol)

Solve and check the solution.

Query data for

Template Parameters
T.

Symbolic step.

Numeric step.

Solve and check against expected solution. Note that klu_solve writes the solution into b.

Transpose solve. Note that klu_solve writes the solution into b.

Free memory.

References Ai, Ap, get_Ax(), get_b(), get_x(), get_x_transpose(), print_and_compare(), and size.

Referenced by main().

◆ main()

int main ( void )

Solve for float.

Solve for double.

Solve for std::complex<float>.

Todo
This does not compile for now!
Examples
MultipleSolves_File.cpp, SimpleSolve.cpp, SimpleSolve_File.cpp, SimpleSolve_WithParameters.cpp, and TwoPartSolve.cpp.

References solve_and_check().

Variable Documentation

◆ size