armadillo
Armadillo
C++ linear algebra library
[top] API Documentation for Armadillo 7.500


Preamble

 
  • Please cite the following article if you use Armadillo in your research and/or software. Citations are useful for the continued development and maintenance of the library.

    Conrad Sanderson and Ryan Curtin.
    Armadillo: a template-based C++ library for linear algebra.
    Journal of Open Source Software, Vol. 1, pp. 26, 2016.


Overview
Matrix, Vector, Cube and Field Classes
Member Functions & Variables
Generated Vectors/Matrices/Cubes
Functions of Vectors/Matrices/Cubes
Decompositions, Factorisations, Inverses and Equation Solvers (Dense Matrices)
Decompositions, Factorisations and Equation Solvers (Sparse Matrices)
Signal & Image Processing
Statistics & Clustering
Miscellaneous




Matrix, Vector, Cube and Field Classes



Mat<type>
mat
cx_mat


Col<type>
vec
cx_vec


Row<type>
rowvec
cx_rowvec


Cube<type>
cube
cx_cube


field<object_type>


SpMat<type>
sp_mat
sp_cx_mat


operators:  +    *  /  %  ==  !=  <=  >=  <  >




Member Functions & Variables



attributes


element/object access via (), [] and .at()


element initialisation


.zeros()
  (member function of Mat, Col, Row, SpMat, Cube)
.zeros( n_elem )
  (member function of Col and Row)
.zeros( n_rows, n_cols )
  (member function of Mat and SpMat)
.zeros( n_rows, n_cols, n_slices )
  (member function of Cube)
.zeros( size(X) )
  (member function of Mat, Col, Row, Cube, SpMat)


.ones()
  (member function of Mat, Col, Row, Cube)
.ones( n_elem )
  (member function of Col and Row)
.ones( n_rows, n_cols )
  (member function of Mat)
.ones( n_rows, n_cols, n_slices )
  (member function of Cube)
.ones( size(X) )
  (member function of Mat, Col, Row, Cube)


.eye()
.eye( n_rows, n_cols )
.eye( size(X) )


.randu()
  (member function of Mat, Col, Row, Cube)
.randu( n_elem )
  (member function of Col and Row)
.randu( n_rows, n_cols )
  (member function of Mat)
.randu( n_rows, n_cols, n_slices )
  (member function of Cube)
.randu( size(X) )
  (member function of Mat, Col, Row, Cube)

.randn()
  (member function of Mat, Col, Row, Cube)
.randn( n_elem )
  (member function of Col and Row)
.randn( n_rows, n_cols )
  (member function of Mat)
.randn( n_rows, n_cols, n_slices )
  (member function of Cube)
.randn( size(X) )
  (member function of Mat, Col, Row, Cube)


.fill( value )


.imbue( functor )
.imbue( lambda_function )   (C++11 only)


.replace( old_value, new_value )


.transform( functor )
.transform( lambda_function )   (C++11 only)


.for_each( functor )
.for_each( lambda_function )   (C++11 only)


.set_size( n_elem )
  (member function of Col, Row, field)
.set_size( n_rows, n_cols )
  (member function of Mat, SpMat, field)
.set_size( n_rows, n_cols, n_slices )
  (member function of Cube and field)
.set_size( size(X) )
  (member function of Mat, Col, Row, Cube, SpMat, field)


.reshape( n_rows, n_cols )
  (member function of Mat and SpMat)
.reshape( n_rows, n_cols, n_slices )
  (member function of Cube)
.reshape( size(X) )
  (member function of Mat, Cube, SpMat)


.resize( n_elem )
  (member function of Col, Row)
.resize( n_rows, n_cols )
  (member function of Mat and SpMat)
.resize( n_rows, n_cols, n_slices )
  (member function of Cube)
.resize( size(X) )
  (member function of Mat, Col, Row, Cube, SpMat)


.copy_size( A )


.reset()


submatrix views


subcube views and slices


subfield views


.diag()
.diag( k )


.each_col()
.each_row()

.each_col( vector_of_indices )
.each_row( vector_of_indices )

.each_col( lambda_function )   (C++11 only)
.each_row( lambda_function )   (C++11 only)


.each_slice()
.each_slice( vector_of_indices )
.each_slice( lambda_function )   (C++11 only)


.set_imag( X )
.set_real( X )


.insert_rows( row_number, X )
.insert_rows( row_number, number_of_rows )
.insert_rows( row_number, number_of_rows, set_to_zero )
  (member functions of Mat and Col)
 
.insert_cols( col_number, X )
.insert_cols( col_number, number_of_cols )
.insert_cols( col_number, number_of_cols, set_to_zero )
  (member functions of Mat and Row)
 
.insert_slices( slice_number, X )
.insert_slices( slice_number, number_of_slices )
.insert_slices( slice_number, number_of_slices, set_to_zero )
  (member functions of Cube)


.shed_row( row_number )
.shed_rows( first_row, last_row )
  (member functions of Mat, Col and SpMat)
 
.shed_col( column_number )
.shed_cols( first_column, last_column )
  (member functions of Mat, Row and SpMat)
 
.shed_slice( slice_number )
.shed_slices( first_slice, last_slice )
  (member functions of Cube)


.swap_rows( row1, row2 )
.swap_cols( col1, col2 )


.swap( X )


.memptr()


.colptr( col_number )


iterators (matrices & vectors)


iterators (cubes)


STL-style container functions


.t()
.st()


.i()


.min()
.max()


.index_min()
.index_max()


.eval()


.in_range( i )
  (member of Mat, Col, Row, Cube, SpMat, field)
.in_range( span(start, end) )
  (member of Mat, Col, Row, Cube, SpMat, field)
 
.in_range( row, col )
  (member of Mat, Col, Row, SpMat, field)
.in_range( span(start_row, end_row), span(start_col, end_col) )
  (member of Mat, Col, Row, SpMat, field)
 
.in_range( row, col, slice )
  (member of Cube and field)
.in_range( span(start_row, end_row), span(start_col, end_col), span(start_slice, end_slice) )
  (member of Cube and field)
 
.in_range( first_row, first_col, size(X) )   (X is a matrix or field)
  (member of Mat, Col, Row, SpMat, field)
.in_range( first_row, first_col, size(n_rows, n_cols) )
  (member of Mat, Col, Row, SpMat, field)
 
.in_range( first_row, first_col, first_slice, size(Q) )   (Q is a cube or field)
  (member of Cube and field)
.in_range( first_row, first_col, first_slice, size(n_rows, n_cols n_slices) )
  (member of Cube and field)


.is_empty()


.is_square()


.is_vec()
.is_colvec()
.is_rowvec()


.is_sorted()
.is_sorted( sort_direction )
.is_sorted( sort_direction, dim )


.is_finite()


.has_inf()


.has_nan()


.print()
.print( header )

.print( stream )
.print( stream, header )


.raw_print()
.raw_print( header )

.raw_print( stream )
.raw_print( stream, header )


saving/loading matrices & cubes

.save( name )
.save( name, file_type )

.save( stream )
.save( stream, file_type )
       .load( name )
.load( name, file_type )

.load( stream )
.load( stream, file_type )



saving/loading fields

.save( name )
.save( name, file_type )

.save( stream )
.save( stream, file_type )
       .load( name )
.load( name, file_type )

.load( stream )
.load( stream, file_type )





Generated Vectors/Matrices/Cubes



eye( n_rows, n_cols )
eye( size(X) )


linspace( start, end )
linspace( start, end, N )


logspace( A, B )
logspace( A, B, N )


ones( n_elem )
ones( n_rows, n_cols )
ones( n_rows, n_cols, n_slices )
ones( size(X) )


randi( n_elem )
randi( n_elem, distr_param(a,b) )

randi( n_rows, n_cols )
randi( n_rows, n_cols, distr_param(a,b) )

randi( n_rows, n_cols, n_slices )
randi( n_rows, n_cols, n_slices, distr_param(a,b) )

randi( size(X) )
randi( size(X), distr_param(a,b) )


randu( n_elem )
randu( n_rows, n_cols )
randu( n_rows, n_cols, n_slices )
randu( size(X) )

randn( n_elem )
randn( n_rows, n_cols )
randn( n_rows, n_cols, n_slices )
randn( size(X) )


randg( n_elem )
randg( n_elem, distr_param(a,b) )

randg( n_rows, n_cols )
randg( n_rows, n_cols, distr_param(a,b) )

randg( n_rows, n_cols, n_slices )
randg( n_rows, n_cols, n_slices, distr_param(a,b) )

randg( size(X) )
randg( size(X), distr_param(a,b) )


regspace( start, end )
regspace( start, delta, end )


speye( n_rows, n_cols )
speye( size(X) )


spones( A )


sprandu( n_rows, n_cols, density )
sprandn( n_rows, n_cols, density )

sprandu( size(X), density )
sprandn( size(X), density )


toeplitz( A )
toeplitz( A, B )
circ_toeplitz( A )


zeros( n_elem )
zeros( n_rows, n_cols )
zeros( n_rows, n_cols, n_slices )
zeros( size(X) )




Functions of Vectors/Matrices/Cubes



abs( X )


accu( X )


all( V )
all( X )
all( X, dim )


any( V )
any( X )
any( X, dim )


approx_equal( A, B, method, tol )
approx_equal( A, B, method, abs_tol, rel_tol )


as_scalar( expression )


clamp( X, min_val, max_val )


cond( A )


conj( X )


conv_to< type >::from( X )


cross( A, B )


cumsum( V )
cumsum( X )
cumsum( X, dim )


cumprod( V )
cumprod( X )
cumprod( X, dim )


det( A )
log_det( val, sign, A )


diagmat( V )
diagmat( V, k )
diagmat( X )
diagmat( X, k )


diagvec( A )
diagvec( A, k )


diff( V )
diff( V, k )

diff( X )
diff( X, k )
diff( X, k, dim )


dot( A, B )
cdot( A, B )
norm_dot( A, B )


eps( X )


B = expmat(A)
expmat(B, A)


B = expmat_sym(A)
expmat_sym(B, A)


find( X )
find( X, k )
find( X, k, s )


find_finite( X )


find_nonfinite( X )


find_unique( X )
find_unique( X, ascending_indices )


fliplr( X )
flipud( X )


imag( X )
real( X )


uvec sub = ind2sub( size(X), index )
umat sub = ind2sub( size(X), vector_of_indices )


index_min( V )
index_min( M )
index_min( M, dim )
       index_max( V )
index_max( M )
index_max( M, dim )


inplace_trans( X )
inplace_trans( X, method )

inplace_strans( X )
inplace_strans( X, method )


is_finite( X )


join_rows( A, B )
join_horiz( A, B )

join_cols( A, B )
join_vert( A, B )


join_slices( cube C, cube D )
join_slices( mat M, mat N )

join_slices( mat M, cube C )
join_slices( cube C, mat M )


kron( A, B )


B = logmat(A)
logmat(B, A)


B = logmat_sympd(A)
logmat_sympd(B, A)


min( V )
min( M )
min( M, dim )
min( Q )
min( Q, dim )
min( A, B )
       max( V )
max( M )
max( M, dim )
max( Q )
max( Q, dim )
max( A, B )


nonzeros(X)


norm( X )
norm( X, p )


normalise( V )
normalise( V, p )

normalise( X )
normalise( X, p )
normalise( X, p, dim )


prod( V )
prod( M )
prod( M, dim )


rank( X )
rank( X, tolerance )


rcond( A )


repmat( A, num_copies_per_row, num_copies_per_col )


reshape( mat, n_rows, n_cols )
reshape( mat, size(X) )

reshape( cube, n_rows, n_cols, n_slices )
reshape( cube, size(X) )


resize( mat, n_rows, n_cols )
resize( mat, size(X) )

