Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Macros | Functions
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)   if(a != b) throw std::runtime_error(#a " is different from " #b);
 Check that a and b are equal.
 
#define ASSERT_TOL_EQ(a, b, tol)   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.
 

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.

Function Documentation

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, and size.

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.

Variable Documentation

const int size = 5