max@0: max@0: max@0: max@0: max@0: Armadillo: C++ linear algebra library max@0: max@0: max@0: max@0: max@0:
max@0: max@0: max@0: max@0: max@0: max@0: max@0:
max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
max@0: Reference for Armadillo 2.4.4 max@0:
max@0: (Loco Lounge Lizard) max@0:
max@0: to Armadillo home page max@0:
max@0: to NICTA home page max@0:
max@0:
max@0:
max@0:
max@0: max@0: [top] max@0: max@0: max@0: max@0: max@0: max@0: Preamble max@0:
max@0:
max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
max@0:
    max@0:
  • max@0: To aid the conversion of Matlab/Octave programs, max@0: there is a syntax conversion table max@0:
  • max@0:
    max@0:
  • max@0: First time users may want to have a look at a short example program max@0:
  • max@0:
    max@0:
  • max@0: If you find any bugs or regressions, please report them max@0:
  • max@0:
    max@0:
  • max@0: Caveat: the API for version 2.x has changes & additions compared to version 1.2; max@0: see also the list of deprecated functionality max@0:
  • max@0:
max@0:
max@0:   max@0: max@0:
max@0:
max@0: max@0:
max@0: max@0:
max@0:
max@0: max@0: Matrix, Vector, Cube and Field Classes max@0: max@0:
max@0: max@0: Member Functions & Variables max@0: max@0:
max@0: max@0: Other Classes max@0: max@0:
max@0: max@0: Generated Vectors/Matrices/Cubes max@0: max@0:
max@0: max@0: Functions Individually Applied to Each Element of a Matrix/Cube max@0: max@0:
max@0: max@0: Scalar Valued Functions of Vectors/Matrices/Cubes max@0: max@0:
max@0: max@0: Scalar/Vector Valued Functions of Vectors/Matrices max@0: max@0:
max@0: max@0: Vector/Matrix/Cube Valued Functions of Vectors/Matrices/Cubes max@0: max@0:
max@0: max@0: Decompositions, Inverses and Equation Solvers max@0: max@0:
max@0: max@0: Miscellaneous max@0: max@0:
max@0: max@0:
max@0:
max@0:
max@0:
max@0:
max@0:
max@0: Matrix, Vector, Cube and Field Classes max@0:
max@0:
max@0:
max@0:
max@0: max@0: Mat<type> max@0:
mat max@0:
cx_mat max@0:
    max@0:
  • max@0: The root template matrix class is Mat<type>, where type can be one of: max@0: char, int, float, double, std::complex<double>, etc. max@0:
  • max@0:
    max@0:
  • max@0: For convenience the following typedefs have been defined: max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: umat max@0: max@0:  =  max@0: max@0: Mat<uword> max@0:
      max@0: imat max@0: max@0:  =  max@0: max@0: Mat<sword> max@0:
      max@0: fmat max@0: max@0:  =  max@0: max@0: Mat<float> max@0:
      max@0: mat max@0: max@0:  =  max@0: max@0: Mat<double> max@0:
      max@0: cx_fmat max@0: max@0:  =  max@0: max@0: Mat<cx_float> max@0:
      max@0: cx_mat max@0: max@0:  =  max@0: max@0: Mat<cx_double> max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: In this documentation the mat type is used for convenience; max@0: it is possible to use other types instead, eg. fmat max@0:
  • max@0:
    max@0:
  • max@0: Functions which are wrappers for LAPACK or ATLAS functions (generally matrix decompositions) are only valid for the following types: max@0: fmat, mat, cx_fmat, cx_mat max@0:
  • max@0:
    max@0:
  • max@0: Elements are stored with column-major ordering (ie. column by column) max@0:
  • max@0:
    max@0: max@0:
  • max@0: Constructors: max@0:
      max@0:
    • mat()
    • max@0:
    • mat(n_rows, n_cols)
    • max@0:
    • mat(mat)
    • max@0:
    • mat(vec)
    • max@0:
    • mat(rowvec)
    • max@0:
    • mat(string)
    • max@0:
    • mat(initialiser_list)   (C++11 only)
    • max@0:
    • cx_mat(mat,mat)   (for constructing a complex matrix out of two real matrices)
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: The string format for the constructor is elements separated by spaces, and rows denoted by semicolons. max@0: For example, the 2x2 identity matrix can be created using the format string "1 0; 0 1". max@0: While string based initialisation is compact, directly setting the elements or using element initialisation is considerably faster. max@0:
  • max@0:
    max@0: max@0:
  • max@0: Advanced constructors: max@0:
    max@0:
    max@0:
      max@0:
    • mat(aux_mem*, n_rows, n_cols, copy_aux_mem = true, strict = true) max@0:
      max@0:
      max@0:
        max@0: Create a matrix using data from writeable auxiliary memory. max@0: By default the matrix allocates its own memory and copies data from the auxiliary memory (for safety). max@0: However, if copy_aux_mem is set to false, max@0: the matrix will instead directly use the auxiliary memory (ie. no copying). max@0: This is faster, but can be dangerous unless you know what you're doing! max@0:
        max@0:
        max@0: The strict variable comes into effect only if copy_aux_mem is set to false max@0: (ie. the matrix is directly using auxiliary memory). max@0: If strict is set to true, max@0: the matrix will be bound to the auxiliary memory for its lifetime; max@0: the number of elements in the matrix can't be changed (directly or indirectly). max@0: If strict is set to false, the matrix will not be bound to the auxiliary memory for its lifetime, max@0: ie., the size of the matrix can be changed. max@0: If the requested number of elements is different to the size of the auxiliary memory, max@0: new memory will be allocated and the auxiliary memory will no longer be used. max@0:
      max@0:
    • max@0:
      max@0:
    • mat(const aux_mem*, n_rows, n_cols) max@0:
      max@0:
      max@0:
        max@0: Create a matrix by copying data from read-only auxiliary memory. max@0:
      max@0:
    • max@0: max@0:
      max@0:
    • mat::fixed<n_rows, n_cols> max@0:
      max@0:
      max@0:
        max@0: Create a fixed size matrix, with the size specified via template arguments. max@0: Memory for the matrix is allocated at compile time. max@0: This is generally faster than dynamic memory allocation, but the size of the matrix can't be changed afterwards (directly or indirectly). max@0:
        max@0:
        max@0: For convenience, there are several pre-defined typedefs for each matrix type max@0: (where the types are: umat, imat, fmat, mat, cx_fmat, cx_mat). max@0: The typedefs specify a square matrix size, ranging from 2x2 to 9x9. max@0: The typedefs were defined by simply appending a two digit form of the size to the matrix type max@0: -- for example, mat33 is equivalent to mat::fixed<3,3>, max@0: while cx_mat44 is equivalent to cx_mat::fixed<4,4>. max@0:
      max@0:
    • max@0:
      max@0:
    • mat::fixed<n_rows, n_cols>(const aux_mem*) max@0:
      max@0:
      max@0:
        max@0: Create a fixed size matrix, with the size specified via template arguments, max@0: and copying data from auxiliary memory. max@0:
      max@0:
    • max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: double x = A(1,2);
      max@0: 
      max@0: mat B = A + A;
      max@0: mat C = A * B;
      max@0: mat D = A % B;
      max@0: 
      max@0: cx_mat X(A,B);
      max@0: 
      max@0: B.zeros();
      max@0: B.set_size(10,10);
      max@0: B.zeros(5,6);
      max@0: 
      max@0: //
      max@0: // fixed size matrices:
      max@0: 
      max@0: mat::fixed<5,6> F;
      max@0: F.ones();
      max@0: 
      max@0: mat44 G;
      max@0: G.randn();
      max@0: 
      max@0: cout << mat22().randu() << endl;
      max@0: 
      max@0: //
      max@0: // constructing matrices from
      max@0: // auxiliary (external) memory:
      max@0: 
      max@0: double aux_mem[24];
      max@0: mat H(aux_mem, 4, 6, false);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • Caveat: max@0: For mathematical correctness, scalars are treated as 1x1 matrices during initialisation. max@0: As such, the code below will not generate a 5x5 matrix with every element equal to 123.0: max@0:
      max@0:
      max@0: mat A(5,5);
      max@0: A = 123.0;
      max@0: 
      max@0:
    max@0: Use the following code instead: max@0:
      max@0:
      max@0: mat A(5,5);
      max@0: A.fill(123.0);
      max@0: 
      max@0:
    max@0: Or: max@0:
      max@0:
      max@0: mat A = 123.0 * ones<mat>(5,5);
      max@0: 
      max@0:
    max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: Col<type> max@0:
colvec max@0:
vec max@0:
    max@0:
  • max@0: Classes for column vectors (matrices with one column) max@0:
  • max@0:
    max@0:
  • The Col<type> class is derived from the Mat<type> class max@0: and inherits most of the member functions max@0:
  • max@0:
    max@0:
  • max@0: For convenience the following typedefs have been defined: max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: uvec, ucolvec max@0: max@0:  =  max@0: max@0: Col<uword> max@0:
      max@0: ivec, icolvec max@0: max@0:  =  max@0: max@0: Col<sword> max@0:
      max@0: fvec, fcolvec max@0: max@0:  =  max@0: max@0: Col<float> max@0:
      max@0: vec, colvec max@0: max@0:  =  max@0: max@0: Col<double> max@0:
      max@0: cx_fvec, cx_fcolvec max@0: max@0:  =  max@0: max@0: Col<cx_float> max@0:
      max@0: cx_vec, cx_colvec max@0: max@0:  =  max@0: max@0: Col<cx_double> max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: In this documentation, the vec and colvec types have the same meaning and are used interchangeably max@0:
  • max@0:
    max@0:
  • max@0: In this documentation, the types vec or colvec are used for convenience; it is possible to use other types instead, eg. fvec, fcolvec max@0:
  • max@0:
    max@0:
  • max@0: Functions which take Mat as input can generally also take Col as input. max@0: Main exceptions are functions which require square matrices max@0:
  • max@0:
    max@0:
  • max@0: Constructors max@0:
      max@0:
    • vec(n_elem=0)
    • max@0:
    • vec(vec)
    • max@0:
    • vec(mat)   (a std::logic_error exception is thrown if the given matrix has more than one column)
    • max@0:
    • vec(string)   (elements separated by spaces)
    • max@0:
    • vec(initialiser_list)   (C++11 only)
    • max@0:
    max@0:
  • max@0:
    max@0: max@0:
  • max@0: Advanced constructors: max@0:
    max@0:
    max@0:
      max@0:
    • vec(aux_mem*, number_of_elements, copy_aux_mem = true, strict = true) max@0:
      max@0:
      max@0:
        max@0: Create a column vector using data from writeable auxiliary memory. max@0: By default the vector allocates its own memory and copies data from the auxiliary memory (for safety). max@0: However, if copy_aux_mem is set to false, max@0: the vector will instead directly use the auxiliary memory (ie. no copying). max@0: This is faster, but can be dangerous unless you know what you're doing! max@0:
        max@0:
        max@0: The strict variable comes into effect only if copy_aux_mem is set to false max@0: (ie. the vector is directly using auxiliary memory). max@0: If strict is set to true, max@0: the vector will be bound to the auxiliary memory for its lifetime; max@0: the number of elements in the vector can't be changed (directly or indirectly). max@0: If strict is set to false, the vector will not be bound to the auxiliary memory for its lifetime, max@0: ie., the vector's size can be changed. max@0: If the requested number of elements is different to the size of the auxiliary memory, max@0: new memory will be allocated and the auxiliary memory will no longer be used. max@0:
      max@0:
    • max@0:
      max@0:
    • vec(const aux_mem*, number_of_elements) max@0:
      max@0:
      max@0:
        max@0: Create a column vector by copying data from read-only auxiliary memory. max@0:
      max@0:
    • max@0:
      max@0:
    • vec::fixed<number_of_elements> max@0:
      max@0:
      max@0:
        max@0: Create a fixed size column vector, with the size specified via the template argument. max@0: Memory for the vector is allocated at compile time. max@0: This is generally faster than dynamic memory allocation, but the size of the vector can't be changed afterwards (directly or indirectly). max@0:
        max@0:
        max@0: For convenience, there are several pre-defined typedefs for each vector type max@0: (where the types are: uvec, ivec, fvec, vec, cx_fvec, cx_vec as well as the corresponding colvec versions). max@0: The pre-defined typedefs specify vector sizes ranging from 2 to 9. max@0: The typedefs were defined by simply appending a single digit form of the size to the vector type max@0: -- for example, vec3 is equivalent to vec::fixed<3>, max@0: while cx_vec4 is equivalent to cx_vec::fixed<4>. max@0:
      max@0:
    • max@0:
      max@0:
    • vec::fixed<number_of_elements>(const aux_mem*) max@0:
      max@0:
      max@0:
        max@0: Create a fixed size column vector, with the size specified via the template argument, max@0: and copying data from auxiliary memory. max@0:
      max@0:
    • max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec x(10);
      max@0: vec y = zeros<vec>(10,1);
      max@0: 
      max@0: mat A = randu<mat>(10,10);
      max@0: vec z = A.col(5); // extract a column vector
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • Caveat: max@0: For mathematical correctness, scalars are treated as 1x1 matrices during initialisation. max@0: As such, the code below will not generate a column vector with every element equal to 123.0: max@0:
      max@0:
      max@0: vec q(5);
      max@0: q = 123.0;
      max@0: 
      max@0:
    max@0: Use the following code instead: max@0:
      max@0:
      max@0: vec q(5);
      max@0: q.fill(123.0);
      max@0: 
      max@0:
    max@0: Or: max@0:
      max@0:
      max@0: vec q = 123.0 * ones<vec>(5,1);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: Row<type> max@0:
rowvec max@0:
    max@0:
  • max@0: Classes for row vectors (matrices with one row) max@0:
  • max@0:
    max@0:
  • The template Row<type> class is derived from the Mat<type> class max@0: and inherits most of the member functions max@0:
  • max@0:
    max@0:
  • max@0: For convenience the following typedefs have been defined: max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: urowvec max@0: max@0:  =  max@0: max@0: Row<uword> max@0:
      max@0: irowvec max@0: max@0:  =  max@0: max@0: Row<sword> max@0:
      max@0: frowvec max@0: max@0:  =  max@0: max@0: Row<float> max@0:
      max@0: rowvec max@0: max@0:  =  max@0: max@0: Row<double> max@0:
      max@0: cx_frowvec max@0: max@0:  =  max@0: max@0: Row<cx_float> max@0:
      max@0: cx_rowvec max@0: max@0:  =  max@0: max@0: Row<cx_double> max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: In this documentation, the rowvec type is used for convenience; max@0: it is possible to use other types instead, eg. frowvec max@0:
  • max@0:
    max@0:
  • max@0: Functions which take Mat as input can generally also take Row as input. max@0: Main exceptions are functions which require square matrices max@0:
  • max@0:
    max@0:
  • max@0: Constructors max@0:
      max@0:
    • rowvec(n_elem=0)
    • max@0:
    • rowvec(rowvec)
    • max@0:
    • rowvec(mat)   (a std::logic_error exception is thrown if the given matrix has more than one row)
    • max@0:
    • rowvec(string)   (elements separated by spaces)
    • max@0:
    • rowvec(initialiser_list)   (C++11 only)
    • max@0:
    max@0:
  • max@0:
    max@0: max@0:
  • max@0: Advanced constructors: max@0:
    max@0:
    max@0:
      max@0:
    • rowvec(aux_mem*, number_of_elements, copy_aux_mem = true, strict = true) max@0:
      max@0:
      max@0:
        max@0: Create a row vector using data from writeable auxiliary memory. max@0: By default the vector allocates its own memory and copies data from the auxiliary memory (for safety). max@0: However, if copy_aux_mem is set to false, max@0: the vector will instead directly use the auxiliary memory (ie. no copying). max@0: This is faster, but can be dangerous unless you know what you're doing! max@0:
        max@0:
        max@0: The strict variable comes into effect only if copy_aux_mem is set to false max@0: (ie. the vector is directly using auxiliary memory). max@0: If strict is set to true, max@0: the vector will be bound to the auxiliary memory for its lifetime; max@0: the number of elements in the vector can't be changed (directly or indirectly). max@0: If strict is set to false, the vector will not be bound to the auxiliary memory for its lifetime, max@0: ie., the vector's size can be changed. max@0: If the requested number of elements is different to the size of the auxiliary memory, max@0: new memory will be allocated and the auxiliary memory will no longer be used. max@0:
      max@0:
    • max@0:
      max@0:
    • rowvec(const aux_mem*, number_of_elements) max@0:
      max@0:
      max@0:
        max@0: Create a row vector by copying data from read-only auxiliary memory. max@0:
      max@0:
    • max@0:
      max@0:
    • rowvec::fixed<number_of_elements> max@0:
      max@0:
      max@0:
        max@0: Create a fixed size row vector, with the size specified via the template argument. max@0: Memory for the vector is allocated at compile time. max@0: This is generally faster than dynamic memory allocation, but the size of the vector can't be changed afterwards (directly or indirectly). max@0:
        max@0:
        max@0: For convenience, there are several pre-defined typedefs for each vector type max@0: (where the types are: urowvec, irowvec, frowvec, rowvec, cx_frowvec, cx_rowvec). max@0: The pre-defined typedefs specify vector sizes ranging from 2 to 9. max@0: The typedefs were defined by simply appending a single digit form of the size to the vector type max@0: -- for example, rowvec3 is equivalent to rowvec::fixed<3>, max@0: while cx_rowvec4 is equivalent to cx_rowvec::fixed<4>. max@0:
      max@0:
    • max@0:
      max@0:
    • rowvec::fixed<number_of_elements>(const aux_mem*) max@0:
      max@0:
      max@0:
        max@0: Create a fixed size row vector, with the size specified via the template argument, max@0: and copying data from auxiliary memory. max@0:
      max@0:
    • max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: rowvec x(10);
      max@0: rowvec y = zeros<mat>(1,10);
      max@0: 
      max@0: mat A = randu<mat>(10,10);
      max@0: rowvec z = A.row(5); // extract a row vector
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: For mathematical correctness, scalars are treated as 1x1 matrices during initialisation. max@0: As such, the code below will not generate a row vector with every element equal to 123.0: max@0:
      max@0:
      max@0: rowvec r(5);
      max@0: r = 123.0;
      max@0: 
      max@0:
    max@0: Use the following code instead: max@0:
      max@0:
      max@0: rowvec r(5);
      max@0: r.fill(123.0);
      max@0: 
      max@0:
    max@0: Or: max@0:
      max@0:
      max@0: rowvec r = 123.0 * ones<rowvec>(1,5);
      max@0: 
      max@0:
    max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: max@0: Cube<type> max@0:
cube max@0:
cx_cube max@0:
    max@0:
  • max@0: Classes for cubes, also known as "3D matrices" max@0:
  • max@0:
    max@0:
  • max@0: The root template cube class is Cube<type>, where type can be one of: max@0: char, int, float, double, std::complex<double>, etc max@0:
  • max@0:
    max@0:
  • max@0: For convenience the following typedefs have been defined: max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: ucube max@0: max@0:  =  max@0: max@0: Cube<uword> max@0:
      max@0: icube max@0: max@0:  =  max@0: max@0: Cube<sword> max@0:
      max@0: fcube max@0: max@0:  =  max@0: max@0: Cube<float> max@0:
      max@0: cube max@0: max@0:  =  max@0: max@0: Cube<double> max@0:
      max@0: cx_fcube max@0: max@0:  =  max@0: max@0: Cube<cx_float> max@0:
      max@0: cx_cube max@0: max@0:  =  max@0: max@0: Cube<cx_double> max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: In this documentation the cube type is used for convenience; max@0: it is possible to use other types instead, eg. fcube max@0:
  • max@0:
    max@0:
  • max@0: Cube data is stored as a set of slices (matrices) stored contiguously within memory. max@0: Within each slice, elements are stored with column-major ordering (ie. column by column) max@0:
  • max@0:
    max@0:
  • max@0: Each slice can be interpreted as a matrix, hence functions which take Mat as input can generally also take cube slices as input max@0:
  • max@0:
    max@0: max@0:
  • max@0: Constructors: max@0:
      max@0: cube() max@0:
      cube(cube) max@0:
      cube(n_rows, n_cols, n_slices) max@0:
      cx_cube(cube, cube) (for constructing a complex cube out of two real cubes) max@0:
    max@0:
  • max@0:
    max@0: max@0: max@0:
  • max@0: Advanced constructors: max@0:
    max@0:
    max@0:
      max@0:
    • max@0: cube::fixed<n_rows, n_cols, n_slices> max@0:
      max@0:
      max@0:
        max@0: Create a fixed size cube, with the size specified via template arguments. max@0: Memory for the cube is allocated at compile time. max@0: This is generally faster than dynamic memory allocation, but the size of the cube can't be changed afterwards (directly or indirectly). max@0:
      max@0:
    • max@0:
      max@0:
    • cube(aux_mem*, n_rows, n_cols, n_slices, copy_aux_mem = true, strict = true) max@0:
      max@0:
      max@0:
        max@0: Create a cube using data from writeable auxiliary memory. max@0: By default the cube allocates its own memory and copies data from the auxiliary memory (for safety). max@0: However, if copy_aux_mem is set to false, max@0: the cube will instead directly use the auxiliary memory (ie. no copying). max@0: This is faster, but can be dangerous unless you know what you're doing! max@0:
        max@0:
        max@0: The strict variable comes into effect only if copy_aux_mem is set to false max@0: (ie. the cube is directly using auxiliary memory). max@0: If strict is set to true, max@0: the cube will be bound to the auxiliary memory for its lifetime; max@0: the number of elements in the cube can't be changed (directly or indirectly). max@0: If strict is set to false, the cube will not be bound to the auxiliary memory for its lifetime, max@0: ie., the size of the cube can be changed. max@0: If the requested number of elements is different to the size of the auxiliary memory, max@0: new memory will be allocated and the auxiliary memory will no longer be used. max@0:
      max@0:
    • max@0:
      max@0:
    • cube(const aux_mem*, n_rows, n_cols, n_slices) max@0:
      max@0:
      max@0:
        max@0: Create a cube by copying data from read-only auxiliary memory. max@0:
      max@0:
    • max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: cube x(1,2,3);
      max@0: cube y = randu<cube>(4,5,6);
      max@0: 
      max@0: mat A = y.slice(1);  // extract a slice from the cube
      max@0:                      // (each slice is a matrix)
      max@0: 
      max@0: mat B = randu<mat>(4,5);
      max@0: y.slice(2) = B;     // set a slice in the cube
      max@0: 
      max@0: cube q = y + y;     // cube addition
      max@0: cube r = y % y;     // element-wise cube multiplication
      max@0: 
      max@0: cube::fixed<4,5,6> f;
      max@0: f.ones();
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Caveats max@0:
    max@0:
    max@0:
      max@0:
    • max@0: The size of individual slices can't be changed. max@0: For example, the following will not work: max@0:
        max@0:
        max@0: cube c(5,6,7);
        max@0: c.slice(0) = randu<mat>(10,20); // wrong size
        max@0: 
        max@0:
      max@0:
    • max@0:
    • max@0: For mathematical correctness, scalars are treated as 1x1x1 cubes during initialisation. max@0: As such, the code below will not generate a cube with every element equal to 123.0: max@0:
        max@0:
        max@0: cube c(5,6,7);
        max@0: c = 123.0;
        max@0: 
        max@0:
      max@0: Use the following code instead: max@0:
        max@0:
        max@0: cube c(5,6,7);
        max@0: c.fill(123.0);
        max@0: 
        max@0:
      max@0: Or: max@0:
        max@0:
        max@0: cube c = 123.0 * ones<cube>(5,6,7);
        max@0: 
        max@0:
      max@0:
    • max@0:
    max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: max@0: field<object type> max@0:
    max@0:
  • max@0: Class for one and two dimensional fields of arbitrary objects max@0:
  • max@0:
    max@0:
  • max@0: Constructors (where object type is another class, eg. std::string, mat, vec, rowvec, etc): max@0:
      max@0: field<object type>(n_elem=0) max@0:
      field<object type>(n_rows, n_cols) max@0:
      field<object type>(field<object type>) max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: // create a field of strings
      max@0: field<std::string> S(3,2);
      max@0: 
      max@0: S(0,0) = "hello";
      max@0: S(1,0) = "there";
      max@0: 
      max@0: // string fields can be saved as plain text files
      max@0: S.save("string_field");
      max@0: 
      max@0: // create a vec field with 3 rows and 2 columns
      max@0: field<vec> F(3,2);
      max@0: 
      max@0: // access components of the field
      max@0: F(0,0) = vec(5);
      max@0: F(1,1) = randu<vec>(6);
      max@0: F(2,0).set_size(7);
      max@0: 
      max@0: // access element 1 of the vec stored at 2,0
      max@0: double x = F(2,0)(1);
      max@0: 
      max@0: // copy rows
      max@0: F.row(0) = F.row(2);
      max@0: 
      max@0: // extract a row of vecs from F
      max@0: field<vec> G = F.row(1);
      max@0: 
      max@0: // print the field to the standard output
      max@0: G.print("G =");
      max@0: 
      max@0: // save the field to a binary file
      max@0: G.save("vec_field");
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0:
max@0:
max@0: Member Functions & Variables max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: max@0: attributes max@0:
    max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
    max@0: .n_rows max@0:    max@0: (number of rows) max@0:
    max@0: .n_cols max@0:    max@0: (number of columns) max@0:
    max@0: .n_elem max@0:    max@0: (total number of elements) max@0:
    max@0: .n_slices max@0:    max@0: (number of slices) max@0:
    max@0:
max@0:
max@0:
    max@0:
  • max@0: Member variables which are read-only; max@0: to change the size, use max@0: .set_size(), max@0: .copy_size(), max@0: .zeros(), max@0: .ones(), max@0: or max@0: .reset() max@0:
  • max@0:
    max@0:
  • n_rows, n_cols and n_elem are applicable to Mat, Col, Row, Cube and field classes
  • max@0:
    max@0:
  • n_slices is applicable only to the Cube class
  • max@0:
    max@0:
  • max@0: For the Col and Row classes, n_elem also indicates vector length
  • max@0:
    max@0:
  • The variables are of type uword
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X(4,5);
      max@0: cout << "X has " << X.n_cols << " columns" << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .colptr(col_number) max@0:
    max@0:
  • max@0: Member function of Mat max@0:
  • max@0:
    max@0:
  • max@0: Obtain a raw pointer to the memory used by the specified column max@0:
  • max@0:
    max@0:
  • max@0: As soon as the size of the matrix is changed, the pointer is no longer valid max@0:
  • max@0:
    max@0:
  • This function is not recommended for use unless you know what you're doing max@0: -- you may wish to use submatrix views instead max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: 
      max@0: double* mem = A.colptr(2);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .copy_size(A) max@0:
    max@0:
  • max@0: Member function of Mat, Col, Row, Cube and field max@0:
  • max@0:
    max@0:
  • max@0: Set the size to be the same as object A max@0:
  • max@0:
    max@0:
  • max@0: Object A must be of the same root type as the object being modified max@0: (eg. you can't set the size of a matrix by providing a cube) max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,6);
      max@0: mat B;
      max@0: B.copy_size(A);
      max@0: 
      max@0: cout << B.n_rows << endl;
      max@0: cout << B.n_cols << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: .diag(k=0) max@0:
    max@0:
  • max@0: Member function of Mat. max@0:
  • max@0:
    max@0:
  • max@0: Read/write access to the k-th diagonal in a matrix max@0:
  • max@0:
    max@0:
  • The argument k is optional -- by default the main diagonal is accessed (k=0)
  • max@0:
    max@0:
  • For k > 0, the k-th super-diagonal is accessed (top-right corner)
  • max@0:
    max@0:
  • For k < 0, the k-th sub-diagonal is accessed (bottom-left corner)
  • max@0:
    max@0:
  • max@0: An extracted diagonal is interpreted as a column vector max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat    X = randu<mat>(5,5);
      max@0: 
      max@0: vec a = X.diag();
      max@0: vec b = X.diag(1);
      max@0: vec c = X.diag(-2);
      max@0: 
      max@0: X.diag()  = randu<vec>(5);
      max@0: X.diag() += 6;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: element/object access via (), [] and .at() max@0:
    max@0:
  • max@0: Provide access to individual elements or objects stored in a container object max@0: (ie., Mat, Col, Row, Cube, field)
    max@0:
    max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0:
      (n)
      max@0:
       
      max@0:
      max@0: For vec and rowvec, access the n-th element. max@0: For mat, cube and field, access the n-th element/object under the assumption of a flat layout, max@0: with column-major ordering of data (ie. column by column). max@0: A std::logic_error exception is thrown if the requested element is out of bounds. max@0: The bounds check can be optionally disabled at compile-time (see below). max@0:
         
      max@0:
      .at(n) and [n]
      max@0:

      max@0:
      max@0: As for (n), but without a bounds check. max@0: Not recommended for use unless your code has been thoroughly debugged. max@0:
         
      max@0:
      (i,j)
      max@0:

      max@0:
      max@0: For mat and field classes, access the element/object stored at the i-th row and j-th column. max@0: A std::logic_error exception is thrown if the requested element is out of bounds. max@0: The bounds check can be optionally disabled at compile-time (see below). max@0:
         
      max@0:
      .at(i,j)
      max@0:

      max@0:
      max@0: As for (i,j), but without a bounds check. max@0: Not recommended for use unless your code has been thoroughly debugged. max@0:
      max@0:
         
      max@0:
      (i,j,k)
      max@0:

      max@0:
      max@0: Cube only: access the element stored at the i-th row, j-th column and k-th slice. max@0: A std::logic_error exception is thrown if the requested element is out of bounds. max@0: The bounds check can be optionally disabled at compile-time (see below). max@0:
         
      max@0:
      .at(i,j,k)
      max@0:

      max@0:
      max@0: As for (i,j,k), but without a bounds check. max@0: Not recommended for use unless your code has been thoroughly debugged.
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: The bounds checks used by the (n), (i,j) and (i,j,k) access forms max@0: can be disabled by defining ARMA_NO_DEBUG or NDEBUG macros max@0: before including the armadillo header file (eg. #define ARMA_NO_DEBUG). max@0: Disabling the bounds checks is not recommended until your code has been thoroughly debugged max@0: -- it's better to write correct code first, and then maximise its speed. max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(10,10);
      max@0: A(9,9) = 123.0;
      max@0: double x = A.at(9,9);
      max@0: double y = A[99];
      max@0: 
      max@0: vec p = randu<vec>(10,1);
      max@0: p(9) = 123.0;
      max@0: double z = p[9];
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: element initialisation max@0:
    max@0:
  • max@0: Instances of Mat, Col, Row and field classes can be initialised via repeated use of the << operator max@0:
  • max@0:
    max@0:
  • max@0: Special element endr indicates "end of row" (conceptually similar to std::endl) max@0:
  • max@0:
    max@0:
  • max@0: Setting elements via << is a bit slower than directly accessing the elements, max@0: but code using << is generally more readable as well as being easier to write max@0:
  • max@0:
    max@0:
  • max@0: If you have a C++11 compiler, instances of Mat, Col and Row classes can be also initialised via initialiser lists; max@0: this requires support for the C++11 standard to be explicitly enabled max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A;
      max@0: 
      max@0: A << 1 << 2 << 3 << endr
      max@0:   << 4 << 5 << 6 << endr;
      max@0: 
      max@0: mat B = { 1, 2, 3, 4, 5, 6 };  // C++11 only
      max@0: B.reshape(2,3);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .eye() max@0:
max@0: .eye(n_rows, n_cols) max@0:
    max@0:
  • max@0: Set the elements along the main diagonal to one and off-diagonal elements set to zero, max@0: optionally first resizing to specified dimensions max@0:
  • max@0:
    max@0:
  • max@0: An identity matrix is generated when n_rows = n_cols max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A(5,5);
      max@0: A.eye();
      max@0: 
      max@0: mat B;
      max@0: B.eye(5,5);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .fill(value) max@0:
    max@0:
  • max@0: Member function of Mat, Col, Row and Cube classes. max@0:
  • max@0:
    max@0:
  • Sets the elements to a specified value. max@0: The type of value must match the type of elements used by the container object max@0: (eg. for mat the type is double) max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A(5,5);
      max@0: A.fill(123.0);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
.in_range( i )
max@0:
(member of Mat, Col, Row, Cube and field) max@0:
.in_range( span(start, end) )
max@0:
(member of Mat, Col, Row, Cube and field) max@0:
max@0:   max@0:
.in_range( row, col )
max@0:
(member of Mat, Col, Row and field) max@0:
.in_range( span(start_row, end_row), span(start_col, end_col) )
max@0:
(member of Mat, Col, Row and field) max@0:
max@0:   max@0:
.in_range( row, col, slice )
max@0:
(member of Cube) max@0:
.in_range( span(start_row, end_row), span(start_col, end_col), span(start_slice, end_slice) )
max@0:
(member of Cube) max@0:
max@0:
max@0:
    max@0:
  • Returns true if the given location or span is currently valid max@0:
  • max@0:
    max@0:
  • Returns false if the object is empty, the location is out of bounds, or the span is out of bounds max@0:
  • max@0:
    max@0:
  • max@0: Instances of span(a,b) can be replaced by: max@0:
      max@0:
    • span() or span::all, to indicate the entire range
    • max@0:
    • span(a), to indicate a particular row, column or slice
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: 
      max@0: cout << A.in_range(0,0) << endl;  // true
      max@0: cout << A.in_range(3,4) << endl;  // true
      max@0: cout << A.in_range(4,5) << endl;  // false
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .is_empty() max@0:
    max@0:
  • max@0: Member function of Mat, Col, Row, Cube and field classes max@0:
  • max@0:
    max@0:
  • Returns true if the object has no elements max@0:
  • max@0:
    max@0:
  • Returns false if the object has one or more elements max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: cout << A.is_empty() << endl;
      max@0: 
      max@0: A.reset();
      max@0: cout << A.is_empty() << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .is_finite() max@0:
    max@0:
  • max@0: Member function of Mat, Col, Row and Cube classes max@0:
  • max@0:
    max@0:
  • Returns true if all elements of the object are finite max@0:
  • max@0:
    max@0:
  • Returns false if at least one of the elements of the object is non-finite (±infinity or NaN) max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = randu<mat>(5,5);
      max@0: 
      max@0: B(1,1) = math::nan()
      max@0: 
      max@0: cout << A.is_finite() << endl;
      max@0: cout << B.is_finite() << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .is_square() max@0:
    max@0:
  • max@0: Member function of the Mat class max@0:
  • max@0:
    max@0:
  • Returns true if the matrix is square, ie., number of rows is equal to the number of columns max@0:
  • max@0:
    max@0:
  • Returns false if the matrix is not square max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = randu<mat>(6,7);
      max@0: 
      max@0: cout << A.is_square() << endl;
      max@0: cout << B.is_square() << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: .is_vec() max@0:
.is_colvec() max@0:
.is_rowvec() max@0:
    max@0:
  • max@0: Member functions of the Mat class max@0:
  • max@0:
    max@0: max@0:
  • .is_vec(): max@0:
      max@0:
    • Returns true if the matrix can be interpreted as a vector (either column or row vector) max@0:
    • max@0:
    • Returns false if the matrix does not have exactly one column or one row max@0:
    • max@0:
    max@0:
  • max@0:
    max@0: max@0:
  • .is_colvec(): max@0:
      max@0:
    • Returns true if the matrix can be interpreted as a column vector max@0:
    • max@0:
    • Returns false if the matrix does not have exactly one column max@0:
    • max@0:
    max@0:
  • max@0:
    max@0: max@0:
  • .is_rowvec(): max@0:
      max@0:
    • Returns true if the matrix can be interpreted as a row vector max@0:
    • max@0:
    • Returns false if the matrix does not have exactly one row max@0:
    • max@0:
    max@0:
  • max@0:
    max@0: max@0:
  • Caveat: do not assume that the vector has elements if these functions return true -- it is possible to have an empty vector (eg. 0x1) max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(1,5);
      max@0: mat B = randu<mat>(5,1);
      max@0: mat C = randu<mat>(5,5);
      max@0: 
      max@0: cout << A.is_vec() << endl;
      max@0: cout << B.is_vec() << endl;
      max@0: cout << C.is_vec() << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
max@0: .insert_rows( row_number, X ) max@0:
max@0: .insert_rows( row_number, number_of_rows, set_to_zero = true ) max@0:

(member functions of Mat and Col) max@0:
 
max@0: .insert_cols( col_number, X ) max@0:
max@0: .insert_cols( col_number, number_of_cols, set_to_zero = true ) max@0:

(member functions of Mat and Row) max@0:
 
max@0: .insert_slices( slice_number, X ) max@0:
max@0: .insert_slices( slice_number, number_of_slices, set_to_zero = true ) max@0:

(member functions of Cube) max@0:
max@0:
max@0:
    max@0:
  • max@0: Functions with the X argument: insert a copy of X at the specified row/column/slice max@0:
      max@0:
    • if inserting rows, X must have the same number of columns as the recipient object
    • max@0:
    • if inserting columns, X must have the same number of rows as the recipient object
    • max@0:
    • if inserting slices, X must have the same number of rows and columns as the recipient object (ie. all slices must have the same size)
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Functions with the number_of_... argument: expand the object by creating new rows/columns/slices. max@0: By default, the new rows/columns/slices are set to zero. max@0: If set_to_zero is false, the memory used by the new rows/columns/slices will not be initialised. max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,10);
      max@0: mat B = ones<mat>(5,2);
      max@0: 
      max@0: // at column 2, insert a copy of B;
      max@0: // A will now have 12 columns
      max@0: A.insert_cols(2, B);
      max@0: 
      max@0: // at column 1, insert 5 zeroed columns;
      max@0: // B will now have 7 columns
      max@0: B.insert_cols(1, 5);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: iterators (matrices & vectors) max@0:
    max@0:
  • max@0: STL-style iterators and associated member functions of the Mat, Col and Row classes max@0:
  • max@0:
    max@0:
  • max@0: iterator types: max@0:
    max@0:
    max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: mat::iterator max@0:
      max@0: vec::iterator max@0:
      max@0: rowvec::iterator max@0:
       
      max@0:
      max@0: random access iterators, for read/write access to elements max@0: (which are stored column by column) max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: mat::const_iterator max@0:
      max@0: vec::const_iterator max@0:
      max@0: rowvec::const_iterator max@0:
       
      max@0:
      max@0: random access iterators, for read-only access to elements max@0: (which are stored column by column) max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: mat::col_iterator max@0:
      max@0: vec::col_iterator max@0:
      max@0: rowvec::col_iterator max@0:
       
      max@0:
      max@0: random access iterators, for read/write access to the elements of a specific column max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: mat::const_col_iterator max@0:
      max@0: vec::const_col_iterator max@0:
      max@0: rowvec::const_col_iterator max@0:
       
      max@0:
      max@0: random access iterators, for read-only access to the elements of a specific column max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: mat::row_iterator max@0:  
      max@0:
      max@0: rudimentary forward iterator, for read/write access to the elements of a specific row max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: mat::const_row_iterator max@0:  
      max@0:
      max@0: rudimentary forward iterator, for read-only access to the elements of a specific row max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: vec::row_iterator max@0:
      max@0: rowvec::row_iterator max@0:
       
      max@0:
      max@0: random access iterators, for read/write access to the elements of a specific row max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: vec::const_row_iterator max@0:
      max@0: rowvec::const_row_iterator max@0:
       
      max@0:
      max@0: random access iterators, for read-only access to the elements of a specific row max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Member functions: max@0:
    max@0:
    max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: .begin() max@0:  
      max@0:
      max@0: iterator referring to the first element max@0:
      max@0: .end() max@0:  
      max@0:
      max@0: iterator referring to the past-the-end element max@0:
      max@0:   max@0:
      max@0: .begin_row(row_number) max@0:  
      max@0:
      max@0: iterator referring to the first element of the specified row max@0:
      max@0: .end_row(row_number) max@0:  
      max@0:
      max@0: iterator referring to the past-the-end element of the specified row max@0:
      max@0:   max@0:
      max@0: .begin_col(col_number) max@0:  
      max@0:
      max@0: iterator referring to the first element of the specified column max@0:
      max@0: .end_col(col_number) max@0:  
      max@0:
      max@0: iterator referring to the past-the-end element of the specified column max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(5,5);
      max@0: 
      max@0: 
      max@0: mat::iterator a = X.begin();
      max@0: mat::iterator b = X.end();
      max@0: 
      max@0: for(mat::iterator i=a; i!=b; ++i)
      max@0:   {
      max@0:   cout << *i << endl;
      max@0:   }
      max@0: 
      max@0: 
      max@0: mat::col_iterator c = X.begin_col(1);  // start of column 1
      max@0: mat::col_iterator d = X.end_col(3);    // end of column 3
      max@0: 
      max@0: for(mat::col_iterator i=c; i!=d; ++i)
      max@0:   {
      max@0:   cout << *i << endl;
      max@0:   (*i) = 123.0;
      max@0:   }
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: iterators (cubes) max@0:
    max@0:
  • max@0: STL-style iterators and associated member functions of the Cube class max@0:
  • max@0:
    max@0:
  • max@0: iterator types: max@0:
    max@0:
    max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: cube::iterator max@0:  
      max@0:
      max@0: random access iterator, for read/write access to elements; max@0: the elements are ordered slice by slice; max@0: the elements within each slice are ordered column by column max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: cube::const_iterator max@0:  
      max@0:
      max@0: random access iterators, for read-only access to elements max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: cube::slice_iterator max@0:  
      max@0:
      max@0: random access iterator, for read/write access to the elements of a particular slice; max@0: the elements are ordered column by column max@0:
      max@0:   max@0:  
      max@0:
      max@0:   max@0:
      max@0: cube::const_slice_iterator max@0:  
      max@0:
      max@0: random access iterators, for read-only access to the elements of a particular slice max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Member functions: max@0:
    max@0:
    max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: .begin() max@0:  
      max@0:
      max@0: iterator referring to the first element max@0:
      max@0: .end() max@0:  
      max@0:
      max@0: iterator referring to the past-the-end element max@0:
      max@0:   max@0:
      max@0: .begin_slice(slice_number) max@0:  
      max@0:
      max@0: iterator referring to the first element of the specified slice max@0:
      max@0: .end_slice(slice_number) max@0:  
      max@0:
      max@0: iterator referring to the past-the-end element of the specified slice max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: cube X = randu<cube>(2,3,4);
      max@0: 
      max@0: 
      max@0: cube::iterator a = X.begin();
      max@0: cube::iterator b = X.end();
      max@0: 
      max@0: for(cube::iterator i=a; i!=b; ++i)
      max@0:   {
      max@0:   cout << *i << endl;
      max@0:   }
      max@0: 
      max@0: 
      max@0: cube::slice_iterator c = X.begin_slice(1);  // start of slice 1
      max@0: cube::slice_iterator d = X.end_slice(2);    // end of slice 2
      max@0: 
      max@0: for(cube::slice_iterator i=c; i!=d; ++i)
      max@0:   {
      max@0:   cout << *i << endl;
      max@0:   (*i) = 123.0;
      max@0:   }
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .memptr() max@0:
    max@0:
  • max@0: Member function of Mat, Col, Row and Cube classes max@0:
  • max@0:
    max@0:
  • max@0: Obtain a raw pointer to the memory used for storing elements. Not recommended for use unless you know what you're doing! max@0:
  • max@0:
    max@0:
  • max@0: The function can be used for interfacing with libraries such as FFTW max@0:
  • max@0:
    max@0:
  • max@0: As soon as the size of the matrix/vector/cube is changed, the pointer is no longer valid max@0:
  • max@0:
    max@0:
  • max@0: Data for matrices is stored in a column-by-column order max@0:
  • max@0:
    max@0:
  • max@0: Data for cubes is stored in a slice-by-slice (matrix-by-matrix) order max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0:       mat A = randu<mat>(5,5);
      max@0: const mat B = randu<mat>(5,5);
      max@0: 
      max@0:       double* A_mem = A.memptr();
      max@0: const double* B_mem = B.memptr();
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
.min()
max@0:
(member functions of Mat, Col, Row, Cube) max@0:
.max()
max@0:
  max@0:
 
max@0:
  max@0:
.min( index_of_min_val )
max@0:
(member functions of Mat, Col, Row, Cube) max@0:
.max( index_of_max_val )
max@0:
  max@0:
 
max@0:
  max@0:
.min( row_of_min_val, col_of_min_val )
max@0:
(member functions of Mat) max@0:
.max( row_of_max_val, col_of_max_val )
max@0:
  max@0:
 
max@0:
  max@0:
.min( row_of_min_val, col_of_min_val, slice_of_min_val )
max@0:
(member functions of Cube) max@0:
.max( row_of_max_val, col_of_max_val, slice_of_max_val )
max@0:
  max@0:
max@0:
    max@0:
    max@0:
  • max@0: Without arguments: return the extremum value of an object max@0:
  • max@0:
    max@0:
  • max@0: With one or more arguments: return the extremum value of an object and store the location of the extremum value in the provided variable(s) max@0:
  • max@0:
    max@0:
  • max@0: The provided variables must be of type uword. max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec v = randu<vec>(10);
      max@0: 
      max@0: cout << "min value is " << v.min() << endl;
      max@0: 
      max@0: 
      max@0: uword  index;
      max@0: double min_val = v.min(index);
      max@0: 
      max@0: cout << "index of min value is " << index << endl;
      max@0: 
      max@0: 
      max@0: mat A = randu<mat>(5,5);
      max@0: 
      max@0: uword  row;
      max@0: uword  col;
      max@0: double min_val2 = A.max(row,col);
      max@0: 
      max@0: cout << "max value is at " << row << ',' << col << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .ones() max@0:
.ones(n_elem) max@0:
.ones(n_rows, n_cols) max@0:
.ones(n_rows, n_cols, n_slices) max@0:
    max@0:
  • max@0: Set the elements of an object to one, optionally first resizing to specified dimensions max@0:
  • max@0:
    max@0:
  • max@0: .ones() and .ones(n_elem) are member functions of Col and Row max@0:
  • max@0:
    max@0:
  • max@0: .ones() and .ones(n_rows, n_cols) are member functions of Mat max@0:
  • max@0:
    max@0:
  • max@0: .ones() and .ones(n_rows, n_cols, n_slices) are member functions of Cube max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,10);
      max@0: A.ones();      // sets all elements to one
      max@0: A.ones(10,20); // sets the size to 10 rows and 20 columns
      max@0:                // followed by setting all elements to one
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: operators:   +   -   *   /   %   ==   !=   <=   >=   <   > max@0:
    max@0:
  • max@0: Overloaded operators for mat, vec, rowvec and cube classes max@0:
  • max@0:
    max@0:
  • max@0: Meanings: max@0:
    max@0:
    max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      +   
      max@0:
      Addition of two objects
      -
      max@0:
      Subtraction of one object from another or negation of an object
      /
      max@0:
      Element-wise division of an object by another object or a scalar
      *
      max@0:
      Matrix multiplication of two objects; not applicable to the cube class unless multiplying a cube by a scalar
      %
      max@0:
      Schur product: element-wise multiplication of two objects
      ==
      max@0:
      Element-wise equality evaluation of two objects; generates a matrix of type umat with entries that indicate whether at a given position the two elements from the two objects are equal (1) or not equal (0)
      !=
      max@0:
      Element-wise non-equality evaluation of two objects
      >=
      max@0:
      As for ==, but the check is for "greater than or equal to"
      <=
      max@0:
      As for ==, but the check is for "less than or equal to"
      >
      max@0:
      As for ==, but the check is for "greater than"
      <
      max@0:
      As for ==, but the check is for "less than"
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: A std::logic_error exception is thrown if incompatible object sizes are used max@0:
  • max@0:
    max@0:
  • max@0: If the +, - and % operators are chained, Armadillo will try to avoid the generation of temporaries; max@0: no temporaries are generated if all given objects are of the same type and size max@0:
  • max@0:
    max@0:
  • max@0: If the * operator is chained, Armadillo will try to find an efficient ordering of the matrix multiplications max@0:
  • max@0:
    max@0:
  • max@0: Caveat: operators involving an equality comparison (ie., ==, !=, >=, <=) max@0: may not work as expected for floating point element types (ie., float, double) max@0: due to the necessarily limited precision of these types; max@0: in other words, these operators are (in general) not recommended for matrices of type mat or fmat max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,10);
      max@0: mat B = randu<mat>(5,10);
      max@0: mat C = randu<mat>(10,5);
      max@0: 
      max@0: mat P = A + B;
      max@0: mat Q = A - B;
      max@0: mat R = -B;
      max@0: mat S = A / 123.0;
      max@0: mat T = A % B;
      max@0: mat U = A * C;
      max@0: 
      max@0: // V is constructed without temporaries
      max@0: mat V = A + B + A + B;
      max@0: 
      max@0: imat AA = "1 2 3; 4 5 6; 7 8 9;";
      max@0: imat BB = "3 2 1; 6 5 4; 9 8 7;";
      max@0: 
      max@0: // compare elements
      max@0: umat ZZ = (AA >= BB);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .print(header="") max@0:
.print(stream, header="") max@0:
    max@0:
  • max@0: Member function of Mat, Col, Row, Cube and field max@0:
  • max@0:
    max@0:
  • max@0: The first form prints the contents of an object to the std::cout stream, with an optional header line max@0:
  • max@0:
    max@0:
  • max@0: The second form prints to a user specified stream max@0:
  • max@0:
    max@0:
  • max@0: It's also possible to print objects using the << stream operator max@0:
  • max@0:
    max@0:
  • max@0: Elements of a field can only be printed if there is an associated operator<< function defined max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = randu<mat>(6,6);
      max@0: 
      max@0: A.print();
      max@0: 
      max@0: // print a transposed version of A
      max@0: A.t().print();
      max@0: 
      max@0: // "B:" is the optional header line
      max@0: B.print("B:");
      max@0: 
      max@0: cout << A << endl;
      max@0: cout << "B:" << endl << B << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .raw_print(header="") max@0:
.raw_print(stream, header="") max@0:
    max@0:
  • max@0: Member function of Mat, Col, Row and Cube max@0:
  • max@0:
    max@0:
  • max@0: Similar to the .print() member function, max@0: with the difference being that no formatting of the output is done -- ie. the user can set the stream's parameters such as precision, cell width, etc. max@0:
  • max@0:
    max@0:
  • max@0: If the cell width is set to zero, a space is printed between the elements max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: 
      max@0: cout.precision(11);
      max@0: cout.setf(ios::fixed);
      max@0: 
      max@0: A.raw_print(cout, "A =");
      max@0: 
      max@0:
    max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: .randu() max@0:
.randu(n_elem) max@0:
.randu(n_rows, n_cols) max@0:
.randu(n_rows, n_cols, n_slices) max@0:
max@0:
max@0: .randn() max@0:
.randn(n_elem) max@0:
.randn(n_rows, n_cols) max@0:
.randn(n_rows, n_cols, n_slices) max@0:
    max@0:
  • max@0: Fill an object with random values, optionally first resizing to specified dimensions max@0:
  • max@0:
    max@0:
  • .randu() uses a uniform distribution in the [0,1] interval max@0:
  • max@0:
    max@0:
  • .randn() uses a normal/Gaussian distribution with zero mean and unit variance max@0:
  • max@0:
    max@0:
  • max@0: To change the seed, use the std::srand() function max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A(4,5);
      max@0: A.randu();
      max@0: 
      max@0: mat B;
      max@0: B.randu(6,7);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: .reset() max@0: max@0:
    max@0:
  • max@0: Member function of Mat, Col, Row, Cube and field max@0:
  • max@0:
    max@0:
  • max@0: Causes an object to have no elements max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5, 5);
      max@0: A.reset();
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
.reshape(n_rows, n_cols, dim=0)
max@0:
(member function of Mat, Col, Row) max@0:
.reshape(n_rows, n_cols, n_slices, dim=0)
max@0:
(member function of Cube) max@0:
max@0:
max@0:
    max@0:
  • max@0: Recreate the object according to given size specifications, max@0: with the elements taken from the previous version of the object, max@0: either column-wise (dim=0) or row-wise (dim=1); max@0: the elements in the generated object are placed column-wise (ie. the first column is filled up before filling the second column) max@0:
  • max@0:
    max@0:
  • max@0: The layout of the elements in the recreated object will be different to the layout in the previous version of the object max@0:
  • max@0:
    max@0:
  • max@0: This function can be used to vectorise a matrix (ie. concatenate all the columns or rows) max@0:
  • max@0:
    max@0:
  • max@0: The new total number of elements (according to the specified size) doesn't have to be the same as the previous total number of elements in the object max@0:
  • max@0:
    max@0:
  • max@0: If the total number of elements in the previous version of the object is less than the specified size, max@0: the extra elements in the recreated object are set to zero max@0:
  • max@0:
    max@0:
  • max@0: If the total number of elements in the previous version of the object is greater than the specified size, max@0: only a subset of the elements is taken max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: .reshape() is slower than .set_size(), which doesn't preserve data max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: if you wish to grow/shrink the object while preserving the elements as well as the layout of the elements, max@0: use .resize() instead max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: A.reshape(5,4);
      max@0: 
      max@0: // vectorise A into a column vector:
      max@0: A.reshape(A.n_elem, 1);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
.resize(n_elem)
max@0:
(member function of Col, Row) max@0:
.resize(n_rows, n_cols)
max@0:
(member function of Mat) max@0:
.resize(n_rows, n_cols, n_slices)
max@0:
(member function of Cube) max@0:
max@0:
max@0:
    max@0:
  • max@0: Recreate the object according to given size specifications, while preserving the elements as well as the layout of the elements max@0:
  • max@0:
    max@0:
  • max@0: Can be used for growing or shrinking an object (ie. adding/removing rows, and/or columns, and/or slices) max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: .resize() is slower than .set_size(), which doesn't preserve data max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: A.resize(7,6);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: This function was added in version 2.4.1 max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: .save(name, file_type = arma_binary) max@0:
max@0: .save(stream, file_type = arma_binary) max@0:
max@0:
max@0: .load(name, file_type = auto_detect) max@0:
max@0: .load(stream, file_type = auto_detect) max@0:
max@0:
max@0: .quiet_save(name, file_type = arma_binary) max@0:
max@0: .quiet_save(stream, file_type = arma_binary) max@0:
max@0:
max@0: .quiet_load(name, file_type = auto_detect) max@0:
max@0: .quiet_load(stream, file_type = auto_detect) max@0:
max@0:
    max@0:
  • Member functions of Mat, Col, Row and Cube classes
  • max@0:
    max@0:
  • Store/retrieve data in files or streams
  • max@0:
    max@0:
  • On success, save(), load(), quiet_save(), and quite_load() will return a bool set to true
  • max@0:
    max@0:
  • save() and quiet_save() will return a bool set to false if the saving process fails
  • max@0:
    max@0:
  • max@0: load() and quiet_load() will return a bool set to false if the loading process fails; max@0: additionally, the object will be reset so it has no elements max@0:
  • max@0:
    max@0:
  • load() and save() will print warning messages if any problems are encountered
  • max@0:
    max@0:
  • quiet_load() and quiet_save() do not print any error messages
  • max@0:
    max@0:
  • max@0: The following file formats are supported: max@0:
    max@0:
    max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      auto_detect
      max@0:
      max@0: for load() and quiet_load(): max@0: try to automatically detect the file type as one of the formats described below. max@0: This is the default operation. max@0:
      max@0:
      max@0:
      raw_ascii
      max@0:
      max@0: Numerical data stored in raw ASCII format, without a header. max@0: The numbers are separated by whitespace. max@0: The number of columns must be the same in each row. max@0: Data which was saved in Matlab/Octave using the -ascii option can be read in Armadillo, except for complex numbers. max@0: Complex numbers are stored in standard C++ notation (a tuple surrounded by brackets: eg. (1.23,4.56) indicates 1.24 + 4.56i). max@0: Cubes are loaded as one slice. max@0:
      max@0:
      max@0:
      raw_binary
      max@0:
      max@0: Numerical data stored in machine dependent raw binary format, without a header. max@0: Matrices are loaded to have one column, max@0: while cubes are loaded to have one slice with one column. max@0: The .reshape() function can be used to alter the size of the loaded matrix/cube without losing data. max@0:
      max@0:
      max@0:
      arma_ascii
      max@0:
      max@0: Numerical data stored in human readable text format, with a simple header to speed up loading. max@0: The header indicates the type of matrix as well as the number of rows and columns. max@0: For cubes, the header additionally specifies the number of slices. max@0:
      max@0:
      max@0:
      arma_binary
      max@0:
      max@0: Numerical data stored in machine dependent binary format, with a simple header to speed up loading. max@0: The header indicates the type of matrix as well as the number of rows and columns. max@0: For cubes, the header additionally specifies the number of slices. max@0:
      max@0:
      max@0:
      csv_ascii
      max@0:
      max@0: Numerical data stored in comma separated value (CSV) text format, without a header. max@0: Applicable to Mat only. max@0:
      max@0:
      max@0:
      pgm_binary
      max@0:
      max@0: Image data stored in Portable Gray Map (PGM) format. max@0: Applicable to Mat only. max@0: Saving int, float or double matrices is a lossy operation, as each element is copied and converted to an 8 bit representation. max@0: As such the matrix should have values in the [0,255] interval, otherwise the resulting image may not display correctly. max@0:
      max@0:
      max@0:
      ppm_binary
      max@0:
      max@0: Image data stored in Portable Pixel Map (PPM) format. max@0: Applicable to Cube only. max@0: Saving int, float or double matrices is a lossy operation, as each element is copied and converted to an 8 bit representation. max@0: As such the cube/field should have values in the [0,255] interval, otherwise the resulting image may not display correctly. max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: 
      max@0: A.save("A1.mat");  // default save format is arma_binary
      max@0: A.save("A2.mat", arma_ascii);
      max@0: 
      max@0: mat B;
      max@0: // automatically detect format type
      max@0: B.load("A1.mat");
      max@0: 
      max@0: mat C;
      max@0: // force loading in the arma_ascii format
      max@0: C.load("A2.mat", arma_ascii);
      max@0: 
      max@0: 
      max@0: // example of saving/loading using a stream
      max@0: std::stringstream s;
      max@0: A.save(s);
      max@0: 
      max@0: mat D;
      max@0: D.load(s);
      max@0: 
      max@0: 
      max@0: // example of testing for success
      max@0: mat E;
      max@0: bool status = E.load("A2.mat");
      max@0: 
      max@0: if(status == true)
      max@0:   {
      max@0:   cout << "loaded okay" << endl;
      max@0:   }
      max@0: else
      max@0:   {
      max@0:   cout << "problem with loading" << endl;
      max@0:   }
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: .save(name, file_type = arma_binary) max@0:
max@0: .save(stream, file_type = arma_binary) max@0:
max@0:
max@0: .load(name, file_type = auto_detect) max@0:
max@0: .load(stream, file_type = auto_detect) max@0:
max@0:
max@0: .quiet_save(name, file_type = arma_binary) max@0:
max@0: .quiet_save(stream, file_type = arma_binary) max@0:
max@0:
max@0: .quiet_load(name, file_type = auto_detect) max@0:
max@0: .quiet_load(stream, file_type = auto_detect) max@0:
max@0:
    max@0:
  • Member functions of the field class
  • max@0:
    max@0:
  • Store/retrieve fields in files or stream
  • max@0:
    max@0:
  • On success, save(), load(), quiet_save(), and quite_load() will return a bool set to true
  • max@0:
    max@0:
  • save() and quiet_save() will return a bool set to false if the saving process fails
  • max@0:
    max@0:
  • max@0: load() and quiet_load() will return a bool set to false if the loading process fails; max@0: additionally, the field will be reset so it has no elements max@0:
  • max@0:
    max@0:
  • load() and save() will print warning messages if any problems are encountered
  • max@0:
    max@0:
  • quiet_load() and quiet_save() do not print any error messages
  • max@0:
    max@0:
  • max@0: Fields with objects of type std::string are saved and loaded as raw text files. max@0: The text files do not have a header. max@0: Each string is separated by a whitespace. max@0: load() and quiet_load() will only accept text files that have the same number of strings on each line. max@0: The strings can have variable lengths. max@0:
  • max@0:
    max@0:
  • max@0: Other than storing string fields as text files, the following file formats are supported: max@0:
    max@0:
    max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      auto_detect
      max@0:
      max@0:
      max@0:
    • max@0: load(): try to automatically detect the field format type as one of the formats described below. max@0: This is the default operation. max@0:
    • max@0:
      max@0:
      arma_binary
      max@0:
      max@0:
      max@0:
    • max@0: Objects are stored in machine dependent binary format. max@0:
    • max@0: Default type for fields of type Mat, Col or Row. max@0:
    • max@0:
    • max@0: Only applicable to fields of type Mat, Col or Row. max@0:
    • max@0:
      max@0:
      ppm_binary
      max@0:
      max@0:
      max@0:
    • max@0: Image data stored in Portable Pixmap Map (PPM) format. max@0:
    • max@0:
    • max@0: Only applicable to fields of type Mat, Col or Row. max@0:
    • max@0:
    • max@0: .load(): Loads the specified image and stores the red, green and blue components as three separate matrices. max@0: The resulting field is comprised of the three matrices, max@0: with the red, green and blue components in the first, second and third matrix, respectively. max@0:
    • max@0:
    • max@0: .save(): Saves a field with exactly three matrices of equal size as an image. max@0: It is assumed that the red, green and blue components are stored in the first, second and third matrix, respectively. max@0: Saving int, float or double matrices is a lossy operation, max@0: as each matrix element is copied and converted to an 8 bit representation. max@0:
    • max@0: max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .set_imag(X) max@0:
max@0: .set_real(X) max@0:
max@0:
    max@0:
  • Member functions of Mat, Col, Row and Cube
  • max@0:
    max@0:
  • max@0: Set the imaginary/real part of an object max@0:
  • max@0:
    max@0:
  • max@0: X must have the same size as the recipient object max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0:    mat A = randu<mat>(4,5);
      max@0:    mat B = randu<mat>(4,5);
      max@0: 
      max@0: cx_mat C = zeros<mat>(4,5);
      max@0: 
      max@0: C.set_real(A);
      max@0: C.set_imag(B);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: if you want to directly construct a complex matrix out of two real matrices, max@0: the following code is faster: max@0:
      max@0:
      max@0:    mat A = randu<mat>(4,5);
      max@0:    mat B = randu<mat>(4,5);
      max@0: 
      max@0: cx_mat C = cx_mat(A,B);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
.set_size(n_elem)
max@0:
(member function of Col, Row, and field) max@0:
.set_size(n_rows, n_cols)
max@0:
(member function of Mat and field) max@0:
.set_size(n_rows, n_cols, n_slices)
max@0:
(member function of Cube) max@0:
max@0:
max@0:
    max@0:
  • Changes the size of an object
  • max@0:
    max@0:
  • max@0: If the requested number of elements is equal to the old number of elements, existing memory is reused max@0:
  • max@0:
    max@0:
  • max@0: If the requested number of elements is not equal to the old number of elements, new memory is used max@0:
  • max@0:
    max@0:
  • max@0: If you need to explicitly preserve data, use .reshape() or .resize() max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A;
      max@0: A.set_size(5,10);
      max@0: 
      max@0: vec q;
      max@0: q.set_size(100);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
max@0: .shed_row( row_number ) max@0:
max@0: .shed_rows( first_row, last_row ) max@0:

(member functions of Mat and Col) max@0:
 
max@0: .shed_col( column_number ) max@0:
max@0: .shed_cols( first_column, last_column ) max@0:

(member functions of Mat and Row) max@0:
 
max@0: .shed_slice( slice_number ) max@0:
max@0: .shed_slices( first_slice, last_slice ) max@0:

(member functions of Cube) max@0:
max@0:
max@0:
    max@0:
  • max@0: Single argument functions: max@0: remove the specified row/column/slice max@0:
  • max@0:
    max@0:
  • max@0: Two argument functions: max@0: remove the specified range of rows/columns/slices max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,10);
      max@0: 
      max@0: A.shed_row(2);
      max@0: A.shed_cols(2,4);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: STL container functions max@0:
    max@0:
  • Mat, Col and Row classes provide the following member functions that mimic the containers in the C++ Standard Template Library:
    max@0:
    max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
    max@0: .clear() max@0:  
    max@0:
    max@0: causes an object to have no elements max@0:
    max@0:   max@0:  
    max@0:
    max@0:   max@0:
    max@0: .empty() max@0:  
    max@0:
    max@0: returns true if the object has no elements; returns false if the object has one or more elements max@0:
    max@0:   max@0:  
    max@0:
    max@0:   max@0:
    max@0: .size() max@0:  
    max@0:
    max@0: returns the total number of elements max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: cout << A.size() << endl;
      max@0: 
      max@0: A.clear();
      max@0: cout << A.empty() << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: submatrix views max@0:
    max@0:
  • A collection of member functions of Mat, Col and Row classes that provide submatrix views
    max@0:
    max@0:
  • For a matrix or vector X, the subviews are accessed as:
  • max@0:
    max@0:
      max@0: X.col( col_number )
      max@0: X( span::all, col_number )
      max@0: X( span(first_row, last_row), col_number )
      max@0:
      max@0: X.unsafe_col( col_number )
      max@0:
      max@0: X.row( row_number )
      max@0: X( row_number, span::all )
      max@0: X( row_number, span(first_col, last_col) )
      max@0:
      max@0: X.cols( first_col, last_col )
      max@0: X.rows( first_row, last_row )
      max@0:
      max@0: X.submat( first_row, first_col, last_row, last_col )
      max@0: X.submat( span(first_row, last_row), span(first_col, last_col) )
      max@0:
      max@0: X( span(first_row, last_row), span(first_col, last_col) )
      max@0:
      max@0: X.elem( vector_of_indices ) max@0:
    max@0: max@0:
    max@0:
  • For a vector V (column or row vector), there is an additional method:
  • max@0: max@0:
    max@0:
      max@0: V.subvec( first_index, last_index )
      max@0: max@0:
    max@0:
    max@0:
  • max@0: Instances of span::all, to indicate an entire range, can be replaced by span(), where no number is specified max@0:
  • max@0:
    max@0:
  • max@0: In the function X.elem(vector_of_indices), max@0: elements specified in vector_of_indices are accessed. max@0: X is interpreted as one long vector, max@0: with column-by-column ordering of the elements of X. max@0: The vector_of_indices must evaluate to be a vector of type uvec max@0: (eg., generated by find()). max@0: The aggregate set of the specified elements is treated as a column vector max@0: (eg., the output of X.elem() is always a column vector). max@0:
  • max@0:
    max@0:
  • max@0: The function .unsafe_col() is provided for speed reasons and should be used only if you know what you're doing. max@0: The function creates a seemingly independent Col vector object (eg. vec), max@0: but the vector actually uses memory from the existing matrix object. max@0: As such, the created Col vector is currently not alias safe max@0: and does not take into account that the parent matrix object could be deleted. max@0: If deleted memory is accessed through the created Col vector, max@0: it will cause memory corruption and/or a crash. max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = zeros<mat>(5,10);
      max@0: 
      max@0: A.submat(0,1,2,3) = randu<mat>(3,3);
      max@0: 
      max@0: // the following three statements
      max@0: // access the same part of A
      max@0: mat B = A.submat(0,1,2,3);
      max@0: mat C = A.submat( span(0,2), span(1,3) );
      max@0: mat D = A( span(0,2), span(1,3) );
      max@0: 
      max@0: // the following two statements
      max@0: // access the same part of A
      max@0: A.col(1)        = randu<mat>(5,1);
      max@0: A(span::all, 1) = randu<mat>(5,1);
      max@0: 
      max@0: mat X = randu<mat>(5,5);
      max@0: 
      max@0: // get all elements of X that are greater than 0.5
      max@0: vec q = X.elem( find(X > 0.5) );
      max@0: 
      max@0: // set four specific elements of X to 1
      max@0: uvec indices;
      max@0: indices << 2 << 3 << 6 << 8;
      max@0: 
      max@0: X.elem(indices) = ones<vec>(4);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: subcube views and slices max@0:
    max@0:
  • A collection of member functions of the Cube class that provide subcube views
    max@0:
    max@0:
  • For a cube Q, the subviews are accessed as:
  • max@0:
    max@0:
      max@0: Q.slice( slice_number )
      max@0: Q.slices( first_slice, last_slice )
      max@0:
      max@0: Q.subcube( first_row, first_col, first_slice, last_row, last_col, last_slice )
      max@0: Q.subcube( span(first_row, last_row), span(first_col, last_col), span(first_slice, last_slice) )
      max@0:
      max@0: Q( span(first_row, last_row), span(first_col, last_col), span(first_slice, last_slice) )
      max@0:
    max@0: max@0:
    max@0:
  • max@0: Instances of span(a,b) can be replaced by: max@0:
      max@0:
    • span() or span::all, to indicate the entire range
    • max@0:
    • span(a), to indicate a particular row, column or slice
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: An individual slice, accessed via .slice(), is an instance of the Mat class max@0: (a reference to a matrix is provided) max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: cube A = randu<cube>(2,3,4);
      max@0: mat B = A.slice(1);
      max@0: 
      max@0: A.slice(0) = randu<mat>(2,3);
      max@0: A.slice(0)(1,2) = 99.0;
      max@0: 
      max@0: A.subcube(0,0,1,  1,1,2) = randu<cube>(2,2,2);
      max@0: A( span(0,1), span(0,1), span(1,2) ) = randu<cube>(2,2,2);
      max@0: 
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: subfield views max@0:
    max@0:
  • A collection of member functions of the field class that provide subfield views
    max@0:
    max@0:
  • For a field F, the subfields are accessed as:
  • max@0:
    max@0:
      max@0: F.row( row_number )
      max@0: F.col( col_number )
      max@0:
      max@0: F.rows( first_row, last_row )
      max@0: F.cols( first_col, last_col )
      max@0:
      max@0: F.subfield( first_row, first_col, last_row, last_col )
      max@0: F.subfield( span(first_row, last_row), span(first_col, last_col) )
      max@0:
      max@0: F( span(first_row, last_row), span(first_col, last_col) )
      max@0:
    max@0: max@0:
    max@0:
  • max@0: Instances of span(a,b) can be replaced by: max@0:
      max@0:
    • span() or span::all, to indicate the entire range
    • max@0:
    • span(a), to indicate a particular row or column
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: .swap_rows(row1, row2) max@0:
.swap_cols(col1, col2) max@0:
max@0:
    max@0:
  • max@0: Member functions of Mat, Col and Row classes max@0:
  • max@0:
    max@0:
  • max@0: Swap the contents of specified rows or columns max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(5,5);
      max@0: X.swap_rows(0,4);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: .t() max@0:
.st() max@0:
max@0:
    max@0:
  • max@0: Member functions of any expression involving matrices or vectors max@0:
  • max@0:
    max@0:
  • max@0: .t() provides a transposed copy of the object; if a given object has complex elements, a Hermitian transpose is done (ie. the conjugate of the elements is taken during the transpose operation) max@0:
  • max@0:
    max@0:
  • max@0: .st() provides a transposed copy of the object, without taking the conjugate of the elements (complex matrices) max@0:
  • max@0:
    max@0:
  • max@0: For non-complex objects, the .t() and .st() functions are equivalent max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: mat B = A.t();
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: The .t() and .st() functions were added in version 2.4 max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: .zeros() max@0:
.zeros(n_elem) max@0:
.zeros(n_rows, n_cols) max@0:
.zeros(n_rows, n_cols, n_slices) max@0:
    max@0:
  • max@0: Set the elements of an object to zero, optionally first resizing to specified dimensions max@0:
  • max@0:
    max@0:
  • max@0: .zeros() and .zeros(n_elem) are member function of Col and Row max@0:
  • max@0:
    max@0:
  • max@0: .zeros() and .zeros(n_rows, n_cols) are member functions of Mat max@0:
  • max@0:
    max@0:
  • max@0: .zeros() and .zeros(n_rows, n_cols, n_slices) are member functions of Cube max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,10);
      max@0: A.zeros();      // sets all elements to zero
      max@0: A.zeros(10,20); // sets the size to 10 rows and 20 columns
      max@0:                 // followed by setting all elements to zero
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0: max@0: max@0:
max@0:
max@0:
max@0: Other Classes max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: running_stat<type> max@0:
    max@0:
  • max@0: Class for keeping statistics of a continuously sampled one dimensional process/signal. max@0: Useful if the storage of individual samples (scalars) is not necessary or desired. max@0: Also useful if the number of samples is not known beforehand or exceeds available memory. max@0:
  • max@0:
    max@0:
  • max@0: type should be one of: float, double, cx_float, cx_double max@0:
  • max@0:
    max@0:
  • max@0: Member functions: max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: .operator()(scalar) max@0:  
      max@0:
      max@0: update the statistics so far using the given scalar max@0:
      max@0: .mean() max@0:  
      max@0:
      max@0: get the mean or average value so far max@0:
      max@0: .var(norm_type=0) max@0:  
      max@0:
      max@0: get the variance so far max@0:
      max@0: .stddev(norm_type=0) max@0:  
      max@0:
      max@0: get the standard deviation so far max@0:
      max@0: .min() max@0:  
      max@0:
      max@0: get the minimum value so far max@0:
      max@0: .max() max@0:  
      max@0:
      max@0: get the maximum value so far max@0:
      max@0: .reset() max@0:  
      max@0:
      max@0: reset all statistics and set the number of samples to zero max@0:
      max@0: .count() max@0:  
      max@0:
      max@0: get the number of samples so far max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: For the .var() and .stddev() functions, the default norm_type=0 performs normalisation using N-1 max@0: (where N is the number of samples so far), max@0: providing the best unbiased estimator. max@0: Using norm_type=1 causes normalisation to be done using N, which provides the second moment around the mean. max@0:
  • max@0:
    max@0:
  • max@0: The return type of .count() depends on the underlying form of type: it is either float or double. max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: running_stat<double> stats;
      max@0: 
      max@0: for(uword i=0; i<10000; ++i)
      max@0:   {
      max@0:   double sample = double(rand())/RAND_MAX;
      max@0:   stats(sample);
      max@0:   }
      max@0: 
      max@0: cout << "mean = " << stats.mean() << endl;
      max@0: cout << "var  = " << stats.var()  << endl;
      max@0: cout << "min  = " << stats.min()  << endl;
      max@0: cout << "max  = " << stats.max()  << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: running_stat_vec<type>(calc_cov = false) max@0:
    max@0:
  • max@0: Class for keeping statistics of a continuously sampled multi-dimensional process/signal. max@0: Useful if the storage of individual samples is not necessary or desired. max@0: Also useful if the number of samples is not known beforehand or exceeds available memory. max@0:
  • max@0:
    max@0:
  • max@0: This class is similar to running_stat, with the difference being that vectors are processed instead of single values. max@0:
  • max@0:
    max@0:
  • max@0: type must match the element type used by the sample vectors max@0: (ie. it must be one of float, double, cx_float, cx_double) max@0:
  • max@0:
    max@0:
  • max@0: type can be inferred via the use of the elem_type member typedef of a vector class. max@0: For example, fvec::elem_type will be interpreted as float, max@0: while cx_vec::elem_type will be interpreted as cx_double. max@0:
  • max@0:
    max@0:
  • max@0: Member functions: max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: .operator()(vector) max@0:  
      max@0:
      max@0: update the statistics so far using the given vector max@0:
      max@0: .mean() max@0:  
      max@0:
      max@0: get the mean vector so far max@0:
      max@0: .var(norm_type=0) max@0:  
      max@0:
      max@0: get the vector of variances so far max@0:
      max@0: .stddev(norm_type=0) max@0:  
      max@0:
      max@0: get the vector of standard deviations so far max@0:
      max@0: .min() max@0:  
      max@0:
      max@0: get the vector of minimum values so far max@0:
      max@0: .max() max@0:  
      max@0:
      max@0: get the vector of maximum values so far max@0:
      max@0: .cov(norm_type=0) max@0:  
      max@0:
      max@0: get the covariance matrix so far max@0:
      NOTE: this only works if calc_cov is set to true during the construction of the class max@0:
      max@0: .reset() max@0:  
      max@0:
      max@0: reset all statistics and set the number of samples to zero max@0:
      max@0: .count() max@0:  
      max@0:
      max@0: get the number of samples so far max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: For the .var() and .stddev() functions, the default norm_type=0 performs normalisation using N-1 max@0: (where N is the number of samples so far), max@0: providing the best unbiased estimator. max@0: Using norm_type=1 causes normalisation to be done using N, which provides the second moment around the mean. max@0:
  • max@0:
    max@0:
  • max@0: The return type of .count() depends on the underlying form of type: it is either float or double. max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: running_stat_vec<rowvec::elem_type> stats;
      max@0: 
      max@0: rowvec sample;
      max@0: 
      max@0: for(uword i=0; i<10000; ++i)
      max@0:   {
      max@0:   sample = randu<rowvec>(5);
      max@0:   stats(sample);
      max@0:   }
      max@0: 
      max@0: cout << "mean = " << stats.mean() << endl;
      max@0: cout << "var  = " << stats.var()  << endl;
      max@0: cout << "min  = " << stats.min()  << endl;
      max@0: cout << "max  = " << stats.max()  << endl;
      max@0: 
      max@0: //
      max@0: //
      max@0: 
      max@0: running_stat_vec<rowvec::elem_type> more_stats(true);
      max@0: 
      max@0: for(uword i=0; i<20; ++i)
      max@0:   {
      max@0:   sample = randu<rowvec>(3);
      max@0:   
      max@0:   sample(1) -= sample(0);
      max@0:   sample(2) += sample(1);
      max@0:   
      max@0:   more_stats(sample);
      max@0:   }
      max@0: 
      max@0: cout << "covariance matrix = " << endl;
      max@0: cout << more_stats.cov() << endl;
      max@0: 
      max@0: rowvec sd = more_stats.stddev();
      max@0: 
      max@0: cout << "correlations = " << endl;
      max@0: cout << more_stats.cov() / (trans(sd) * sd);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: wall_clock max@0:
    max@0:
  • max@0: Simple wall clock timer class, for measuring the number of elapsed seconds between two intervals max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: wall_clock timer;
      max@0: 
      max@0: mat A = randu<mat>(4,4);
      max@0: mat B = randu<mat>(4,4);
      max@0: mat C;
      max@0: 
      max@0: timer.tic();
      max@0: for(uword i=0; i<100000; ++i)
      max@0:   C = A + B + A + B;
      max@0: 
      max@0: double n_secs = timer.toc();
      max@0: cout << "took " << n_secs << " seconds" << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
