Perform LU decomposition. More...

Functions

AFAPI void lu (array &out, array &pivot, const array &in, const bool is_lapack_piv=true)
 C++ Interface for LU decomposition in packed format. More...
 
AFAPI void lu (array &lower, array &upper, array &pivot, const array &in)
 C++ Interface for LU decomposition. More...
 
AFAPI void luInPlace (array &pivot, array &in, const bool is_lapack_piv=true)
 C++ Interface for in place LU decomposition. More...
 
AFAPI af_err af_lu (af_array *lower, af_array *upper, af_array *pivot, const af_array in)
 C Interface for LU decomposition. More...
 
AFAPI af_err af_lu_inplace (af_array *pivot, af_array in, const bool is_lapack_piv)
 C Interface for in place LU decomposition. More...
 

Detailed Description

Perform LU decomposition.

This function decomposes input matrix A into a lower triangle L, an upper triangle U such that

\f$A = L * U\f$

For stability, a permutation array P is also used to modify the formula in the following manner.

\f$A(P, span) = L * U\f$

This operation can be performed in ArrayFire using the following code snippet.

array l, u, pivot;
lu(l, u, pivot, a_orig);

The permuted version of the original matrix can be reconstructed using the following snippet.

array a_recon = matmul(l, u);
array a_perm = a_orig(pivot, span);

The sample output for these operations can be seen below.

a_orig [3 3 1 1]
0.0000 3.0000 6.0000
1.0000 4.0000 7.0000
2.0000 5.0000 8.0000
l [3 3 1 1]
1.0000 0.0000 0.0000
0.0000 1.0000 0.0000
0.5000 0.5000 1.0000
u [3 3 1 1]
2.0000 5.0000 8.0000
0.0000 3.0000 6.0000
0.0000 0.0000 0.0000
pivot [3 1 1 1]
2
0
1
a_recon [3 3 1 1]
2.0000 5.0000 8.0000
0.0000 3.0000 6.0000
1.0000 4.0000 7.0000
a_perm [3 3 1 1]
2.0000 5.0000 8.0000
0.0000 3.0000 6.0000
1.0000 4.0000 7.0000

When memory is a concern, users can perform the LU decomposition in place as shown below.

array out = a_orig.copy();
array pivot2;
luInPlace(pivot2, out, false);

The lower and upper triangle matrices can be obtained if necessary in the following manner.

array l2 = lower(out, true);
array u2 = upper(out, false);

LU decompositions has many applications including solving a system of linear equations. Check af::solveLU fore more information.


Function Documentation

◆ af_lu()

AFAPI af_err af_lu ( af_array lower,
af_array upper,
af_array pivot,
const af_array  in 
)

C Interface for LU decomposition.

Parameters
[out]lowerwill contain the lower triangular matrix of the LU decomposition
[out]upperwill contain the upper triangular matrix of the LU decomposition
[out]pivotwill contain the permutation indices to map the input to the decomposition
[in]inis the input matrix

◆ af_lu_inplace()

AFAPI af_err af_lu_inplace ( af_array pivot,
af_array  in,
const bool  is_lapack_piv 
)

C Interface for in place LU decomposition.

Parameters
[out]pivotwill contain the permutation indices to map the input to the decomposition
[in,out]incontains the input on entry, the packed LU decomposition on exit
[in]is_lapack_pivspecifies if the pivot is returned in original LAPACK compliant format

◆ lu() [1/2]

AFAPI void af::lu ( array lower,
array upper,
array pivot,
const array in 
)

C++ Interface for LU decomposition.

Parameters
[out]lowerwill contain the lower triangular matrix of the LU decomposition
[out]upperwill contain the upper triangular matrix of the LU decomposition
[out]pivotwill contain the permutation indices to map the input to the decomposition
[in]inis the input matrix
Note
This function is not supported in GFOR

◆ lu() [2/2]

AFAPI void af::lu ( array out,
array pivot,
const array in,
const bool  is_lapack_piv = true 
)

C++ Interface for LU decomposition in packed format.

Parameters
[out]outis the output array containing the packed LU decomposition
[out]pivotwill contain the permutation indices to map the input to the decomposition
[in]inis the input matrix
[in]is_lapack_pivspecifies if the pivot is returned in original LAPACK compliant format
Note
This function is not supported in GFOR
Examples
lin_algebra/lu.cpp.

◆ luInPlace()

AFAPI void af::luInPlace ( array pivot,
array in,
const bool  is_lapack_piv = true 
)

C++ Interface for in place LU decomposition.

Parameters
[out]pivotwill contain the permutation indices to map the input to the decomposition
[in,out]incontains the input on entry, the packed LU decomposition on exit
[in]is_lapack_pivspecifies if the pivot is returned in original LAPACK compliant format
Note
This function is not supported in GFOR
Examples
lin_algebra/lu.cpp.
af::matmul
AFAPI array matmul(const array &lhs, const array &rhs, const matProp optLhs=AF_MAT_NONE, const matProp optRhs=AF_MAT_NONE)
Matrix multiply of two arrays.
af::lower
AFAPI array lower(const array &in, bool is_unit_diag=false)
afcl::array
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
Definition: opencl.h:327
af::luInPlace
AFAPI void luInPlace(array &pivot, array &in, const bool is_lapack_piv=true)
C++ Interface for in place LU decomposition.
af::lu
AFAPI void lu(array &out, array &pivot, const array &in, const bool is_lapack_piv=true)
C++ Interface for LU decomposition in packed format.
af::span
AFAPI seq span
A special value representing the entire axis of an af::array.
af::upper
AFAPI array upper(const array &in, bool is_unit_diag=false)
af::array::copy
array copy() const
Perform deep copy of the array.