max@0:
max@0:
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: 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:
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: umat
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Mat<uword>
max@0: |
max@0:
max@0:
max@0:
max@0: imat
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Mat<sword>
max@0: |
max@0:
max@0:
max@0:
max@0: fmat
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Mat<float>
max@0: |
max@0:
max@0:
max@0:
max@0: mat
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Mat<double>
max@0: |
max@0:
max@0:
max@0:
max@0: cx_fmat
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Mat<cx_float>
max@0: |
max@0:
max@0:
max@0:
max@0: cx_mat
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Mat<cx_double>
max@0: |
max@0:
max@0:
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: 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: mat A(5,5);
max@0: A = 123.0;
max@0:
max@0:
max@0: Use the following code instead:
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: 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:
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: vec q(5);
max@0: q = 123.0;
max@0:
max@0:
max@0: Use the following code instead:
max@0:
max@0: vec q(5);
max@0: q.fill(123.0);
max@0:
max@0:
max@0: Or:
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:
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: rowvec r(5);
max@0: r = 123.0;
max@0:
max@0:
max@0: Use the following code instead:
max@0:
max@0: rowvec r(5);
max@0: r.fill(123.0);
max@0:
max@0:
max@0: Or:
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: ucube
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Cube<uword>
max@0: |
max@0:
max@0:
max@0:
max@0: icube
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Cube<sword>
max@0: |
max@0:
max@0:
max@0:
max@0: fcube
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Cube<float>
max@0: |
max@0:
max@0:
max@0:
max@0: cube
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Cube<double>
max@0: |
max@0:
max@0:
max@0:
max@0: cx_fcube
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Cube<cx_float>
max@0: |
max@0:
max@0:
max@0:
max@0: cx_cube
max@0: |
max@0:
max@0: =
max@0: |
max@0:
max@0: Cube<cx_double>
max@0: |
max@0:
max@0:
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: 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:
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: 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: cube c(5,6,7);
max@0: c.fill(123.0);
max@0:
max@0:
max@0: Or:
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: // 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: .n_rows
max@0: |
max@0: |
max@0:
max@0: (number of rows)
max@0: |
max@0:
max@0:
max@0:
max@0: .n_cols
max@0: |
max@0: |
max@0:
max@0: (number of columns)
max@0: |
max@0:
max@0:
max@0:
max@0: .n_elem
max@0: |
max@0: |
max@0:
max@0: (total number of elements)
max@0: |
max@0:
max@0:
max@0:
max@0: .n_slices
max@0: |
max@0: |
max@0:
max@0: (number of slices)
max@0: |
max@0:
max@0:
max@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: .colptr(col_number)
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:
max@0:
max@0:
max@0:
max@0:
max@0: .diag(k=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: (n)
max@0: |
max@0:
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:
max@0:
max@0: |
max@0: |
max@0: |
max@0:
max@0:
max@0:
max@0: .at(n) and [n]
max@0: |
max@0:
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:
max@0:
max@0: |
max@0: |
max@0: |
max@0:
max@0:
max@0:
max@0: (i,j)
max@0: |
max@0:
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:
max@0:
max@0: |
max@0: |
max@0: |
max@0:
max@0:
max@0:
max@0: .at(i,j)
max@0: |
max@0:
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: |
max@0:
max@0:
max@0: |
max@0: |
max@0: |
max@0:
max@0:
max@0:
max@0: (i,j,k)
max@0: |
max@0:
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:
max@0:
max@0: |
max@0: |
max@0: |
max@0:
max@0:
max@0:
max@0: .at(i,j,k)
max@0: |
max@0:
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:
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: 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: 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:
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:
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: .in_range( i ) |
max@0:
max@0: |
max@0: (member of Mat, Col, Row, Cube and field)
max@0: |
max@0:
max@0:
max@0: .in_range( span(start, end) ) |
max@0:
max@0: |
max@0: (member of Mat, Col, Row, Cube and field)
max@0: |
max@0:
max@0:
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0: .in_range( row, col ) |
max@0:
max@0: |
max@0: (member of Mat, Col, Row and field)
max@0: |
max@0:
max@0:
max@0: .in_range( span(start_row, end_row), span(start_col, end_col) ) |
max@0:
max@0: |
max@0: (member of Mat, Col, Row and field)
max@0: |
max@0:
max@0:
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0: .in_range( row, col, slice ) |
max@0:
max@0: |
max@0: (member of Cube)
max@0: |
max@0:
max@0:
max@0: .in_range( span(start_row, end_row), span(start_col, end_col), span(start_slice, end_slice) ) |
max@0:
max@0: |
max@0: (member of Cube)
max@0: |
max@0:
max@0:
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: 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:
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: 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:
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: 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: .insert_rows( row_number, X )
max@0:
max@0: .insert_rows( row_number, number_of_rows, set_to_zero = true )
max@0: |
max@0:
|
max@0: (member functions of Mat and Col)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
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: |
max@0:
|
max@0: (member functions of Mat and Row)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
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: |
max@0:
|
max@0: (member functions of Cube)
max@0: |
max@0:
max@0:
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: 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: mat::iterator
max@0:
max@0: vec::iterator
max@0:
max@0: rowvec::iterator
max@0: |
max@0:
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:
max@0: |
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: |
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:
max@0: |
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: |
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:
max@0: |
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: |
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:
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: mat::row_iterator
max@0: |
max@0:
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:
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: mat::const_row_iterator
max@0: |
max@0:
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:
max@0: |
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: |
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:
max@0: |
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: |
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:
max@0:
max@0: -
max@0: Member functions:
max@0:
max@0:
max@0:
max@0:
max@0:
max@0:
max@0:
max@0: .begin()
max@0: |
max@0:
max@0: |
max@0:
max@0: iterator referring to the first element
max@0: |
max@0:
max@0:
max@0:
max@0: .end()
max@0: |
max@0:
max@0: |
max@0:
max@0: iterator referring to the past-the-end element
max@0: |
max@0:
max@0:
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: .begin_row(row_number)
max@0: |
max@0:
max@0: |
max@0:
max@0: iterator referring to the first element of the specified row
max@0: |
max@0:
max@0:
max@0:
max@0: .end_row(row_number)
max@0: |
max@0:
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:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: .begin_col(col_number)
max@0: |
max@0:
max@0: |
max@0:
max@0: iterator referring to the first element of the specified column
max@0: |
max@0:
max@0:
max@0:
max@0: .end_col(col_number)
max@0: |
max@0:
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:
max@0:
max@0: -
max@0: Examples:
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: cube::iterator
max@0: |
max@0:
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:
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: cube::const_iterator
max@0: |
max@0:
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:
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: cube::slice_iterator
max@0: |
max@0:
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:
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: cube::const_slice_iterator
max@0: |
max@0:
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:
max@0:
max@0: -
max@0: Member functions:
max@0:
max@0:
max@0:
max@0:
max@0:
max@0:
max@0:
max@0: .begin()
max@0: |
max@0:
max@0: |
max@0:
max@0: iterator referring to the first element
max@0: |
max@0:
max@0:
max@0:
max@0: .end()
max@0: |
max@0:
max@0: |
max@0:
max@0: iterator referring to the past-the-end element
max@0: |
max@0:
max@0:
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: .begin_slice(slice_number)
max@0: |
max@0:
max@0: |
max@0:
max@0: iterator referring to the first element of the specified slice
max@0: |
max@0:
max@0:
max@0:
max@0: .end_slice(slice_number)
max@0: |
max@0:
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:
max@0:
max@0: -
max@0: Examples:
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:
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: .min() |
max@0:
max@0: |
max@0: (member functions of Mat, Col, Row, Cube)
max@0: |
max@0:
max@0:
max@0: .max() |
max@0:
max@0: |
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( index_of_min_val ) |
max@0:
max@0: |
max@0: (member functions of Mat, Col, Row, Cube)
max@0: |
max@0:
max@0:
max@0: .max( index_of_max_val ) |
max@0:
max@0: |
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( row_of_min_val, col_of_min_val ) |
max@0:
max@0: |
max@0: (member functions of Mat)
max@0: |
max@0:
max@0:
max@0: .max( row_of_max_val, col_of_max_val ) |
max@0:
max@0: |
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( row_of_min_val, col_of_min_val, slice_of_min_val ) |
max@0:
max@0: |
max@0: (member functions of Cube)
max@0: |
max@0:
max@0:
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:
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: 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:
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: Addition of two objects |
max@0:
max@0:
max@0: - |
max@0:
max@0: |
max@0: Subtraction of one object from another or negation of an object |
max@0:
max@0:
max@0: / |
max@0:
max@0: |
max@0: Element-wise division of an object by another object or a scalar |
max@0:
max@0:
max@0: * |
max@0:
max@0: |
max@0: Matrix multiplication of two objects; not applicable to the cube class unless multiplying a cube by a scalar |
max@0:
max@0:
max@0: % |
max@0:
max@0: |
max@0: Schur product: element-wise multiplication of two objects |
max@0:
max@0:
max@0: == |
max@0:
max@0: |
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:
max@0:
max@0: != |
max@0:
max@0: |
max@0: Element-wise non-equality evaluation of two objects |
max@0:
max@0:
max@0: >= |
max@0:
max@0: |
max@0: As for ==, but the check is for "greater than or equal to" |
max@0:
max@0:
max@0: <= |
max@0:
max@0: |
max@0: As for ==, but the check is for "less than or equal to" |
max@0:
max@0:
max@0: > |
max@0:
max@0: |
max@0: As for ==, but the check is for "greater than" |
max@0:
max@0:
max@0: < |
max@0:
max@0: |
max@0: As for ==, but the check is for "less than" |
max@0:
max@0:
max@0:
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: 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: 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:
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:
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:
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: .reshape(n_rows, n_cols, dim=0) |
max@0:
max@0: |
max@0: (member function of Mat, Col, Row)
max@0: |
max@0:
max@0:
max@0: .reshape(n_rows, n_cols, n_slices, dim=0) |
max@0:
max@0: |
max@0: (member function of Cube)
max@0: |
max@0:
max@0:
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: 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: .resize(n_elem) |
max@0:
max@0: |
max@0: (member function of Col, Row)
max@0: |
max@0:
max@0:
max@0: .resize(n_rows, n_cols) |
max@0:
max@0: |
max@0: (member function of Mat)
max@0: |
max@0:
max@0:
max@0: .resize(n_rows, n_cols, n_slices) |
max@0:
max@0: |
max@0: (member function of Cube)
max@0: |
max@0:
max@0:
max@0:
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: auto_detect |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: raw_ascii |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: raw_binary |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: arma_ascii |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: arma_binary |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: csv_ascii |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: pgm_binary |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: ppm_binary |
max@0:
max@0: |
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:
max@0:
max@0: -
max@0: Examples:
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: auto_detect |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: arma_binary |
max@0:
max@0: |
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: |
max@0:
max@0:
max@0: ppm_binary |
max@0:
max@0: |
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:
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: 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: 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: .set_size(n_elem) |
max@0:
max@0: |
max@0: (member function of Col, Row, and field)
max@0: |
max@0:
max@0:
max@0: .set_size(n_rows, n_cols) |
max@0:
max@0: |
max@0: (member function of Mat and field)
max@0: |
max@0:
max@0:
max@0: .set_size(n_rows, n_cols, n_slices) |
max@0:
max@0: |
max@0: (member function of Cube)
max@0: |
max@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:
max@0:
max@0:
max@0:
max@0: .shed_row( row_number )
max@0:
max@0: .shed_rows( first_row, last_row )
max@0: |
max@0:
|
max@0: (member functions of Mat and Col)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: .shed_col( column_number )
max@0:
max@0: .shed_cols( first_column, last_column )
max@0: |
max@0:
|
max@0: (member functions of Mat and Row)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: .shed_slice( slice_number )
max@0:
max@0: .shed_slices( first_slice, last_slice )
max@0: |
max@0:
|
max@0: (member functions of Cube)
max@0: |
max@0:
max@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: STL container functions
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: 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: 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:
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:
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: 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:
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:
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: 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:
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: 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: 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: 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:
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:
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: 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:
max@0:
max@0:
max@0:
max@0:
max@0: eps(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:
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:
max@0:
max@0:
max@0:
max@0:
max@0: trigonometric functions (cos, sin, tan, ...)
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: 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: 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: 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:
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: 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:
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:
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:
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:
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: 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: 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: 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: 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:
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:
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:
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: 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: 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:
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:
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:
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: 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:
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:
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: 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: 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:
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:
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:
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:
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:
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:
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:
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:
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:
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: 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: 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: 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: 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:
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: 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: 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: 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: 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: 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: 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: 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: // 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:
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:
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: cx_float is a typedef for std::complex<float>
max@0:
max@0:
max@0: -
max@0: cx_double is a typedef for std::complex<double>
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: 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: Matlab/Octave
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: Armadillo
max@0: |
max@0:
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: |
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: |
max@0:
max@0: A(0, 0)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: indexing in Armadillo starts at 0
max@0: |
max@0:
max@0:
max@0:
max@0: A(k, k)
max@0: |
max@0:
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:
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: |
max@0:
max@0: A.n_rows
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: read only
max@0: |
max@0:
max@0:
max@0:
max@0: size(A,2)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: A.n_cols
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: size(Q,3)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: Q.n_slices
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: Q is a cube (3D array)
max@0: |
max@0:
max@0:
max@0:
max@0: numel(A)
max@0: |
max@0:
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:
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: |
max@0:
max@0: A.col(k)
max@0: |
max@0:
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:
max@0:
max@0:
max@0: A(k, :)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: A.row(k)
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)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: A.cols(p, q)
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, :)
max@0: |
max@0:
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:
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:
max@0:
max@0: A.submat(p, r, q, s)
max@0:
max@0: |
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:
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:
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:
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: |
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: |
max@0:
max@0: Q.slice(k)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: Q is a cube (3D array)
max@0: |
max@0:
max@0:
max@0:
max@0: Q(:, :, t:u)
max@0: |
max@0:
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:
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:
max@0:
max@0: Q.subcube(p, r, t, q, s, u)
max@0:
max@0: |
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:
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:
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:
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: |
max@0:
max@0: A.t() or trans(A)
max@0: |
max@0:
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:
max@0:
max@0:
max@0: A.'
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: A.st() or strans(A)
max@0: |
max@0:
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: |
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: |
max@0:
max@0: A.zeros()
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: A = ones(size(A))
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: A.ones()
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0:
max@0:
max@0: A = zeros(k)
max@0: |
max@0:
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:
max@0: |
max@0:
max@0:
max@0:
max@0: A = ones(k)
max@0: |
max@0:
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:
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: |
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:
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: |
max@0:
max@0: A % B
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: element-wise multiplication
max@0: |
max@0:
max@0:
max@0:
max@0: A ./ B
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: A / B
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: element-wise division
max@0: |
max@0:
max@0:
max@0:
max@0: A \ B
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: solve(A,B)
max@0: |
max@0:
max@0:
max@0: |
max@0:
max@0: conceptually similar to inv(A)*B, but more efficient
max@0: |
max@0:
max@0:
max@0:
max@0: A = A + 1;
max@0: |
max@0:
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: A = A - 1;
max@0: |
max@0:
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:
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: |
max@0:
max@0: A << 1 << 2 << endr
max@0: << 3 << 4 << endr;
max@0: |
max@0:
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: |
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: |
max@0:
max@0: X = join_rows(A,B)
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: |
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:
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: |
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:
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: |
max@0:
max@0: A.save("A.dat", raw_ascii);
max@0: |
max@0:
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:
max@0:
max@0:
max@0: load -ascii 'A.dat'
max@0: |
max@0:
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:
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: |
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: |
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:
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: #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: - trans() now takes the complex conjugate when transposing a complex matrix
max@0: - Forms of
max@0: chol(), eig_sym(), eig_gen(),
max@0: inv(), lu(), pinv(), princomp(),
max@0: qr(), solve(), svd(), syl()
max@0: that do not return a bool indicating success now throw std::runtime_error exceptions when failures are detected
max@0: - princomp_cov() has been removed; eig_sym() in conjunction with cov() can be used instead
max@0: - .is_vec() now outputs true for empty vectors (eg. 0x1)
max@0: - set_log_stream() & get_log_stream() have been replaced by set_stream_err1() & get_stream_err1()
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: 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: