c++boost.gif Overview of Matrix- and Vector-Types

Contents:
Vectors
Vector Proxies
Matrices
Matrix Proxies
Special Storage Layouts

Notation:

T is the data type, e.g. double, ...
F is the orientation type (functor), either row_major or column_major
C is a container type, e.g. std::vector, bounded_array, unbounded_array, ...
TRI is a triangular functor: lower, unit_lower, strict_lower, upper, unit_upper, strict_upper
M, N are unsinged integer values (std::size_t)
VEC is any vector type
MAT is any matrix type
[...] denote optional arguments - for more details look at the section "storage layout".

Vectors

Definition Description
vector<T [, C]> v(size); a dense vector of values of type T of arbitrary size - only depending on the underlying container type C which defaults to unbounded_array.
bounded_vector<T, N> v; a dense vector of values of type T of maximal size N. The default contructor initialises c to a zero vector of size N.
zero_vector<T> v(size); the zero vector of type T with arbitrary size.
unit_vector<T> v(size, index); the unit vector of type T with arbitrary size. The vector is v(i) = (i==index)?T(1):T(). index should be less than size.
sparse_vector<T [, C]> v(size); a sparse vector of values of type T of arbitrary size. The container type can be std::map<size_t, T> or map_array<size_t, T>.
compressed_vector<T [, C]> v(size); a sparse vector of values of type T of arbitrary size. The non zero values are stored as two seperate arrays - an index array and a value array. The index array is always sorted and the is at most one entry for each index.
coordinate_vector<T [, C]> v(size); a sparse vector of values of type T of arbitrary size. The non zero values are stored as two seperate arrays - an index array and a value array. The arrays may be out of order with multiple entries for each vector element. If there are multiple values for the same index the sum of these values is the real value.

Note: the default types are defined in boost/numeric/ublas/fwd.hpp.

Vector Proxies

Definition Description
vector_range<VEC> vr(v, range); a vector referencing a continuous subvector of elements of vector v containing all elements specified by range.
vector_slice<VEC> vs(v, slice); a vector referencing a non continuous subvector of elements of vector v containing all elements specified by slice.
matrix_row<MAT> vr(m, index); a vector referencing the index-th row of matrix m
matrix_column<MAT> vc(m, index); a vector referencing the index-th column of matrix m

Matrices

Definition Description
matrix<T [, F, C]> m(rows, columns); a dense matrix of values of type T of arbitrary size - only depending on the underlying container type C which defaults to unbounded_array. The orientation functor F defaults to row_major.
bounded_matrix<T, M, N [, F]> m; a dense matrix of M-by-N values of type T. The orientation functor F defaults to row_major. The default constructor creates a M-by-N zero matrix.
c_matrix<T, M, N> m(rows, columns); a dense matrix of values of type T of given size. The data is stored as a usual c array T data_[N][M]
vector_of_vector<T [, F, C]> m(rows, columns); a dense matrix of values of type T of given size. The data is stored as a vector of vectors. The orientation F defaults to row_major. The container type C defaults to unbounded_array<unbounded_array<T> >
zero_matrix<T> m(rows, columns); a zero matrix of type T of arbitrary size.
identity_matrix<T> m(rows, columns); an identity matrix of type T of arbitrary size. The values are v(i,j) = (i==j)?T(1):T().
scalar_matrix<T> m(rows, columns, value); a matrix of type T of arbitrary size that has the value value everywhere.
triangular_matrix<T [, TRI, F, C]> m(size); a triangular matrix of values of type T of arbitrary size. Only the nonzero elements are stored in the given order F. ("triangular packed storage") The triangular type F defaults to lower, the orientation type F defaults to row_major.
banded_matrix<T [, F, C]> m(size1, size2, n_lower, n_upper); a banded matrix of values of type T of arbitrary size with n_lower sub diagonals and n_upper super diagonals. Only the nonzero elements are stored in the given order F. ("packed storage")
symmetric_matrix<T [, TRI, F, C]> m(size); a symmetric matrix of values of type T of arbitrary size. Only the given triangular matrix is stored in the given order F.
hermitian_matrix<T [, TRI, F, C]> m(size); a hermitian matrix of values of type T of arbitrary size. Only the given triangular matrix is stored using the order F.
sparse_matrix<T, [F, C]> m(size1, size2 [, nnz]); a sparse matrix of values of type T of arbitrary size. The container type can be either std::map<size_t, std::map<size_t, T> > or map_array<size_t, map_array<size_t, T> >.
sparse_vector_of_sparse_vector<T, [F, C]> m(size1, size2 [, nnz]); a sparse matrix of values of type T of arbitrary size.
compressed_matrix<T, [F, IB, IA, TA]> m(size1, size2 [, nnz]); a sparse matrix of values of type T of arbitrary size. The values are stored in compressed row/column storage.
coordinate_matrix<T, [F, IB, IA, TA]> m(size1, size2 [, nnz]); a sparse matrix of values of type T of arbitrary size. The values are stored in 3 parallel array as triples (i, j, value). More than one value for each pair of indices is possible, the real value is the sum of all.
generalized_vector_of_vector<T, F, A> m(size1, size2 [, nnz]); a sparse matrix of values of type T of arbitrary size. The values are stored as a vector of sparse vectors, e.g. generalized_vector_of_vector<double, row_major, unbounded_array<coordinate_vector<double> > >

Note: the default types are defined in boost/numeric/ublas/fwd.hpp.

Matrix Proxies

Definition Description
triangular_adaptor<MAT, TRI> ta(m); a triangular matrix referencing a selection of elements of the matrix m.
symmetric_adaptor<MAT, TRI> sa(m); a symmetric matrix referencing a selection of elements of the matrix m.
hermitian_adaptor<MAT, TRI> ha(m); a hermitian matrix referencing a selection of elements of the matrix m.
banded_adaptor<MAT> ba(m, n_lower, n_upper); a banded matrix referencing a selection of elements of the matrix m.
matrix_range<MAT, TRI> mr(m, range1, range2); a matrix referencing a submatrix of elements in the matrix m.
matrix_slice<MAT, TRI> ms(m, slice1, slice2); a matrix referencing a non continues submatrix of elements in the matrix m.

Special Storage Layouts

The library supports conventional dense, packed and basic sparse vector and matrix storage layouts. The description of the most common constructions of vectors and matrices comes next.

Construction Comment
vector<T,
 std::vector<T> >
  v (size)
Constructs a dense vector, storage is provided by a standard vector.
The storage layout usually is BLAS compliant.
vector<T,
 unbounded_array<T> >
  v (size)
Constructs a dense vector, storage is provided by a heap-based array.
The storage layout usually is BLAS compliant.
vector<T,
 bounded_array<T, N> >
  v (size)
Constructs a dense vector, storage is provided by a stack-based array.
The storage layout usually is BLAS compliant.
sparse_vector<T,
 std::map<std::size_t, T> >
  v (size, non_zeros)
Constructs a sparse vector, storage is provided by a standard map.
sparse_vector<T,
 map_array<std::size_t, T> >
  v (size, non_zeros)
Constructs a sparse vector, storage is provided by a map array.
matrix<T,
 row_major,
 std::vector<T> >
  m (size1, size2)
Constructs a dense matrix, orientation is row major, storage is provided by a standard vector.
matrix<T,
 column_major,
 std::vector<T> >
  m (size1, size2)
Constructs a dense matrix, orientation is column major, storage is provided by a standard vector.
The storage layout usually is BLAS compliant.
matrix<T,
 row_major,
 unbounded_array<T> >
  m (size1, size2)
Constructs a dense matrix, orientation is row major, storage is provided by a heap-based array.
matrix<T,
 column_major,
 unbounded_array<T> >
  m (size1, size2)
Constructs a dense matrix, orientation is column major, storage is provided by a heap-based array.
The storage layout usually is BLAS compliant.
matrix<T,
 row_major,
 bounded_array<T, N1 * N2> >
  m (size1, size2)
Constructs a dense matrix, orientation is row major, storage is provided by a stack-based array.
matrix<T,
 column_major,
 bounded_array<T, N1 * N2> >
  m (size1, size2)
Constructs a dense matrix, orientation is column major, storage is provided by a stack-based array.
The storage layout usually is BLAS compliant.
triangular_matrix<T,
 row_major, F, A>
  m (size)
Constructs a packed triangular matrix, orientation is row major.
triangular_matrix<T,
 column_major, F, A>
  m (size)
Constructs a packed triangular matrix, orientation is column major.
The storage layout usually is BLAS compliant.
banded_matrix<T,
 row_major, A>
  m (size1, size2, lower, upper)
Constructs a packed banded matrix, orientation is row major.
banded_matrix<T,
 column_major, A>
  m (size1, size2, lower, upper)
Constructs a packed banded matrix, orientation is column major.
The storage layout usually is BLAS compliant.
symmetric_matrix<T,
 row_major, F, A>
  m (size)
Constructs a packed symmetric matrix, orientation is row major.
symmetric_matrix<T,
 column_major, F, A>
  m (size)
Constructs a packed symmetric matrix, orientation is column major.
The storage layout usually is BLAS compliant.
hermitian_matrix<T,
 row_major, F, A>
  m (size)
Constructs a packed hermitian matrix, orientation is row major.
hermitian_matrix<T,
 column_major, F, A>
  m (size)
Constructs a packed hermitian matrix, orientation is column major.
The storage layout usually is BLAS compliant.
sparse_matrix<T,
 row_major,
 std::map<std::size_t, T> >
  m (size1, size2, non_zeros)
Constructs a sparse matrix, orientation is row major, storage is provided by a standard map.
sparse_matrix<T,
 column_major,
 std::map<std::size_t, T> >
  m (size1, size2, non_zeros)
Constructs a sparse matrix, orientation is column major, storage is provided by a standard map.
sparse_matrix<T,
 row_major,
 map_array<std::size_t, T> >
  m (size1, size2, non_zeros)
Constructs a sparse matrix, orientation is row major, storage is provided by a map array.
sparse_matrix<T,
 column_major,
 map_array<std::size_t, T> >
  m (size1, size2, non_zeros)
Constructs a sparse matrix, orientation is column major, storage is provided by a map array.
compressed_matrix<T,
 row_major>
  m (size1, size2, non_zeros)
Constructs a compressed matrix, orientation is row major.
The storage layout usually is BLAS compliant.
compressed_matrix<T,
 column_major>
  m (size1, size2, non_zeros)
Constructs a compressed matrix, orientation is column major.
The storage layout usually is BLAS compliant.
coordinate_matrix<T,
 row_major>
  m (size1, size2, non_zeros)
Constructs a coordinate matrix, orientation is row major.
The storage layout usually is BLAS compliant.
coordinate_matrix<T,
 column_major>
  m (size1, size2, non_zeros)
Constructs a coordinate matrix, orientation is column major.
The storage layout usually is BLAS compliant.

Copyright (©) 2000-2004 Joerg Walter, Mathias Koch, Gunter Winkler, Michael Stevens
Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided ``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Last revised: 2004-07-05