CUDA
C/C++    Fortran   

Matrix Operations

Functions

template<typename ty >
ty norm (const array &in, float p=af::NaN)
 Matrix or vector norm.
array inverse (const array &in)
 Matrix inversion.
array matpow (const array &base, double exponent)
 Matrix power.
unsigned rank (const array &in, double tolerance=1e-5)
 Rank of matrix.
template<typename T >
det (const array &in)
 Matrix determinant.

Function Documentation

ty af::norm ( const array &  in,
float  p = af::NaN 
)

Matrix or vector norm.

Some options require ArrayFire Pro.

    // compute norm of vector x
    array x = randu(1e5);
    float y = norm<float>(x);
Parameters:
[in]in
[in]ptype of norm:

  • p == Inf returns max(abs(in)) for vectors, infinity norm for matrices
  • p == -Inf returns min(abs(in)) for vectors, not supported for matrices
  • p == NaN (default) returns Euclidean norm for both vectors and matrices
  • p (anything else) returns p norm of the input
Note:
if p is 2 and the input is vector, ArrayFire Pro license is required.
Examples:
examples/machine_learning/pca.cpp.
array af::inverse ( const array &  in)

Matrix inversion.

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]insquare system matrix
Returns:
inverse system
array af::matpow ( const array &  base,
double  exponent 
)

Matrix power.

Double-precision or complex input requires ArrayFire Pro.

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

Rank of matrix.

Double-precision or complex input requires ArrayFire Pro.

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

Matrix determinant.

Double-precision or complex input requires ArrayFire Pro.

Parameters:
[in]insquare
Returns:
scalar determinant