ArrayFire Do more. Code less
Matrix Operations

## Modules

norm
Calculate the norm of a vector.

## Functions

array inverse (const array &in)
Matrix inversion. More...

array matpow (const array &base, double exponent)
Matrix power. More...

unsigned rank (const array &in, double tolerance=1e-5)
Rank of matrix. More...

template<typename T >
det (const array &in)
Matrix determinant. More...

## Function Documentation

 array af::inverse ( const array & in )

Matrix inversion.

For a square matrix A, this function returns the regular inverse IA of the same size as A, such that the following relationship is valid:

matmul(A, IA) = I


where I is an identity matrix of the same dimensions as A and IA.

If the input matrix is not square, the inverse operation swaps the rows and columns of the matrix and calculates what is sometimes called the pseudo-inverse.

matrix rows columns
input matrix m n
inverse matrix n m

Further, for non-square input matrices, it is always a multiplication of the flat matrix (m < n) and the tall matrix (m > n) that gives the identity matrix, as illustrated below for a flat matrix A of size 2 x 6 and a tall matrix B of size 6 x 2. The size of the (square) identity matrix is the minimum of m and n, which in the figure below is 2.

So depending on the orientation (tall or flat) of the input matrix, we either pre-multiply or post-multiply the (pseudo) inverse matrix to get the identity matrix.

Double-precision or complex input requires ArrayFire Pro.

array A = randu(5, 5);
array B = randu(5, 4);
array IA = inverse(A); // Regular inverse
array IB = inverse(B); // Psuedo inverse
Parameters
 [in] in square system matrix
Returns
inverse system
 array af::matpow ( const array & base, double exponent )

Matrix power.

Calculates the input array (typically a 2D matrix) raised to the specified exponent.

Double-precision or complex input requires ArrayFire Pro.

// matrix^3
array in = randu(5, 5);
array out = matpow(in, 3); // in x in x in
Parameters
 [in] base square [in] exponent
Returns
base raised to exponent
 unsigned af::rank ( const array & in, double tolerance = 1e-5 )

Double-precision or complex input requires ArrayFire Pro.

Parameters
 [in] in [in] tolerance only consider singular values greater than this
Returns
maximum of linearly independent column vectors
 T af::det ( const array & in )

Double-precision or complex input requires ArrayFire Pro.

Parameters
 [in] in square
Returns
scalar determinant