max@0:
max@0:
max@0: max@0:
max@0:
max@0:
max@0: Generated Vectors/Matrices max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: eye(n_rows, n_cols) max@0:
    max@0:
  • max@0: Generate a matrix with the elements along the main diagonal set to one max@0: and off-diagonal elements set to zero max@0:
  • max@0:
    max@0:
  • max@0: An identity matrix is generated when n_rows = n_cols max@0:
  • max@0:
    max@0:
  • max@0: Usage: max@0:
      max@0:
    • max@0: matrix_type X = eye<matrix_type>(n_rows, n_cols) max@0:
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = eye<mat>(5,5);
      max@0: mat B = 123.0 * eye<mat>(5,5);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: linspace(start, end, N=100) max@0:
    max@0:
  • max@0: Generate a vector with N elements; max@0: the values of the elements linearly increase from start upto (and including) end max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Usage: max@0:
      max@0:
    • vector_type v = linspace<vector_type>(start, end, N)
    • max@0:
    • matrix_type X = linspace<matrix_type>(start, end, N)
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: If a matrix_type is specified, the resultant matrix will have one column max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec v = linspace<vec>(10, 20, 5);
      max@0: mat X = linspace<mat>(10, 20, 5);
      max@0: 
      max@0:
    max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: ones(n_elem) max@0:
ones(n_rows, n_cols) max@0:
ones(n_rows, n_cols, n_slices) max@0:
max@0:
    max@0:
  • max@0: Generate a vector, matrix or cube with all elements set to one max@0:
  • max@0:
    max@0:
  • max@0: Usage: max@0:
      max@0:
    • vector_type v = ones<vector_type>(n_elem)
    • max@0:
    • matrix_type X = ones<matrix_type>(n_rows, n_cols)
    • max@0:
    • cube_type Q = ones<cube_type>(n_rows, n_cols, n_slices)
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec  v = ones<vec>(10);
      max@0: mat  A = ones<mat>(5,6);
      max@0: cube Q = ones<cube>(5,6,7);
      max@0: 
      max@0: mat  B = 123.0 * ones<mat>(5,6);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0:
      max@0:
    • .ones() (member function of Mat, Col, Row and Cube)
    • max@0:
    • eye()
    • max@0:
    max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: randu(n_elem) max@0:
randu(n_rows, n_cols) max@0:
randu(n_rows, n_cols, n_slices) max@0:
max@0:
randn(n_elem) max@0:
randn(n_rows, n_cols) max@0:
randn(n_rows, n_cols, n_slices) max@0:
    max@0:
  • max@0: Generate a vector, matrix or cube with the elements set to random values max@0:
  • max@0:
    max@0:
  • randu() uses a uniform distribution in the [0,1] interval max@0:
  • max@0:
    max@0:
  • randn() uses a normal/Gaussian distribution with zero mean and unit variance max@0:
  • max@0:
    max@0:
  • max@0: Usage: max@0:
      max@0:
    • vector_type v = randu<vector_type>(n_elem)
    • max@0:
    • matrix_type X = randu<matrix_type>(n_rows, n_cols)
    • max@0:
    • cube_type Q = randu<cube_type>(n_rows, n_cols, n_slices)
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: To change the seed, use the std::srand() function. max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec  v = randu<vec>(5);
      max@0: mat  A = randu<mat>(5,6);
      max@0: cube Q = randu<cube>(5,6,7);
      max@0: 
      max@0:
    max@0:
  • max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: repmat(A, num_copies_per_row, num_copies_per_col) max@0:
    max@0:
  • Generate a matrix by replicating matrix A in a block-like fashion
  • max@0:
    max@0:
  • The generated matrix has the following size: max@0:
      max@0: rows = num_copies_per_row * A.n_rows max@0:
      max@0: cols = num_copies_per_col * A.n_cols max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(2, 3);
      max@0: 
      max@0: mat B = repmat(A, 4, 5);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: max@0: toeplitz(A) max@0:
toeplitz(A,B) max@0:
circ_toeplitz(A) max@0:
    max@0:
  • max@0: toeplitz(): generate a Toeplitz matrix, with the first column specified by A, and (optionally) the first row specified by B max@0:
  • max@0:
    max@0:
  • max@0: circ_toeplitz(): generate a circulant Toeplitz matrix max@0:
  • max@0:
    max@0:
  • max@0: A and B must be vectors max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec A = randu<vec>(5);
      max@0: mat X = toeplitz(A);
      max@0: mat Y = circ_toeplitz(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: max@0: zeros(n_elem) max@0:
zeros(n_rows, n_cols) max@0:
zeros(n_rows, n_cols, n_slices) max@0:
    max@0:
  • max@0: Generate a vector, matrix or cube with the elements set to zero max@0:
  • max@0:
    max@0:
  • max@0: Usage: max@0:
      max@0:
    • vector_type v = zeros<vector_type>(n_elem)
    • max@0:
    • matrix_type X = zeros<matrix_type>(n_rows, n_cols)
    • max@0:
    • cube_type X = zeros<cube_type>(n_rows, n_cols, n_slices)
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec  v = zeros<vec>(5);
      max@0: mat  A = zeros<mat>(5,6);
      max@0: cube Q = zeros<cube>(5,6,7);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0:
      max@0:
    • .zeros() (member function of Mat, Col, Row and Cube)
    • max@0:
    • .ones() (member function of Mat, Col, Row and Cube)
    • max@0:
    • ones()
    • max@0:
    max@0:
  • max@0:
max@0:
max@0:
max@0: max@0:
max@0:
max@0:
max@0: Functions Individually Applied to Each Element of a Matrix/Cube max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: abs(mat) max@0:
abs(cube) max@0:
abs(cx_mat) max@0:
abs(cx_cube) max@0:
    max@0:
  • max@0: Obtain the magnitude of each element max@0:
  • max@0:
    max@0:
  • max@0: Usage for non-complex matrices: max@0:
      max@0:
    • matrix_type Y = abs(X)
    • max@0:
    • X and Y must have the same matrix_type
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Usage for non-complex cubes: max@0:
      max@0:
    • cube_type Y = abs(X)
    • max@0:
    • X and Y must have the same cube_type
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Usage for complex matrices: max@0:
      max@0:
    • non_complex_matrix_type Y = abs(X)
    • max@0:
    • X must be a have complex matrix type, eg., cx_mat or cx_fmat
    • max@0:
    • The type of Y must be related to the type of X, max@0: eg., if X has the type cx_mat, then the type of Y must be mat max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Usage for complex cubes: max@0:
      max@0:
    • non_complex_cube_type Y = abs(X)
    • max@0:
    • X must be a have complex cube type, eg., cx_cube or cx_fcube
    • max@0:
    • The type of Y must be related to the type of X, max@0: eg., if X has the type cx_cube, then the type of Y must be cube max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = abs(A); 
      max@0: 
      max@0: cx_mat X = randu<cx_mat>(5,5);
      max@0: mat    Y = abs(X);
      max@0: 
      max@0:
    max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: eps(X) max@0:
    max@0:
  • max@0: Obtain the positive distance of the absolute value of each element of X to the next largest representable floating point number max@0:
  • max@0:
    max@0:
  • max@0: X can be a scalar (eg. double), vector or matrix max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: mat B = eps(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: miscellaneous functions: max@0:
  exp, exp2, exp10, trunc_exp, max@0:
  log, log2, log10, trunc_log, max@0:
  pow, sqrt, square max@0:
  floor, ceil max@0:
max@0:
max@0:
    max@0:
  • max@0: Apply a function to each element max@0:
  • max@0:
    max@0:
  • max@0: Usage: max@0:
      max@0:
    • max@0: matrix_type B = misc_fn(A) max@0:
    • max@0:
    • max@0: cube_type B = misc_fn(A) max@0:
    • max@0:
    • max@0: A and B must have the same matrix_type/cube_type max@0:
    • max@0:
    • max@0: misc_fn(A) is one of: max@0:
        max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
        max@0: exp(A)  max@0: max@0:   max@0: max@0: base-e exponential, ex max@0:
        max@0: exp2(A)  max@0: max@0:   max@0: max@0: base-2 exponential, 2x max@0:
        max@0: exp10(A)  max@0: max@0:   max@0: max@0: base-10 exponential, 10x max@0:
        max@0: trunc_exp(A) max@0: max@0:   max@0: max@0: base-e exponential, max@0: truncated to avoid infinity max@0:
        max@0: (only for elements with type float or double) max@0:
        max@0: log(A)  max@0: max@0:   max@0: max@0: natural log, loge x max@0:
        max@0: log2(A)  max@0: max@0:   max@0: max@0: base-2 log, log2 x max@0:
        max@0: log10(A)  max@0: max@0:   max@0: max@0: base-10 log, log10 x max@0:
        max@0: trunc_log(A) max@0: max@0:   max@0: max@0: natural log, max@0: truncated to avoid ±infinity max@0:
        max@0: (only for elements with type float or double) max@0:
        max@0: pow(A, p)  max@0: max@0:   max@0: max@0: raise to the power of p, xp max@0:
        max@0: sqrt(A)  max@0: max@0:   max@0: max@0: square root, x½ max@0:
        max@0: square(A)  max@0: max@0:   max@0: max@0: square, x2 max@0:
        max@0: floor(A) max@0: max@0:   max@0: max@0: largest integral value that is not greater than the input value max@0:
        max@0: ceil(A) max@0: max@0:   max@0: max@0: smallest integral value that is not less than the input value max@0:
        max@0: max@0: max@0:
      max@0:
    • max@0: max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = exp(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: trigonometric functions (cos, sin, tan, ...) max@0:
    max@0:
  • max@0: Apply a trigonometric function to each element max@0:
  • max@0:
    max@0:
  • max@0: Usage: max@0:
      max@0:
    • max@0: matrix_type Y = trig_fn(X) max@0:
    • max@0:
    • max@0: cube_type Y = trig_fn(X) max@0:
    • max@0:
    • max@0: X and Y must have the same matrix_type/cube_type max@0:
    • max@0:
    • max@0: trig_fn is one of: max@0:
        max@0:
      • max@0: cos family: cos, acos, cosh, acosh max@0:
      • max@0:
      • max@0: sin family: sin, asin, sinh, asinh max@0:
      • max@0:
      • max@0: tan family: tan, atan, tanh, atanh max@0:
      • max@0:
      max@0:
    • max@0: max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(5,5);
      max@0: mat Y = cos(X);
      max@0: 
      max@0:
    max@0:
  • max@0:
max@0:
max@0:
max@0: max@0:
max@0:
max@0:
max@0: Scalar Valued Functions of Vectors/Matrices/Cubes max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: accu(mat) max@0:
accu(cube) max@0:
    max@0:
  • max@0: Accumulate (sum) all elements max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: double x = accu(A);
      max@0: 
      max@0: mat B = randu<mat>(5,5);
      max@0: double y = accu(A % B);
      max@0: 
      max@0: // operator % performs element-wise multiplication,
      max@0: // hence accu(A % B) is a "multiply-and-accumulate"
      max@0: // operation
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: as_scalar(expression) max@0:
    max@0:
  • max@0: Evaluate an expression that results in a 1x1 matrix, max@0: followed by converting the 1x1 matrix to a pure scalar max@0:
  • max@0:
    max@0:
  • max@0: If a binary or trinary expression is given (ie. 2 or 3 terms), max@0: the function will try to exploit the fact that the result is a 1x1 matrix max@0: by using optimised expression evaluations max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: rowvec r = randu<rowvec>(5);
      max@0: colvec q = randu<colvec>(5);
      max@0: mat    X = randu<mat>(5,5);
      max@0: 
      max@0: // examples of some expressions
      max@0: // for which optimised implementations exist
      max@0: 
      max@0: double a = as_scalar(r*q);
      max@0: double b = as_scalar(r*X*q);
      max@0: double c = as_scalar(r*diagmat(X)*q);
      max@0: double d = as_scalar(r*inv(diagmat(X))*q);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: det(A, slow = false) max@0:
    max@0:
  • max@0: Determinant of square matrix A max@0:
  • max@0:
    max@0:
  • max@0: If A is not square, a std::logic_error exception is thrown max@0:
  • max@0:
    max@0:
  • max@0: Caveat: for large matrices you may want to use log_det() instead max@0:
  • max@0:
    max@0:
  • max@0: For matrix sizes ≤ 4x4, a fast algorithm is used by default. max@0: In rare instances, the fast algorithm might be less precise than the standard algorithm. max@0: To force the use of the standard algorithm, set the slow argument to true max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat    A = randu<mat>(5,5);
      max@0: double x = det(A);
      max@0: 
      max@0: mat44  B = randu<mat>(4,4);
      max@0: 
      max@0: double y = det(B);       // use fast algorithm by default
      max@0: double z = det(B, true); // use slow algorithm
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: dot(A, B) max@0:
cdot(A, B) max@0:
norm_dot(A, B) max@0:
    max@0:
  • max@0: dot(A,B): dot product of A and B, under the assumption that A and B are vectors with the same number of elements max@0:
  • max@0:
    max@0:
  • max@0: cdot(A,B): as per dot(A,B), but the complex conjugate of A is used max@0:
  • max@0:
    max@0:
  • max@0: norm_dot(A,B): normalised version of dot(A,B) max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec a = randu<vec>(10);
      max@0: vec b = randu<vec>(10);
      max@0: 
      max@0: double x = dot(a,b);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: log_det(val, sign, A) max@0:
    max@0:
  • max@0: Log determinant of square matrix A, such that the determinant is equal to exp(val)*sign max@0:
  • max@0:
    max@0:
  • max@0: If A is not square, a std::logic_error exception is thrown max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: 
      max@0: double val;
      max@0: double sign;
      max@0: 
      max@0: log_det(val, sign, A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: norm(X, p) max@0: max@0:
    max@0:
  • max@0: Compute the p-norm of X, where X can be a vector or a matrix max@0:
  • max@0:
    max@0:
  • max@0: For vectors, p is an integer ≥1, or one of: "-inf", "inf", "fro" max@0:
  • max@0:
    max@0:
  • max@0: For matrices, p is one of: 1, 2, "inf", "fro" max@0:
  • max@0:
    max@0:
  • max@0: "-inf" is the minimum norm, "inf" is the maximum norm, while "fro" is the Frobenius norm max@0:
  • max@0:
    max@0:
  • max@0: To obtain the zero norm or Hamming norm (ie. the number of non-zero elements), max@0: you may want to use this expression: accu(X != 0). max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec    q = randu<vec>(5);
      max@0: double x = norm(q, 2);
      max@0: double y = norm(q, "inf");
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: rank(X, tolerance = default) max@0: max@0:
    max@0:
  • Returns the rank of matrix X

  • max@0:
  • Any singular values less than default tolerance are treated as zero

  • max@0:
  • The default tolerance is max(X.n_rows, X.n_cols)*eps(sigma), max@0: where sigma is the largest singular value of X max@0:

  • max@0:
  • The computation is based on singular value decomposition; max@0: if the decomposition fails, a std::runtime_error exception is thrown

  • max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: uword r = rank(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: trace(mat) max@0:
    max@0:
  • max@0: Sum of the diagonal elements of a square matrix max@0:
  • max@0:
    max@0:
  • max@0: A std::logic_error exception is thrown if the given matrix is not square max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: double x = trace(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0: max@0:
max@0:
max@0:
max@0: Scalar/Vector Valued Functions of Vectors/Matrices max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: diagvec(A, k=0) max@0:
    max@0:
  • max@0: Extract the k-th diagonal from matrix A max@0:
  • max@0:
    max@0:
  • max@0: The argument k is optional -- by default the main diagonal is extracted (k=0) max@0:
  • max@0:
    max@0:
  • For k > 0, the k-th super-diagonal is extracted (top-right corner)
  • max@0:
    max@0:
  • For k < 0, the k-th sub-diagonal is extracted (bottom-left corner)
  • max@0:
    max@0:
  • max@0: An extracted a diagonal is interpreted as a column vector max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: vec d = diagvec(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: max@0: min(mat, dim=0) max@0:
min(rowvec) max@0:
min(colvec) max@0:
max@0:
max(mat, dim=0) max@0:
max(rowvec) max@0:
max(colvec) max@0:
    max@0:
  • max@0: For a matrix argument, return the extremum value for each column (dim=0), or each row (dim=1) max@0:
  • max@0:
    max@0:
  • max@0: For a vector argument, return the extremum value max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: colvec q = randu<colvec>(10,1);
      max@0: double x = max(q);
      max@0: 
      max@0: mat    A = randu<mat>(10,10);
      max@0: rowvec b = max(A);
      max@0: 
      max@0: // same result as max(A)
      max@0: // the 0 explicitly indicates
      max@0: // "traverse across rows"
      max@0: rowvec c = max(A,0); 
      max@0: 
      max@0: // the 1 explicitly indicates
      max@0: // "traverse across columns"
      max@0: colvec d = max(A,1);
      max@0: 
      max@0: // find the overall maximum value
      max@0: double y = max(max(A));
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: prod(mat, dim=0) max@0:
prod(rowvec) max@0:
prod(colvec) max@0:
    max@0:
  • max@0: For a matrix argument, return the product of elements in each column (dim=0), or each row (dim=1) max@0:
  • max@0:
    max@0:
  • max@0: For a vector argument, return the product of all elements max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: colvec q = randu<colvec>(10,1);
      max@0: double x = prod(q);
      max@0: 
      max@0: mat    A = randu<mat>(10,10);
      max@0: rowvec b = prod(A);
      max@0: 
      max@0: // same result as prod(A)
      max@0: // the 0 explicitly indicates
      max@0: // "traverse across rows"
      max@0: rowvec c = prod(A,0);
      max@0: 
      max@0: // the 1 explicitly indicates
      max@0: // "traverse across columns"
      max@0: colvec d = prod(A,1);
      max@0: 
      max@0: // find the overall product
      max@0: double y = prod(prod(A));
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: sum(mat, dim=0) max@0:
sum(rowvec) max@0:
sum(colvec) max@0:
    max@0:
  • max@0: For a matrix argument, return the sum of elements in each column (dim=0), or each row (dim=1) max@0:
  • max@0:
    max@0:
  • max@0: For a vector argument, return the sum of all elements max@0:
  • max@0:
    max@0:
  • max@0: To get a sum of all the elements regardless of the argument type (ie. matrix or vector), max@0: you may wish to use accu() instead max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: colvec q = randu<colvec>(10,1);
      max@0: double x = sum(q);
      max@0: 
      max@0: mat    A = randu<mat>(10,10);
      max@0: rowvec b = sum(A);
      max@0: 
      max@0: // same result as sum(A)
      max@0: // the 0 explicitly indicates
      max@0: // "traverse across rows"
      max@0: rowvec c = sum(A,0);
      max@0: 
      max@0: // the 1 explicitly indicates
      max@0: // "traverse across columns"
      max@0: colvec d = sum(A,1);
      max@0: 
      max@0: // find the overall sum
      max@0: double y = sum(sum(A));
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: statistics: mean, median, stddev, var max@0: max@0:
    max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
    max@0: mean(mat, dim=0) max@0:
    mean(colvec) max@0:
    mean(rowvec) max@0:
    max@0:
    max@0:
    max@0:   max@0: max@0: mean (average value) max@0:
    max@0: median(mat, dim=0) max@0:
    median(colvec) max@0:
    median(rowvec) max@0:
    max@0:
    max@0:
    max@0:   max@0: max@0: median max@0:
    max@0: stddev(mat, norm_type=0, dim=0) max@0:
    stddev(colvec, norm_type=0) max@0:
    stddev(rowvec, norm_type=0) max@0:
    max@0:
    max@0:
    max@0:   max@0: max@0: standard deviation max@0:
    max@0: var(mat, norm_type=0, dim=0) max@0:
    var(colvec, norm_type=0) max@0:
    var(rowvec, norm_type=0) max@0:
    max@0:
    max@0:
    max@0:   max@0: max@0: variance max@0:
    max@0:
    max@0:
  • max@0: For a matrix argument, find a particular statistic for each column (dim=0), or each row (dim=1) max@0:
  • max@0:
    max@0:
  • max@0: For a vector argument, return a particular statistic calculated using all the elements of the vector max@0:
  • max@0:
    max@0:
  • max@0: For the var() and stddev() functions, the default norm_type=0 performs normalisation using N-1 (where N is the number of samples), max@0: providing the best unbiased estimator. max@0: Using norm_type=1 causes normalisation to be done using N, which provides the second moment around the mean max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A    = randu<mat>(5,5);
      max@0: mat B    = mean(A);
      max@0: mat C    = var(A);
      max@0: double m = mean(mean(A));
      max@0: 
      max@0: vec    q = randu<vec>(5);
      max@0: double v = var(q);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:
max@0: max@0:
max@0:
max@0:
max@0: Vector/Matrix/Cube Valued Functions of Vectors/Matrices/Cubes max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: max@0: C = conv(A, B) max@0: max@0:
    max@0:
  • max@0: Convolution of vectors A and B. max@0:
  • max@0:
    max@0:
  • max@0: If A and B are polynomial coefficient vectors, convolving them is equivalent to multiplying the two polynomials max@0:
  • max@0:
    max@0:
  • max@0: The convolution operation is also equivalent to FIR filtering max@0:
  • max@0:
    max@0:
  • max@0: The orientation of the result vector is the same as the orientation of A (ie. column or row vector) max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec A = randu<vec>(128) - 0.5;
      max@0: vec B = randu<vec>(128) - 0.5;
      max@0: 
      max@0: vec C = conv(A,B);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: conv_to<type>::from(X) max@0: max@0:
    max@0:
  • max@0: A form of casting max@0:
  • max@0:
    max@0:
  • max@0: Convert between matrix/vector types (eg. mat to fmat), as well as cube types (eg. cube to fcube) max@0:
  • max@0:
    max@0:
  • max@0: Conversion between std::vector and Armadillo matrices/vectors is also possible max@0:
  • max@0:
    max@0:
  • max@0: Conversion of a mat object into colvec, rowvec or std::vector is possible if the object can be interpreted as a vector max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat  A = randu<mat>(5,5);
      max@0: fmat B = conv_to<fmat>::from(A);
      max@0: 
      max@0: typedef std::vector<double> stdvec;
      max@0: 
      max@0: stdvec x(3);
      max@0: x[0] = 0.0; x[1] = 1.0;  x[2] = 2.0;
      max@0: 
      max@0: colvec y = conv_to< colvec >::from(x);
      max@0: stdvec z = conv_to< stdvec >::from(y); 
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: conj(cx_mat) max@0:
conj(cx_cube) max@0:
    max@0:
  • max@0: Obtain the complex conjugate of each element in a complex matrix/cube max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: cx_mat X = randu<cx_mat>(5,5);
      max@0: cx_mat Y = conj(X);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: cor(X, Y, norm_type=0) max@0:
cor(X, norm_type=0) max@0:
    max@0:
  • max@0: For two matrix arguments X and Y, max@0: if each row of X and Y is an observation and each column is a variable, max@0: the (i,j)-th entry of cor(X,Y) is the correlation coefficient between the i-th variable in X and the j-th variable in Y max@0:
  • max@0:
    max@0:
  • max@0: For vector arguments, the type of vector is ignored and each element in the vector is treated as an observation max@0:
  • max@0:
    max@0:
  • max@0: For matrices, X and Y must have the same dimensions max@0:
  • max@0:
    max@0:
  • max@0: For vectors, X and Y must have the same number of elements max@0:
  • max@0:
    max@0:
  • max@0: cor(X) is equivalent to cor(X, X), also called autocorrelation max@0:
  • max@0:
    max@0:
  • max@0: The default norm_type=0 performs normalisation of the correlation matrix using N-1 (where N is the number of observations). max@0: Using norm_type=1 causes normalisation to be done using N max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(4,5);
      max@0: mat Y = randu<mat>(4,5);
      max@0: 
      max@0: mat R = cor(X,Y);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: cov(X, Y, norm_type=0) max@0:
cov(X, norm_type=0) max@0:
    max@0:
  • max@0: For two matrix arguments X and Y, max@0: if each row of X and Y is an observation and each column is a variable, max@0: the (i,j)-th entry of cov(X,Y) is the covariance between the i-th variable in X and the j-th variable in Y max@0:
  • max@0:
    max@0:
  • max@0: For vector arguments, the type of vector is ignored and each element in the vector is treated as an observation max@0:
  • max@0:
    max@0:
  • max@0: For matrices, X and Y must have the same dimensions max@0:
  • max@0:
    max@0:
  • max@0: For vectors, X and Y must have the same number of elements max@0:
  • max@0:
    max@0:
  • max@0: cov(X) is equivalent to cov(X, X) max@0:
  • max@0:
    max@0:
  • max@0: The default norm_type=0 performs normalisation using N-1 (where N is the number of observations), max@0: providing the best unbiased estimation of the covariance matrix (if the observations are from a normal distribution). max@0: Using norm_type=1 causes normalisation to be done using N, which provides the second moment matrix of the observations about their mean max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(4,5);
      max@0: mat Y = randu<mat>(4,5);
      max@0: 
      max@0: mat C = cov(X,Y);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: cross(A, B) max@0:
    max@0:
  • max@0: Calculate the cross product between A and B, under the assumption that A and B are 3 dimensional vectors max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec a = randu<vec>(3);
      max@0: vec b = randu<vec>(3);
      max@0: 
      max@0: vec c = cross(a,b);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: cumsum(mat, dim=0) max@0:
cumsum(rowvec) max@0:
cumsum(colvec) max@0:
    max@0:
  • max@0: For a matrix argument, return a matrix containing the cumulative sum of elements in each column (dim=0, the default), or each row (dim=1) max@0:
  • max@0:
    max@0:
  • max@0: For a vector argument, return a vector of the same orientation, containing the cumulative sum of elements max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = cumsum(A);
      max@0: 
      max@0: vec x = randu<vec>(10);
      max@0: vec y = cumsum(x);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: diagmat(mat) max@0:
diagmat(rowvec) max@0:
diagmat(colvec) max@0:
    max@0:
  • max@0: Interpret a matrix or vector as a diagonal matrix max@0:
  • max@0:
    max@0:
  • max@0: For mat, given matrix must be square; the main diagonal is copied and all other elements in the generated matrix are set to zero max@0:
  • max@0:
    max@0:
  • max@0: For colvec and rowvec, elements of the vector are placed on the main diagonal in the generated matrix and all other elements are set to zero max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = diagmat(A);
      max@0: mat C = A*diagmat(A);
      max@0: 
      max@0: rowvec q = randu<rowvec>(5);
      max@0: colvec r = randu<colvec>(5);
      max@0: mat    X = diagmat(q)*diagmat(r);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: max@0: find(X, k=0, s="first") max@0:
    max@0:
  • Return a column vector of the indices of non-zero elements of X
  • max@0:
    max@0:
  • The output vector must have the type uvec or umat max@0: (ie. the indices are stored as unsigned integers of type uword) max@0:
  • max@0:
    max@0:
  • max@0: The input matrix X is interpreted as a vector, with column-by-column ordering of the elements of X max@0:
  • max@0:
    max@0:
  • Relational operators can be used instead of X, eg. A > 0.5 max@0:
  • max@0:
    max@0:
  • If k=0 (default), return the indices of all non-zero elements, otherwise return at most k of their indices
  • max@0:
    max@0:
  • If s="first" (default), return at most the first k indices of the non-zero elements max@0:
  • max@0:
    max@0:
  • If s="last", return at most the last k indices of the non-zero elements max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat  A  = randu<mat>(5,5);
      max@0: mat  B  = randu<mat>(5,5);
      max@0: 
      max@0: uvec q1 = find(A > B);
      max@0: uvec q2 = find(A > 0.5);
      max@0: uvec q3 = find(A > 0.5, 3, "last");
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: max@0: fliplr(mat) max@0:
flipud(mat) max@0:
    max@0:
  • max@0: fliplr(): generate a copy of the input matrix, with the order of the columns reversed max@0:
  • max@0:
    max@0:
  • max@0: flipud(): generate a copy of the input matrix, with the order of the rows reversed max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: 
      max@0: mat B = fliplr(A);
      max@0: mat C = flipud(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: imag(cx_mat) max@0:
imag(cx_cube) max@0:
max@0:
real(cx_mat) max@0:
real(cx_cube) max@0:
    max@0:
  • max@0: Extract the imaginary/real part of a complex matrix/cube max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: cx_mat C = randu<cx_mat>(5,5);
      max@0: 
      max@0: mat    A = imag(C);
      max@0: mat    B = real(C);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • Caveat: versions 4.4, 4.5 and 4.6 of the GCC C++ compiler have a bug when using the -std=c++0x compiler option (ie. experimental support for C++11); max@0: to work around this bug, preface Armadillo's imag() and real() with the arma namespace qualification, eg. arma::imag(C) max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: join_rows(mat A, mat B) max@0:
join_cols(mat A, mat B) max@0:
join_slices(cube A, cube B) max@0:
    max@0:
  • max@0: join_rows(): max@0: for two matrices A and B, append each row of B to its respective row of A; max@0: matrices A and B must have the same number of rows max@0:
  • max@0:
    max@0:
  • max@0: join_cols(): max@0: for two matrices A and B, append each column of B to its respective column of A; max@0: matrices A and B must have the same number of columns max@0:
  • max@0:
    max@0:
  • max@0: join_slices(): max@0: for two cubes A and B, append the slices of B to the slices of A; max@0: cubes A and B have the same number of rows and columns (ie. all slices must have the same size) max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: mat B = randu<mat>(4,6);
      max@0: mat C = randu<mat>(6,5);
      max@0: 
      max@0: mat X = join_rows(A,B);
      max@0: mat Y = join_cols(A,C);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: kron(A,B) max@0: max@0:
    max@0:
  • Kronecker tensor product.
  • max@0:
    max@0:
  • Using matrix A (with n rows and p columns) and matrix B (with m rows and q columns), max@0: kron(A,B) returns a matrix (with nm rows and pq columns) which denotes the tensor product of A and B max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: mat B = randu<mat>(5,4);
      max@0: 
      max@0: mat K = kron(A,B);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: reshape(mat, n_rows, n_cols, dim=0) max@0:
reshape(cube, n_rows, n_cols, n_slices, dim=0) max@0:
    max@0:
  • max@0: Generate a matrix/cube sized according to given size specifications, max@0: whose elements are taken from the given matrix/cube, either column-wise (dim=0) or row-wise (dim=1); max@0: the elements in the generated object are placed column-wise (ie. the first column is filled up before filling the second column) max@0:
  • max@0:
    max@0:
  • max@0: The layout of the elements in the generated object will be different to the layout in the given object max@0:
  • max@0:
    max@0:
  • max@0: This function can be used to create a vector representation of a matrix (ie. concatenate all the columns or rows) max@0:
  • max@0:
    max@0:
  • max@0: The total number of elements in the generated matrix/cube doesn't have to be the same as the total number of elements in the given matrix/cube max@0:
  • max@0:
    max@0:
  • max@0: If the total number of elements in the given matrix/cube is less than the specified size, max@0: the remaining elements in the generated matrix/cube are set to zero max@0:
  • max@0:
    max@0:
  • max@0: If the total number of elements in the given matrix/cube is greater than the specified size, max@0: only a subset of elements is taken from the given matrix/cube max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: reshape() is slower than .set_size(), which doesn't preserve data max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: if you wish to grow/shrink a matrix while preserving the elements as well as the layout of the elements, max@0: use resize() instead max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(10, 5);
      max@0: mat B = reshape(A, 5, 10);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: resize(mat, n_rows, n_cols) max@0:
resize(cube, n_rows, n_cols, n_slices) max@0:
    max@0:
  • max@0: Generate a matrix/cube sized according to given size specifications, max@0: whose elements as well as the layout of the elements are taken from the given matrix/cube max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: resize() is slower than .set_size(), which doesn't preserve data max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4, 5);
      max@0: mat B = resize(A, 7, 6);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: This function was added in version 2.4.1 max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: shuffle(mat, dim=0) max@0:
shuffle(rowvec, dim=0) max@0:
shuffle(colvec, dim=0) max@0:
    max@0:
  • max@0: Shuffle the rows (dim=0) or columns (dim=1) of a matrix or vector max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: mat B = shuffle(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: sort(mat, sort_type=0, dim=0) max@0:
sort(rowvec, sort_type=0) max@0:
sort(colvec, sort_type=0) max@0:
    max@0:
  • For a matrix argument, return a matrix with the elements of the input matrix sorted in each column (dim=0), or each row (dim=1)
  • max@0:
    max@0:
  • sort_type=0 (default) indicates an ascending sort
  • max@0:
    max@0:
  • sort_type=1 indicates a descending sort
  • max@0:
    max@0:
  • For a vector argument, return a vector which is a sorted version of the input vector
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(10,10);
      max@0: mat B = sort(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: sort_index(colvec, sort_type=0) max@0:
sort_index(rowvec, sort_type=0) max@0:
    max@0:
  • Return a vector which describes the sorted order of the given vector's elements max@0: (ie. it contains the indices of the given vector's elements) max@0:
  • max@0:
    max@0:
  • The output vector must have the type uvec or umat max@0: (ie. the indices are stored as unsigned integers of type uword) max@0:
  • max@0:
    max@0:
  • sort_type=0 (default) indicates an ascending sort
  • max@0:
    max@0:
  • sort_type=1 indicates a descending sort
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: vec  q       = randu<vec>(10);
      max@0: uvec indices = sort_index(q);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: symmatu(A) max@0:
symmatl(A) max@0:
    max@0:
  • max@0: symmatu(A): interpret square matrix A as symmetric, reflecting the upper triangle to the lower triangle max@0:
  • max@0:
    max@0:
  • max@0: symmatl(A): interpret square matrix A as symmetric, reflecting the lower triangle to the upper triangle max@0:
  • max@0:
    max@0:
  • max@0: If A is non-square, a std::logic_error exception is thrown max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: 
      max@0: mat B = symmatu(A);
      max@0: mat C = symmatl(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: strans(mat) max@0:
strans(colvec) max@0:
strans(rowvec) max@0:
    max@0:
  • max@0: Simple matrix transpose, without taking the conjugate of the elements (complex matrices) max@0:
  • max@0:
    max@0:
  • max@0: Use trans() instead, unless you explicitly need to take the transpose of a complex matrix without taking the conjugate of the elements max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: trans(mat) max@0:
trans(colvec) max@0:
trans(rowvec) max@0:
    max@0:
  • max@0: Matrix transpose / Hermitian transpose max@0:
  • max@0:
    max@0:
  • max@0: If a given object has real elements, a normal transpose is done max@0:
  • max@0:
    max@0:
  • max@0: If a given object has complex elements, a Hermitian transpose is done (ie. the conjugate of the elements is taken during the transpose operation) max@0:
  • max@0:
    max@0:
  • max@0: Caveat: for complex matrices, the functionality of trans() has changed in version 2.0: max@0:
      max@0:
    • in version 1.2.x and earlier, trans() does not take the conjugate of complex elements
    • max@0:
    • in version 1.2.x and earlier, the deprecated htrans() function is used for the Hermitian transpose
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      mat A = randu<mat>(5,10);
      max@0: mat B = trans(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: trimatu(A) max@0:
trimatl(A) max@0:
    max@0:
  • max@0: trimatu(A): interpret square matrix A as upper triangular max@0:
  • max@0:
    max@0:
  • max@0: trimatl(A): interpret square matrix A as lower triangular max@0:
  • max@0:
    max@0:
  • max@0: A std::logic_error exception is thrown if A is non-square max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      mat A = randu<mat>(5,5);
      max@0: mat U = trimatu(A);
      max@0: mat L = trimatl(A);
      max@0: 
      max@0: // tell the inv() function to look only
      max@0: // at the upper triangular part
      max@0: mat X = inv( trimatu(U) );
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
max@0:
max@0:
max@0: max@0: max@0:
max@0:
max@0:
max@0: Decompositions, Inverses and Equation Solvers max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: R = chol(X) max@0:
chol(R, X) max@0:
    max@0:
  • max@0: Cholesky decomposition of X, such that trans(R)*R = X max@0:
  • max@0:
    max@0:
  • max@0: X must be a symmetric, positive-definite matrix max@0:
  • max@0:
    max@0:
  • If the decomposition fails, R is reset and: max@0:
      max@0:
    • chol(X) throws a std::runtime_error exception
    • max@0:
    • chol(R,X) returns a bool set to false
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(5,5);
      max@0: mat Y = trans(X)*X;
      max@0: 
      max@0: mat R = chol(Y);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: vec eigval = eig_sym(mat X) max@0:
vec eigval = eig_sym(cx_mat X) max@0:
max@0:
eig_sym(vec eigval, mat X) max@0:
eig_sym(vec eigval, cx_mat X) max@0:
max@0:
eig_sym(vec eigval, mat eigvec, mat X) max@0:
eig_sym(vec eigval, cx_mat eigvec, cx_mat X) max@0:
    max@0:
  • max@0: Eigen decomposition of symmetric/hermitian matrix X
  • max@0:
    max@0:
  • The eigenvalues and corresponding eigenvectors are stored in eigval and eigvec, respectively
  • max@0:
    max@0:
  • max@0: The eigenvalues are in ascending order max@0:
  • max@0:
    max@0:
  • If X is not square, a std::logic_error exception is thrown
  • max@0:
    max@0:
  • If the decomposition fails, the output objects are reset and: max@0:
      max@0:
    • eig_sym(X) throws a std::runtime_error exception
    • max@0:
    • eig_sym(eigval, X) and eig_sym(eigval, eigvec, X) return a bool set to false
    • max@0:
    max@0:
  • max@0:
    max@0:
  • There is currently no check whether X is symmetric
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(10,10);
      max@0: mat B = trans(A)*A;  // generate a symmetric matrix
      max@0: 
      max@0: vec eigval;
      max@0: mat eigvec;
      max@0: 
      max@0: eig_sym(eigval, eigvec, B);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: eig_gen(cx_vec eigval, cx_mat eigvec, mat X, side='r') max@0:
max@0: eig_gen(cx_vec eigval, cx_mat eigvec, cx_mat X, side='r') max@0:
max@0:
max@0: eig_gen(cx_vec eigval, mat l_eigvec, mat r_eigvec, mat X) max@0:
max@0: eig_gen(cx_vec eigval, cx_mat l_eigvec, cx_mat r_eigvec, cx_mat X) max@0:
    max@0:
  • max@0: Eigen decomposition of general (non-symmetric/non-hermitian) square matrix X
  • max@0:
    max@0:
  • The eigenvalues and corresponding eigenvectors are stored in eigval and eigvec, respectively
  • max@0:
    max@0:
  • max@0: For the first two forms, side='r' (default) specifies that right eigenvectors are computed, max@0: while side='l' specifies that left eigenvectors are computed max@0:
  • max@0:
    max@0:
  • For the last two forms, both left and right eigenvectors are computed
  • max@0:
    max@0:
  • max@0: The eigenvalues are not guaranteed to be ordered max@0:
  • max@0:
    max@0:
  • If X is not square, a std::logic_error exception is thrown
  • max@0:
    max@0:
  • If the decomposition fails, the output objects are reset and eig_gen() returns a bool set to false
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(10,10);
      max@0: 
      max@0: cx_vec eigval;
      max@0: cx_mat eigvec;
      max@0: 
      max@0: eig_gen(eigval, eigvec, A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: B = inv(A, slow = false) max@0:
max@0: inv(B, A, slow = false) max@0:
    max@0:
  • max@0: Inverse of square matrix A max@0:
  • max@0:
    max@0:
  • max@0: If A is known to be a triangular matrix, max@0: the inverse can be computed faster by explicitly marking the matrix as triangular max@0: through trimatu() or trimatl() max@0:
  • max@0:
    max@0:
  • max@0: If A is known to be a positive-definite symmetric matrix, max@0: the inverse can be computed faster by explicitly marking the matrix using sympd() max@0:
  • max@0:
    max@0:
  • max@0: If A is not square, a std::logic_error exception is thrown max@0:
  • max@0:
    max@0:
  • If A appears to be singular, B is reset and: max@0:
      max@0:
    • inv(A) throws a std::runtime_error exception
    • max@0:
    • inv(B,A) returns a bool set to false
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: If you want to solve a system of linear equations, eg., X = inv(A)*B, max@0: the solve() function is generally more efficient max@0:
  • max@0:
    max@0:
  • max@0: For matrix sizes ≤ 4x4, a fast inverse algorithm is used by default. max@0: In rare instances, the fast algorithm might be less precise than the standard algorithm. max@0: To force the use of the standard algorithm, set the slow argument to true max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = inv(A);
      max@0: 
      max@0: 
      max@0: // Diagonal elements in C are set to the
      max@0: // reciprocal of the corresponding elements in A.
      max@0: // Off-diagonal elements in C are set to zero.
      max@0: mat C = inv( diagmat(A) );
      max@0: 
      max@0: 
      max@0: // tell inv() to look only at the upper triangular part of A
      max@0: mat D = inv( trimatu(A) );
      max@0: 
      max@0: 
      max@0: // tell inv() that AA is a symmetric positive definite matrix
      max@0: mat AA = A*trans(A);
      max@0: mat E  = inv( sympd(AA) );
      max@0: 
      max@0: 
      max@0: mat44 F = randu<mat>(4,4);
      max@0: 
      max@0: mat G = inv(F);       // use fast algorithm by default
      max@0: mat H = inv(F, true); // use slow algorithm
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: max@0: max@0: lu(mat L, mat U, mat P, mat X) max@0:
max@0: lu(mat L, mat U, mat X) max@0:
    max@0:
  • max@0: Lower-upper decomposition (with partial pivoting) of matrix X max@0:
  • max@0:
    max@0:
  • max@0: The first form provides max@0: a lower-triangular matrix L, max@0: an upper-triangular matrix U, max@0: and a permutation matrix P, max@0: such that trans(P)*L*U = X max@0:
  • max@0:
    max@0:
  • max@0: The second form provides permuted L and U, such that L*U = X. max@0: Note that in this case L is generally not lower-triangular max@0:
  • max@0:
    max@0:
  • max@0: If the decomposition fails, the output objects are reset and lu() returns a bool set to false max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: 
      max@0: mat L, U, P;
      max@0: 
      max@0: lu(L, U, P, A);
      max@0: 
      max@0: mat B = trans(P)*L*U;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: B = pinv(A, tolerance = default) max@0:
pinv(B, A, tolerance = default) max@0:
    max@0:
  • Moore-Penrose pseudo-inverse of matrix A
  • max@0:
    max@0:
  • The computation is based on singular value decomposition; max@0: if the decomposition fails, B is reset and: max@0:
      max@0:
    • pinv(A) throws a std::runtime_error exception
    • max@0:
    • pinv(B,A) returns a bool set to false
    • max@0:
    max@0:
    max@0:
  • Any singular values less than tol are treated as zero
  • max@0:
    max@0:
  • For matrix A with m rows and n columns, max@0: the default tolerance is max(m,n)*norm(A)*math::eps(), max@0: where math::eps() denotes the difference between 1 and the least value greater than 1 that is representable
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(4,5);
      max@0: mat B = pinv(A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: mat coeff = princomp(mat X) max@0:
cx_mat coeff = princomp(cx_mat X)
max@0: max@0:
princomp(mat coeff, mat X) max@0:
princomp(cx_mat coeff, cx_mat X)
max@0: max@0:
princomp(mat coeff, mat score, mat X) max@0:
princomp(cx_mat coeff, cx_mat score, cx_mat X)
max@0: max@0:
princomp(mat coeff, mat score, vec latent, mat X) max@0:
princomp(cx_mat coeff, cx_mat score, vec latent, cx_mat X)
max@0: max@0:
princomp(mat coeff, mat score, vec latent, vec tsquared, mat X) max@0:
princomp(cx_mat coeff, cx_mat score, vec latent, cx_vec tsquared, cx_mat X)
max@0:
max@0:
    max@0:
  • Principal component analysis of matrix X

  • max@0:
  • Each row of X is an observation and each column is a variable

  • max@0:
  • output objects: max@0:
      max@0:
    • coeff: principal component coefficients
    • max@0:
    • score: projected data
    • max@0:
    • latent: eigenvalues of the covariance matrix of X
    • max@0:
    • tsquared: Hotteling's statistic for each sample
    • max@0:
    max@0:
  • max@0:
    max@0:
  • The computation is based on singular value decomposition; max@0: if the decomposition fails, the output objects are reset and: max@0:
      max@0:
    • princomp(X) throws a std::runtime_error exception
    • max@0:
    • remaining forms of princomp() return a bool set to false
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,4);
      max@0: 
      max@0: mat coeff;
      max@0: mat score;
      max@0: vec latent;
      max@0: vec tsquared;
      max@0: 
      max@0: princomp(coeff, score, latent, tsquared, A);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: qr(Q,R,X) max@0:
    max@0:
  • max@0: Decomposition of matrix X into an orthogonal (Q) and a right triangular matrix (R), such that Q*R = X max@0:
  • max@0:
    max@0:
  • max@0: If the decomposition fails, Q and R are reset and the function returns a bool set to false max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(5,5);
      max@0: mat Q, R;
      max@0: 
      max@0: qr(Q,R,X);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: X = solve(A, B, slow = false) max@0:
solve(X, A, B, slow = false) max@0:
    max@0:
  • Solve a system of linear equations, ie., A*X = B, where X is unknown
  • max@0:
    max@0:
  • For a square matrix A, this function is conceptually the same as X = inv(A)*B, but is more efficient
  • max@0:
    max@0:
  • Similar functionality to the "\" (left division operator) operator in Matlab/Octave, ie. X = A \ B
  • max@0:
    max@0:
  • The number of rows in A and B must be the same
  • max@0:
    max@0:
  • max@0: If A is known to be a triangular matrix, max@0: the solution can be computed faster by explicitly marking the matrix as triangular max@0: through trimatu() or trimatl() max@0:
  • max@0:
    max@0:
  • max@0: If A is non-square (and hence also non-triangular), max@0: solve() will also try to provide approximate solutions to under-determined as well as over-determined systems
  • max@0:
    max@0:
  • max@0: If no solution is found, X is reset and: max@0:
      max@0:
    • solve(A,B) throws a std::runtime_error exception
    • max@0:
    • solve(X,A,B) returns a bool set to false
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: For matrix sizes ≤ 4x4, a fast algorithm is used by default. max@0: In rare instances, the fast algorithm might be less precise than the standard algorithm. max@0: To force the use of the standard algorithm, set the slow argument to true max@0:
  • max@0:
    max@0:
  • max@0: NOTE: Old versions of the ATLAS library (eg. 3.6) can corrupt memory and crash your program; max@0: the standard LAPACK library and later versions of ATLAS (eg. 3.8) work without problems max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: vec b = randu<vec>(5);
      max@0: mat B = randu<mat>(5,5);
      max@0: 
      max@0: vec x = solve(A, b);
      max@0: mat X = solve(A, B);
      max@0: 
      max@0: vec x2;
      max@0: solve(x2, A, b);
      max@0: 
      max@0: // tell solve() to look only at the upper triangular part of A
      max@0: mat Y = solve( trimatu(A), B );
      max@0: 
      max@0: 
      max@0: mat44 C = randu<mat>(4,4);
      max@0: mat44 D = randu<mat>(4,4);
      max@0: 
      max@0: mat E = solve(C, D);       // use fast algorithm by default
      max@0: mat F = solve(C, D, true); // use slow algorithm
      max@0: 
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: max@0: vec s = svd(mat X) max@0:
vec s = svd(cx_mat X) max@0:
max@0:
svd(vec s, mat X), max@0:
svd(vec s, cx_mat X) max@0:
max@0:
svd(mat U, vec s, mat V, mat X) max@0:
svd(cx_mat U, vec s, cx_mat V, cx_mat X) max@0:
    max@0:
  • max@0: The single and two argument versions compute the singular values of X max@0:
  • max@0:
    max@0:
  • max@0: The four argument version computes the full singular value decomposition of X max@0:
  • max@0:
    max@0:
  • If X is square, it can be reconstructed using X = U*diagmat(s)*trans(V) max@0:
  • max@0:
    max@0:
  • max@0: The singular values are in descending order max@0:
  • max@0:
    max@0:
  • max@0: If the decomposition fails, the output objects are reset and: max@0:
      max@0:
    • svd(X) throws a std::runtime_error exception
    • max@0:
    • svd(s,X) and svd(U,s,V,X) return a bool set to false
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: NOTE: Old versions of the ATLAS library (eg. 3.6) can corrupt memory and crash your program; max@0: the standard LAPACK library and later versions of ATLAS (eg. 3.8) work without problems max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(5,5);
      max@0: 
      max@0: mat U;
      max@0: vec s;
      max@0: mat V;
      max@0: svd(U,s,V,X);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: svd_econ(mat U, vec s, mat V, mat X, mode = 'b') max@0:
svd_econ(cx_mat U, vec s, cx_mat V, cx_mat X, mode = 'b') max@0:
    max@0:
  • max@0: Economical singular value decomposition of X max@0:
  • max@0:
    max@0:
  • max@0: mode is one of: max@0:
      max@0:
    • 'l': compute only left singular vectors
    • max@0:
    • 'r': compute only right singular vectors
    • max@0:
    • 'b': compute both left and right singular vectors (default)
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: The singular values are in descending order max@0:
  • max@0:
    max@0:
  • max@0: If the decomposition fails, the output objects are reset and bool set to false is returned max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat X = randu<mat>(4,5);
      max@0: 
      max@0: mat U;
      max@0: vec s;
      max@0: mat V;
      max@0: svd_econ(U, s, V, X, 'l');
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: X = syl(A, B, C) max@0:
syl(X, A, B, C) max@0:
    max@0:
  • Solve the Sylvester equation, ie., AX + XB + C = 0, where X is unknown.
  • max@0:
    max@0:
  • Matrices A, B and C must be square sized.
  • max@0:
    max@0:
  • max@0: If no solution is found, X is reset and: max@0:
      max@0:
    • syl(A,B,C) throws a std::runtime_error exception
    • max@0:
    • svd(X,A,B,C) returns a bool set to false
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = randu<mat>(5,5);
      max@0: mat C = randu<mat>(5,5);
      max@0: 
      max@0: mat X1 = syl(A, B, C);
      max@0: 
      max@0: mat X2;
      max@0: syl(X2, A, B, C);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0: max@0: max@0:
max@0:
max@0:
max@0: Miscellaneous max@0:
max@0:
max@0:
max@0:
max@0: max@0: max@0: is_finite(X) max@0:
    max@0:
  • max@0: Returns true if all elements in X are finite max@0:
  • max@0:
    max@0:
  • max@0: Returns false if at least one element in X is non-finite (±infinity or NaN) max@0:
  • max@0:
    max@0:
  • max@0: X can be a scalar (eg. double), vector, matrix or cube max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: mat A = randu<mat>(5,5);
      max@0: mat B = randu<mat>(5,5);
      max@0: 
      max@0: B(1,1) = math::nan();
      max@0: 
      max@0: cout << is_finite(A) << endl;
      max@0: cout << is_finite(B) << endl;
      max@0: 
      max@0: cout << is_finite( 0.123456789 ) << endl;
      max@0: cout << is_finite( math::nan() ) << endl;
      max@0: cout << is_finite( math::inf() ) << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: logging of warnings and errors max@0:
max@0:
max@0: set_stream_err1(user_stream)
max@0: set_stream_err2(user_stream)
max@0:
max@0: std::ostream& x = get_stream_err1() max@0:
max@0: std::ostream& x = get_stream_err2() max@0:
max@0:
    max@0:
  • max@0: By default, Armadillo prints warnings and messages associated with std::logic_error and std::runtime_error exceptions to the std::cout stream max@0:
  • max@0:
    max@0:
  • set_stream_err1(): change the stream for messages associated with std::logic_error exceptions (eg. out of bounds accesses)
  • max@0:
    max@0:
  • set_stream_err2(): change the stream for warnings and messages associated with std::runtime_error exceptions (eg. failed decompositions)
  • max@0:
    max@0:
  • get_stream_err1(): get a reference to the stream for messages associated with std::logic_error exceptions
  • max@0:
    max@0:
  • get_stream_err2(): get a reference to the stream for warnings and messages associated with std::runtime_error exceptions
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: // print "hello" to the current err1 stream
      max@0: get_stream_err1() << "hello" << endl;
      max@0: 
      max@0: // change the err2 stream to be a file
      max@0: ofstream f("my_log.txt");
      max@0: set_stream_err2(f);
      max@0: 
      max@0: // trying to invert a singular matrix
      max@0: // will print a message to the err2 stream
      max@0: // and throw an exception
      max@0: mat X = zeros<mat>(5,5);
      max@0: mat Y = inv(X);
      max@0: 
      max@0: // disable messages being printed to the err2 stream
      max@0: std::ostream nullstream(0);
      max@0: set_stream_err2(nullstream);
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Caveat: set_stream_err1() and set_stream_err2() will not change the stream used by .print() max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
    max@0:
max@0:
max@0: max@0: max@0: max@0: max@0: math constants (pi, e, euler, gratio, sqrt2, eps, log_min, log_max, nan, inf) max@0:
max@0:
    max@0:
  • max@0: Collection of constants, with their precision and/or value dependant on the numerical type and/or machine used. max@0:
  • max@0:
    max@0:
  • max@0: The constants are stored as static functions in the Math<type> class, max@0: where type is either float or double. max@0:
  • max@0:
    max@0:
  • max@0: For convenience, Math<float> has been typedefed as fmath, max@0: while Math<double> has been typedefed as math. max@0:
  • max@0:
    max@0:
  • max@0: Meaning of the constants: max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: math::pi() max@0: max@0:   max@0: max@0: π, the ratio of any circle's circumference to its diameter max@0:
      max@0: math::e() max@0: max@0:   max@0: max@0: base of the natural logarithm max@0:
      max@0: math::euler() max@0: max@0:   max@0: max@0: Euler's constant, aka Euler-Mascheroni constant max@0:
      max@0: math::gratio() max@0: max@0:   max@0: max@0: golden ratio max@0:
      max@0: math::sqrt2() max@0: max@0:   max@0: max@0: square root of 2 max@0:
      max@0: math::eps() max@0: max@0:   max@0: max@0: the difference between 1 and the least value greater than 1 that is representable max@0:
      max@0: math::log_min() max@0: max@0:   max@0: max@0: log of minimum non-zero value max@0:
      max@0: math::log_max() max@0: max@0:   max@0: max@0: log of maximum value max@0:
      max@0: math::nan() max@0: max@0:   max@0: max@0: “not a number” (NaN) max@0:
      max@0: math::inf() max@0: max@0:   max@0: max@0: infinity max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Caveat: max@0: nan() is not equal to anything, even itself; max@0: if you wish to check whether a given number x is finite, max@0: use is_finite(x). max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: cout << "2.0 * pi = " << 2.0 * math::pi() << endl;
      max@0: 
      max@0: cout << "log_max for floats = ";
      max@0: cout << fmath::log_max() << endl;
      max@0: 
      max@0: cout << "log_max for doubles = ";
      max@0: cout << math::log_max() << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: physical constants (speed of light, etc) max@0:
max@0:
    max@0:
  • max@0: Collection of fundamental physical constants, max@0: mainly taken from max@0: NIST max@0: and some from max@0: WolframAlpha max@0: on 2009-06-23. max@0:
  • max@0:
    max@0:
  • max@0: Constants from NIST are in turn sourced from the 2006 CODATA values. max@0:
  • max@0:
    max@0:
  • max@0: The constants are stored as static functions in the Phy<type> class, max@0: where type is either float or double. max@0:
  • max@0:
    max@0:
  • max@0: For convenience, Phy<float> has been typedefed as fphy, max@0: while Phy<double> has been typedefed as phy. max@0:
  • max@0:
    max@0:
  • max@0: Meaning of the constants: max@0:
      max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
      max@0: phy::m_u() max@0: max@0:   max@0: max@0: atomic mass constant (in kg) max@0:
      max@0: phy::N_A() max@0: max@0:   max@0: max@0: Avogadro constant max@0:
      max@0: phy::k() max@0: max@0:   max@0: max@0: Boltzmann constant (in joules per kelvin) max@0:
      max@0: phy::k_evk() max@0: max@0:   max@0: max@0: Boltzmann constant (in eV/K) max@0:
      max@0: phy::a_0() max@0: max@0:   max@0: max@0: Bohr radius (in meters) max@0:
      max@0: phy::mu_B() max@0: max@0:   max@0: max@0: Bohr magneton max@0:
      max@0: phy::Z_0() max@0: max@0:   max@0: max@0: characteristic impedance of vacuum (in ohms) max@0:
      max@0: phy::G_0() max@0: max@0:   max@0: max@0: conductance quantum (in siemens) max@0:
      max@0: phy::k_e() max@0: max@0:   max@0: max@0: Coulomb's constant (in meters per farad) max@0:
      max@0: phy::eps_0() max@0: max@0:   max@0: max@0: electric constant (in farads per meter) max@0:
      max@0: phy::m_e() max@0: max@0:   max@0: max@0: electron mass (in kg) max@0:
      max@0: phy::eV() max@0: max@0:   max@0: max@0: electron volt (in joules) max@0:
      max@0: phy::e() max@0: max@0:   max@0: max@0: elementary charge (in coulombs) max@0:
      max@0: phy::F() max@0: max@0:   max@0: max@0: Faraday constant (in coulombs) max@0:
      max@0: phy::alpha() max@0: max@0:   max@0: max@0: fine-structure constant max@0:
      max@0: phy::alpha_inv() max@0: max@0:   max@0: max@0: inverse fine-structure constant max@0:
      max@0: phy::K_J() max@0: max@0:   max@0: max@0: Josephson constant max@0:
      max@0: phy::mu_0() max@0: max@0:   max@0: max@0: magnetic constant (in henries per meter) max@0:
      max@0: phy::phi_0() max@0: max@0:   max@0: max@0: magnetic flux quantum (in webers) max@0:
      max@0: phy::R() max@0: max@0:   max@0: max@0: molar gas constant (in joules per mole kelvin) max@0:
      max@0: phy::G() max@0: max@0:   max@0: max@0: Newtonian constant of gravitation (in newton square meters per kilogram squared) max@0:
      max@0: phy::h() max@0: max@0:   max@0: max@0: Planck constant (in joule seconds) max@0:
      max@0: phy::h_bar() max@0: max@0:   max@0: max@0: Planck constant over 2 pi, aka reduced Planck constant (in joule seconds) max@0:
      max@0: phy::m_p() max@0: max@0:   max@0: max@0: proton mass (in kg) max@0:
      max@0: phy::R_inf() max@0: max@0:   max@0: max@0: Rydberg constant (in reciprocal meters) max@0:
      max@0: phy::c_0() max@0: max@0:   max@0: max@0: speed of light in vacuum (in meters per second) max@0:
      max@0: phy::sigma() max@0: max@0:   max@0: max@0: Stefan-Boltzmann constant max@0:
      max@0: phy::R_k() max@0: max@0:   max@0: max@0: von Klitzing constant (in ohms) max@0:
      max@0: phy::b() max@0: max@0:   max@0: max@0: Wien wavelength displacement law constant max@0:
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Examples: max@0:
      max@0:
      max@0: cout << "speed of light = " << phy::c_0() << endl;
      max@0: 
      max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: See also: max@0: max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: log_add(log_a, log_b) max@0:
    max@0:
  • max@0: Safe replacement for log(exp(log_a) + exp(log_b)) max@0:
  • max@0:
    max@0:
  • max@0: Usage: max@0:
      max@0:
    • max@0: scalar_type log_c = log_add(log_a, log_b) max@0:
    • max@0:
    • max@0: scalar_type is either float or double max@0:
    • max@0:
    • max@0: log_a, log_b and log_c must have the same type max@0:
    • max@0:
    max@0:
  • max@0:
max@0:
max@0:

max@0: max@0: max@0: uword, sword max@0:
    max@0:
  • max@0: uword is a typedef for an unsigned integer with a minimum width of 32 bits; if ARMA_64BIT_WORD is enabled, the minimum width is 64 bits max@0:
  • max@0:
    max@0:
  • max@0: sword is a typedef for a signed integer with a minimum width of 32 bits; if ARMA_64BIT_WORD is enabled, the minimum width is 64 bits max@0:
  • max@0:
    max@0:
  • max@0: ARMA_64BIT_WORD can be enabled via editing include/armadillo_bits/config.hpp max@0:
  • max@0:
    max@0:
  • See also: max@0: max@0:
  • max@0:
    max@0:
max@0:

max@0: max@0: max@0: cx_float, cx_double max@0: max@0: max@0: max@0:
max@0:
max@0: max@0: Examples of Matlab/Octave syntax and conceptually corresponding Armadillo syntax max@0: max@0:
max@0:
max@0:
    max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0: max@0:
    max@0: Matlab/Octave max@0: max@0:   max@0: max@0: Armadillo max@0: max@0:   max@0: max@0: Notes max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: A(1, 1) max@0: max@0:   max@0: max@0: A(0, 0) max@0: max@0:   max@0: max@0: indexing in Armadillo starts at 0 max@0:
    max@0: A(k, k) max@0: max@0:   max@0: max@0: A(k-1, k-1) max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: size(A,1) max@0: max@0:   max@0: max@0: A.n_rows max@0: max@0:   max@0: max@0: read only max@0:
    max@0: size(A,2) max@0: max@0:   max@0: max@0: A.n_cols max@0: max@0:   max@0: max@0:   max@0:
    max@0: size(Q,3) max@0: max@0:   max@0: max@0: Q.n_slices max@0: max@0:   max@0: max@0: Q is a cube (3D array) max@0:
    max@0: numel(A) max@0: max@0:   max@0: max@0: A.n_elem max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: A(:, k) max@0: max@0:   max@0: max@0: A.col(k) max@0: max@0:   max@0: max@0: this is a conceptual example only; max@0: exact conversion from Matlab/Octave to Armadillo syntax max@0: will require taking into account that indexing starts at 0 max@0:
    max@0: A(k, :) max@0: max@0:   max@0: max@0: A.row(k) max@0: max@0:   max@0: max@0:   max@0:
    max@0: A(:, p:q) max@0: max@0:   max@0: max@0: A.cols(p, q) max@0: max@0:   max@0: max@0:   max@0:
    max@0: A(p:q, :) max@0: max@0:   max@0: max@0: A.rows(p, q) max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: A(p:q, r:s) max@0: max@0:   max@0: max@0: max@0: A.submat(p, r, q, s) max@0: max@0: max@0:   max@0: max@0: max@0: A.submat(first_row, first_col, last_row, last_col) max@0: max@0:
    max@0:   max@0: max@0:   max@0: max@0: max@0: or max@0: max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0: max@0: A( span(p,q), span(r,s) ) max@0: max@0: max@0:   max@0: max@0: max@0: A( span(first_row, last_row), span(first_col, last_col) ) max@0: max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: Q(:, :, k) max@0: max@0:   max@0: max@0: Q.slice(k) max@0: max@0:   max@0: max@0: Q is a cube (3D array) max@0:
    max@0: Q(:, :, t:u) max@0: max@0:   max@0: max@0: Q.slices(t, u) max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: Q(p:q, r:s, t:u) max@0: max@0:   max@0: max@0: max@0: Q.subcube(p, r, t, q, s, u) max@0: max@0: max@0:   max@0: max@0: max@0: .subcube(first_row, first_col, first_slice, last_row, last_col, last_slice) max@0: max@0:
    max@0:   max@0: max@0:   max@0: max@0: max@0: or max@0: max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0: max@0: Q( span(p,q), span(r,s), span(t,u) ) max@0: max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: A' max@0: max@0:   max@0: max@0: A.t() or trans(A) max@0: max@0:   max@0: max@0: matrix transpose / Hermitian transpose max@0:
    max@0: (for complex matrices, the conjugate of each element is taken) max@0:
    max@0: A.' max@0: max@0:   max@0: max@0: A.st() or strans(A) max@0: max@0:   max@0: max@0: simple matrix transpose max@0:
    max@0: (for complex matrices, the conjugate of each element is not taken) max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: A = zeros(size(A)) max@0: max@0:   max@0: max@0: A.zeros() max@0: max@0:   max@0: max@0:   max@0:
    max@0: A = ones(size(A)) max@0: max@0:   max@0: max@0: A.ones() max@0: max@0:   max@0: max@0:   max@0:
    max@0: A = zeros(k) max@0: max@0:   max@0: max@0: A = zeros<mat>(k,k) max@0: max@0:   max@0: max@0:   max@0:
    max@0: A = ones(k) max@0: max@0:   max@0: max@0: A = ones<mat>(k,k) max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: C = complex(A,B) max@0: max@0:   max@0: max@0: cx_mat C = cx_mat(A,B) max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: A .* B max@0: max@0:   max@0: max@0: A % B max@0: max@0:   max@0: max@0: element-wise multiplication max@0:
    max@0: A ./ B max@0: max@0:   max@0: max@0: A / B max@0: max@0:   max@0: max@0: element-wise division max@0:
    max@0: A \ B max@0: max@0:   max@0: max@0: solve(A,B) max@0: max@0:   max@0: max@0: conceptually similar to inv(A)*B, but more efficient max@0:
    max@0: A = A + 1; max@0: max@0:   max@0: max@0: A++ max@0: max@0:   max@0: max@0:   max@0:
    max@0: A = A - 1; max@0: max@0:   max@0: max@0: A-- max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: A = [ 1 2; 3 4; ] max@0: max@0:   max@0: max@0: A << 1 << 2 << endr
    max@0:    << 3 << 4 << endr; max@0:
    max@0:   max@0: max@0: element initialisation, max@0: with special element endr indicating end of row max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: X = [ A  B ] max@0: max@0:   max@0: max@0: X = join_rows(A,B) max@0: max@0:   max@0: max@0:   max@0:
    max@0: X = [ A; B ] max@0: max@0:   max@0: max@0: X = join_cols(A,B) max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: A max@0: max@0:   max@0: max@0: cout << A << endl; max@0:
    or max@0:
    A.print("A ="); max@0:
    max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: save -ascii 'A.dat' A max@0: max@0:   max@0: max@0: A.save("A.dat", raw_ascii); max@0: max@0:   max@0: max@0: Matlab/Octave matrices saved as ascii are readable by Armadillo (and vice-versa) max@0:
    max@0: load -ascii 'A.dat' max@0: max@0:   max@0: max@0: A.load("A.dat", raw_ascii); max@0: max@0:   max@0: max@0:   max@0:
    max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0: max@0:   max@0:
    max@0: S = { 'abc'; 'def' } max@0: max@0:   max@0: max@0: field<std::string> S(2); max@0:
    S(0) = "abc"; max@0:
    S(1) = "def"; max@0:
    max@0:   max@0: max@0: fields can store arbitrary objects, in a 1D or 2D layout max@0:
    max@0:
max@0:
max@0: max@0: max@0:
max@0:
max@0: example program max@0:
max@0:
max@0:
    max@0:
  • max@0: If you save the program below as example.cpp, max@0: under Linux you can compile it using: max@0:
    max@0: g++ example.cpp -o example -O1 -larmadillo max@0:
  • max@0:
      max@0:
      max@0: #include <iostream>
      max@0: #include <armadillo>
      max@0: 
      max@0: using namespace std;
      max@0: using namespace arma;
      max@0: 
      max@0: int main(int argc, char** argv)
      max@0:   {
      max@0:   mat A = randu<mat>(4,5);
      max@0:   mat B = randu<mat>(4,5);
      max@0:   
      max@0:   cout << A*trans(B) << endl;
      max@0:   
      max@0:   return 0;
      max@0:   }
      max@0: 
      max@0:
    max@0:
  • max@0: You may also want to have a look at the example programs that come with the Armadillo archive. max@0:
  • max@0:
    max@0:
  • max@0: As Armadillo is a template library, we strongly recommended to have optimisation enabled when compiling programs max@0: (eg. when compiling with GCC, use the -O1 or -O2 options). max@0:
  • max@0:
max@0:
max@0: max@0: max@0: max@0: max@0: max@0:
max@0:
max@0: API Changes, Additions and Deprecations max@0:
max@0:
max@0: Armadillo's version number is X.Y.Z, where X is a major version, Y is a minor version, and Z is the patch level (indicating bug fixes). max@0:
max@0:
max@0: Within each major version (eg. 2.x), minor versions with an even number (eg. 2.2) are backwards compatible with earlier even minor versions (eg. 2.0). max@0: For example, code written for version 2.0 will work with version 2.2. max@0: However, as each minor version may have more features (ie. API extensions) than earlier versions, max@0: code written for version 2.2 doesn't necessarily work with 2.0. max@0:
max@0:
max@0: An odd minor version number (eg. 2.3) indicates an experimental version. max@0: Experimental versions are generally faster and have more functionality, max@0: but their APIs have not been finalised yet. max@0:
max@0:
max@0: In general, we don't like changes to existing APIs and prefer not to break any user software. max@0: However, to allow evolution and help code maintenance, we reserve the right to change the APIs in future major versions of Armadillo, max@0: while remaining backwards compatible wherever possible max@0: (eg. 3.0 may have slightly different APIs than 2.x). max@0: Also, in a rare instance the user API may need to be altered if a bug fix absolutely requires it. max@0:
max@0:
max@0:
max@0: max@0: Below is a list of deprecated functionality; this functionality will be removed in version 3.0: max@0:
    max@0:
  • max@0: .print_trans() and .raw_print_trans() are deprecated; max@0:
    instead, you can chain .t() and .print() to achieve a similar result: .t().print() max@0:
      max@0:
  • max@0:
  • max@0: support for tying writeable auxiliary (external) memory to fixed size matrices is deprecated; max@0:
    instead, you can use standard matrices with writeable auxiliary memory, max@0: or initialise fixed size matrices by copying the memory. max@0: Using auxiliary memory with standard matrices is unaffected. max@0:
      max@0:
  • max@0:
max@0:
max@0:
max@0: Below is a list of additions and changes since prior versions of Armadillo: max@0:
    max@0: max@0:
  • Added in 2.4: max@0:
      max@0:
    • shorter forms of transposes: .t() and .st()
    • max@0:
    • .resize() and resize() (added in 2.4.1)
    • max@0:
    • optional use of 64 bit indices (allowing matrices to have more than 4 billion elements), max@0:
      enabled via ARMA_64BIT_WORD in include/armadillo_bits/config.hpp
    • max@0:
    • experimental support for C++11 initialiser lists, enabled via ARMA_USE_CXX11 in include/armadillo_bits/config.hpp
    • max@0:
    max@0:
    max@0:
  • Changed in 2.4: max@0:
      max@0:
    • refactored code to eliminate warnings when using the Clang C++ compiler
    • max@0:
    • umat, uvec, .min() and .max() max@0: have been changed to use the uword type instead of the u32 type; max@0: by default the uword and u32 types are equivalent (ie. unsigned integer type with a minimum width 32 bits); max@0: however, when the use of 64 bit indices is enabled via ARMA_64BIT_WORD in include/armadillo_bits/config.hpp, max@0: the uword type then has a minimum width of 64 bits max@0:
    max@0:
  • max@0:
    max@0:
  • Added in 2.2: max@0: max@0:
    max@0:
  • Changed in 2.0: max@0: max@0:
    max@0:
  • Added in 2.0: max@0:
      max@0:
    • det(), inv() and solve() can be forced to use more precise algorithms for tiny matrices (≤ 4x4)
    • max@0:
    • syl(), for solving Sylvester's equation
    • max@0:
    • strans(), for transposing a complex matrix without taking the complex conjugate
    • max@0:
    • symmatu() and symmatl()
    • max@0:
    • submatrices of submatrices
    • max@0:
    • faster inverse of symmetric positive definite matrices
    • max@0:
    • faster element access for fixed size matrices
    • max@0:
    • faster multiplication of tiny matrices (eg. 4x4)
    • max@0:
    • faster compound expressions containing submatrices
    • max@0:
    • handling of arbitrarily sized empty matrices (eg. 5x0)
    • max@0:
    • .count() member function in running_stat and running_stat_vec
    • max@0:
    • loading & saving of matrices as CSV text files
    • max@0:
    max@0:
    max@0:
  • Added in 1.2: max@0:
      max@0:
    • .min() & .max() member functions of Mat and Cube
    • max@0:
    • floor() and ceil()
    • max@0:
    • representation of “not a number”: math::nan()
    • max@0:
    • representation of infinity: math::inf()
    • max@0:
    • standalone is_finite()
    • max@0:
    • .in_range() can use span() arguments
    • max@0:
    • fixed size matrices and vectors can use auxiliary (external) memory
    • max@0:
    • submatrices and subfields can be accessed via X( span(a,b)span(c,d) )
    • max@0:
    • subcubes can be accessed via X( span(a,b)span(c,d)span(e,f) )
    • max@0:
    • the two argument version of span can be replaced by max@0: span::all or span(), to indicate an entire range max@0:
    • max@0:
    • for cubes, the two argument version of span can be replaced by max@0: a single argument version, span(a), to indicate a single column, row or slice max@0:
    • max@0:
    • arbitrary "flat" subcubes can be interpreted as matrices; for example: max@0:
        max@0:
        max@0: cube Q = randu<cube>(5,3,4);
        max@0: mat  A = Q( span(1), span(1,2), span::all );
        max@0: // A has a size of 2x4
        max@0: 
        max@0: vec v = ones<vec>(4);
        max@0: Q( span(1), span(1), span::all ) = v;
        max@0: 
        max@0:
      max@0:
    • max@0:
    • interpretation of matrices as triangular through trimatu() / trimatl()
    • max@0:
    • explicit handling of triangular matrices by solve() and inv()
    • max@0:
    • extended syntax for submatrices, including access to elements whose indices are specified in a vector
    • max@0:
    • ability to change the stream used for logging of errors and warnings
    • max@0:
    • ability to save/load matrices in raw binary format
    • max@0:
    • cumulative sum function: cumsum()
    • max@0:
    max@0:
  • max@0:
    max@0:
  • max@0: Changed in 1.0 (compared to earlier 0.x development versions): max@0:
      max@0:
    • max@0: the 3 argument version of lu(), max@0: eg. lu(L,U,X), max@0: provides L and U which should be the same as produced by Octave 3.2 max@0: (this was not the case in versions prior to 0.9.90) max@0:
    • max@0:
      max@0:
    • max@0: rand() has been replaced by randu(); max@0: this has been done to avoid confusion with std::rand(), max@0: which generates random numbers in a different interval max@0:
    • max@0:
      max@0:
    • max@0: In versions earlier than 0.9.0, max@0: some multiplication operations directly converted result matrices with a size of 1x1 into scalars. max@0: This is no longer the case. max@0: If you know the result of an expression will be a 1x1 matrix and wish to treat it as a pure scalar, max@0: use the as_scalar() wrapping function max@0:
    • max@0:
      max@0:
    • max@0: Almost all functions have been placed in the delayed operations framework (for speed purposes). max@0: This may affect code which assumed that the output of some functions was a pure matrix. max@0: The solution is easy, as explained below. max@0:
      max@0:
      max@0: In general, Armadillo queues operations before executing them. max@0: As such, the direct output of an operation or function cannot be assumed to be a directly accessible matrix. max@0: The queued operations are executed when the output needs to be stored in a matrix, max@0: eg. mat B = trans(A) or mat B(trans(A)). max@0: If you need to force the execution of the delayed operations, max@0: place the operation or function inside the corresponding Mat constructor. max@0: For example, if your code assumed that the output of some functions was a pure matrix, max@0: eg. chol(m).diag(), change the code to mat(chol(m)).diag(). max@0: Similarly, if you need to pass the result of an operation such as A+B to one of your own functions, max@0: use my_function( mat(A+B) ). max@0:
    • max@0:
    max@0:
  • max@0:
    max@0:
max@0:
max@0:
max@0: max@0: max@0: max@0: max@0: max@0:
max@0:
max@0:
max@0: max@0:
max@0:
max@0: max@0: