Documentation
Solving linear systems

Enumerations

enum  af_solve_t {
af_solve_none = 0, af_solve_posdef = 1, af_solve_nonposdef = 2, af_solve_gaussian = 3,
af_solve_pseudo = 4, af_solve_ctrans = 256, af_solve_trans = 512, af_solve_uppertri = 1024,
af_solve_lowertri = 2048, af_solve_tridiag = 4096, af_solve_blkdiag = 8192
}

Functions

array solve (const array &A, const array &b, af_solve_t options=af_solve_none)
Solve linear system. More...

Enumeration Type Documentation

 enum af_solve_t
Enumerator
af_solve_none

Default.

af_solve_posdef

A is positive definite.

af_solve_nonposdef

A is not positive definite.

af_solve_gaussian

Use Gaussian elimination (fast, cannot be combined with other options)

af_solve_pseudo

Use pseudo inverse (fast, cannot be combined with other options)

af_solve_ctrans

Solve A.H() (conjugate transpose)

af_solve_trans

Solve A.T() (non-conjugate transpose)

af_solve_uppertri

Solve uppertri(A) (upper triangular system)

af_solve_lowertri

Solve lowertri(A) (lower triangular system)

af_solve_tridiag
af_solve_blkdiag

Function Documentation

 array af::solve ( const array & A, const array & b, af_solve_t options = af_solve_none )

Solve linear system.

Uses lu or cholesky for square systems and qr for non-square systems. Sparse matrices are not currently supported.

Double-precision or complex input requires ArrayFire Pro.

#include<stdio.h>
#include <arrayfire.h>
using namespace af;
int main(void)
{
try {
// create a coefficient matrix A
float h_buffer[] = {2, 3, 6, -4, -3, -1, 2, -4, 5}; // A = 2 -4 2
array A(3, 3, h_buffer); // 3 -3 -4
print(A); // 6 -1 5
// create a solution vector x
float h_sol[] = {-20, 32, 4.22}; // x = -20.00
array x(3, 1, h_sol); // 32.00
print(x); // 4.22
// create a right hand side vector b = Ax // b = -159.5600
array b = matmul(A, x); // -172.8800
print(b); // -130.9000
// solve for x using A and b
x = solve(A, b);
print(x);
} catch(af::exception &ae) {
std::cout << ae.what() << std::endl;
}
return 0;
}
Parameters
 [in] A system matrix [in] b residual vector or matrix [in] options bitwise combination (see af_solve_t)
Returns
x from the linear system A * x = b.
Examples:
examples/getting_started/lin_algebra.cpp.