resize( cube, n_rows, n_cols, n_slices )
resize( cube, size(X) )


shift( V, N )
shift( X, N )
shift( X, N, dim )


shuffle( V )
shuffle( X )
shuffle( X, dim )


size( X )
size( n_rows, n_cols )
size( n_rows, n_cols, n_slices )


sort( V )
sort( V, sort_direction )

sort( X )
sort( X, sort_direction )
sort( X, sort_direction, dim )


sort_index( X )
sort_index( X, sort_direction )

stable_sort_index( X )
stable_sort_index( X, sort_direction )


B = sqrtmat(A)
sqrtmat(B,A)


B = sqrtmat_sympd(A)
sqrtmat_sympd(B,A)


sum( V )
sum( M )
sum( M, dim )
sum( Q )
sum( Q, dim )


uword index = sub2ind( size(M), row, col )(M is a matrix)
uvec indices = sub2ind( size(M), matrix_of_subscripts )
    
uword index = sub2ind( size(Q), row, col, slice )(Q is a cube)
uvec indices = sub2ind( size(Q), matrix_of_subscripts )


symmatu( A )
symmatu( A, do_conj )

symmatl( A )
symmatl( A, do_conj )


trace( X )


trans( A )
strans( A )


trapz( X, Y )
trapz( X, Y, dim )

trapz( Y )
trapz( Y, dim )


trimatu( A )
trimatl( A )


unique( A )


vectorise( X )
vectorise( X, dim )


miscellaneous element-wise functions:


trigonometric element-wise functions (cos, sin, tan, ...)




Decompositions, Factorisations, Inverses and Equation Solvers (Dense Matrices)



R = chol( X )
R = chol( X, layout )

chol( R, X )
chol( R, X, layout )


vec eigval = eig_sym( X )

eig_sym( eigval, X )

eig_sym( eigval, eigvec, X )
eig_sym( eigval, eigvec, X, method )


cx_vec eigval = eig_gen( X )

eig_gen( eigval, X )

eig_gen( eigval, eigvec, X )


cx_vec eigval = eig_pair( A, B )

eig_pair( eigval, A, B )

eig_pair( eigval, eigvec, A, B )


B = inv( A )
inv( B, A )


B = inv_sympd( A )
inv_sympd( B, A )


lu( L, U, P, X )
lu( L, U, X )


B = null( A )
B = null( A, tolerance )

null( B, A )
null( B, A, tolerance )


B = orth( A )
B = orth( A, tolerance )

orth( B, A )
orth( B, A, tolerance )


B = pinv( A )
B = pinv( A, tolerance )
B = pinv( A, tolerance, method )

pinv( B, A )
pinv( B, A, tolerance )
pinv( B, A, tolerance, method )


qr( Q, R, X )


qr_econ( Q, R, X )


qz( AA, BB, Q, Z, A, B )
qz( AA, BB, Q, Z, A, B, select )


S = schur( X )

schur( S, X )

schur( U, S, X )


X = solve( A, B )
X = solve( A, B, settings )

solve( X, A, B )
solve( X, A, B, settings )


vec s = svd( X )

svd( vec s, X )

svd( mat U, vec s, mat V, mat X )
svd( mat U, vec s, mat V, mat X, method )

svd( cx_mat U, vec s, cx_mat V, cx_mat X )
svd( cx_mat U, vec s, cx_mat V, cx_mat X, method )


svd_econ( mat U, vec s, mat V, mat X )
svd_econ( mat U, vec s, mat V, mat X, mode )
svd_econ( mat U, vec s, mat V, mat X, mode, method )

svd_econ( cx_mat U, vec s, cx_mat V, cx_mat X )
svd_econ( cx_mat U, vec s, cx_mat V, cx_mat X, mode )
svd_econ( cx_mat U, vec s, cx_mat V, cx_mat X, mode, method )


X = syl( A, B, C )
syl( X, A, B, C )




Decompositions, Factorisations and Equation Solvers (Sparse Matrices)



vec eigval = eigs_sym( X, k )
vec eigval = eigs_sym( X, k, form )
vec eigval = eigs_sym( X, k, form, tol )

eigs_sym( eigval, X, k )
eigs_sym( eigval, X, k, form )
eigs_sym( eigval, X, k, form, tol )

eigs_sym( eigval, eigvec, X, k )
eigs_sym( eigval, eigvec, X, k, form )
eigs_sym( eigval, eigvec, X, k, form, tol )


cx_vec eigval = eigs_gen( X, k )
cx_vec eigval = eigs_gen( X, k, form )
cx_vec eigval = eigs_gen( X, k, form, tol )

eigs_gen( eigval, X, k )
eigs_gen( eigval, X, k, form )
eigs_gen( eigval, X, k, form, tol )

eigs_gen( eigval, eigvec, X, k )
eigs_gen( eigval, eigvec, X, k, form )
eigs_gen( eigval, eigvec, X, k, form, tol )


X = spsolve( A, B )
X = spsolve( A, B, solver )
X = spsolve( A, B, solver, settings )

spsolve( X, A, B )
spsolve( X, A, B, solver )
spsolve( X, A, B, solver, settings )


vec s = svds( X, k )
vec s = svds( X, k, tol )

svds( vec s, X, k )
svds( vec s, X, k, tol )

svds( mat U, vec s, mat V, sp_mat X, k )
svds( mat U, vec s, mat V, sp_mat X, k, tol )

svds( cx_mat U, vec s, cx_mat V, sp_cx_mat X, k )
svds( cx_mat U, vec s, cx_mat V, sp_cx_mat X, k, tol )




Signal & Image Processing



conv( A, B )
conv( A, B, shape )


conv2( A, B )
conv2( A, B, shape )


cx_mat Y =  fft( X )
cx_mat Y =  fft( X, n )

cx_mat Z = ifft( cx_mat Y )
cx_mat Z = ifft( cx_mat Y, n )


cx_mat Y =  fft2( X )
cx_mat Y =  fft2( X, n_rows, n_cols )

cx_mat Z = ifft2( cx_mat Y )
cx_mat Z = ifft2( cx_mat Y, n_rows, n_cols )


interp1( X, Y, XI, YI )
interp1( X, Y, XI, YI, method )
interp1( X, Y, XI, YI, method, extrapolation_value )




Statistics & Clustering



mean, median, stddev, var


cov( X, Y )
cov( X, Y, norm_type )

cov( X )
cov( X, norm_type )


cor( X, Y )
cor( X, Y, norm_type )

cor( X )
cor( X, norm_type )


hist( V )
hist( V, n_bins )
hist( V, centers )

hist( X, centers )
hist( X, centers, dim )


histc( V, edges )
histc( X, edges )
histc( X, edges, dim )


mat coeff = princomp( mat X )
cx_mat coeff = princomp( cx_mat X )

princomp( mat coeff, mat X )
princomp( cx_mat coeff, cx_mat X )

princomp( mat coeff, mat score, mat X )
princomp( cx_mat coeff, cx_mat score, cx_mat X )

princomp( mat coeff, mat score, vec latent, mat X )
princomp( cx_mat coeff, cx_mat score, vec latent, cx_mat X )

princomp( mat coeff, mat score, vec latent, vec tsquared, mat X )
princomp( cx_mat coeff, cx_mat score, vec latent, cx_vec tsquared, cx_mat X )


running_stat<type>


running_stat_vec<vec_type>
running_stat_vec<vec_type>(calc_cov)


kmeans( means, data, k, seed_mode, n_iter, print_mode )


gmm_diag




Miscellaneous



constants (pi, inf, speed of light, ...)


wall_clock


logging of warnings and errors

set_stream_err1( user_stream )
set_stream_err2( user_stream )

std::ostream& x = get_stream_err1()
std::ostream& x = get_stream_err2()


uword, sword


cx_double, cx_float


Examples of Matlab/Octave syntax and conceptually corresponding Armadillo syntax




example program



config.hpp


History of API Additions, Changes and Deprecations


sourceforge