Matrix

Matrix

Description

The templated class matrix<T, F, A> is the base container adaptor for dense matrices. For a (m x n)-dimensional matrix and 0 <= i < m, 0 <= j < n every element mi, j is mapped to the (i x n + j)-th element of the container for row major orientation or the (i + j x m)-th element of the container for column major orientation.

Example

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

int main () {
    using namespace boost::numeric::ublas;
    matrix<double> m (3, 3);
    for (unsigned i = 0; i < m.size1 (); ++ i)
        for (unsigned j = 0; j < m.size2 (); ++ j)
            m (i, j) = 3 * i + j;
    std::cout << m << std::endl;
}

Definition

Defined in the header matrix.hpp.

Template parameters

Parameter Description Default
T The type of object stored in the matrix.
F Functor describing the storage organization. [1] row_major
A The type of the Storage array. [2] unbounded_array<T>

Model of

Matrix .

Type requirements

None, except for those imposed by the requirements of Matrix .

Public base classes

matrix_container<matrix<T, F, A> >

Members

Member Description
matrix () Allocates an uninitialized matrix that holds zero rows of zero elements.
matrix (size_type size1, size_type size2) Allocates an uninitialized matrix that holds size1 rows of size2 elements.
matrix (const matrix &m) The copy constructor.
template<class AE>
matrix (const matrix_expression<AE> &ae)
The extended copy constructor.
void resize (size_type size1, size_type size2, bool preserve = true) Reallocates a matrix to hold size1 rows of size2 elements. The existing elements of the matrix are preseved when specified.
size_type size1 () const Returns the number of rows.
size_type size2 () const Returns the number of columns.
const array_type& data () const
array_type& data ()
const_reference operator () (size_type i, size_type j) const Returns a const reference of the j -th element in the i-th row.
reference operator () (size_type i, size_type j) Returns a reference of the j-th element in the i-th row.
matrix &operator = (const matrix &m) The assignment operator.
matrix &assign_temporary (matrix &m) Assigns a temporary. May change the matrix m.
template<class AE>
matrix &operator = (const matrix_expression<AE> &ae)
The extended assignment operator.
template<class AE>
matrix &assign (const matrix_expression<AE> &ae)
Assigns a matrix expression to the matrix. Left and right hand side of the assignment should be independent.
template<class AE>
matrix &operator += (const matrix_expression<AE> &ae)
A computed assignment operator. Adds the matrix expression to the matrix.
template<class AE>
matrix &plus_assign (const matrix_expression<AE> &ae)
Adds a matrix expression to the matrix. Left and right hand side of the assignment should be independent.
template<class AE>
matrix &operator -= (const matrix_expression<AE> &ae)
A computed assignment operator. Subtracts the matrix expression from the matrix.
template<class AE>
matrix &minus_assign (const matrix_expression<AE> &ae)
Subtracts a matrix expression from the matrix. Left and right hand side of the assignment should be independent.
template<class AT>
matrix &operator *= (const AT &at)
A computed assignment operator. Multiplies the matrix with a scalar.
template<class AT>
matrix &operator /= (const AT &at)
A computed assignment operator. Divides the matrix through a scalar.
void swap (matrix &m) Swaps the contents of the matrices.
void insert_element (size_type i, size_type j, const_reference t) Inserts the value t at the j-th element of the i-th row.
void erase_element (size_type i, size_type j) Erases the value at the j-th element of the i-th row.
void clear () Clears the matrix.
const_iterator1 begin1 () const Returns a const_iterator1 pointing to the beginning of the matrix.
const_iterator1 end1 () const Returns a const_iterator1 pointing to the end of the matrix.
iterator1 begin1 () Returns a iterator1 pointing to the beginning of the matrix.
iterator1 end1 () Returns a iterator1 pointing to the end of the matrix.
const_iterator2 begin2 () const Returns a const_iterator2 pointing to the beginning of the matrix.
const_iterator2 end2 () const Returns a const_iterator2 pointing to the end of the matrix.
iterator2 begin2 () Returns a iterator2 pointing to the beginning of the matrix.
iterator2 end2 () Returns a iterator2 pointing to the end of the matrix.
const_reverse_iterator1 rbegin1 () const Returns a const_reverse_iterator1 pointing to the beginning of the reversed matrix.
const_reverse_iterator1 rend1 () const Returns a const_reverse_iterator1 pointing to the end of the reversed matrix.
reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to the beginning of the reversed matrix.
reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to the end of the reversed matrix.
const_reverse_iterator2 rbegin2 () const Returns a const_reverse_iterator2 pointing to the beginning of the reversed matrix.
const_reverse_iterator2 rend2 () const Returns a const_reverse_iterator2 pointing to the end of the reversed matrix.
reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to the beginning of the reversed matrix.
reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to the end of the reversed matrix.

Notes

[1] Supported parameters for the storage organization are row_major and column_major.

[2] Common parameters for the storage array are unbounded_array<T> , bounded_array<T> and std::vector<T> .

Identity Matrix

Description

The templated class identity_matrix<T> represents identity matrices. For a (m x n)-dimensional identity matrix and 0 <= i < m, 0 <= j < n holds idi, j = 0, if i <> j, and idi, i= 1.

Example

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

int main () {
    using namespace boost::numeric::ublas;
    identity_matrix<double> m (3);
    std::cout << m << std::endl;
}

Definition

Defined in the header matrix.hpp.

Template parameters

Parameter Description Default
T The type of object stored in the matrix. int

Model of

Matrix .

Type requirements

None, except for those imposed by the requirements of Matrix .

Public base classes

matrix_container<identity_matrix<T> >

Members

Member Description
identity_matrix () Constructs an identity_matrix that holds zero rows of zero elements.
identity_matrix (size_type size) Constructs an identity_matrix that holds size rows of size elements.
identity_matrix (const identity_matrix &m) The copy constructor.
void resize (size_type size, bool preserve = true) Resizes a identity_matrix to hold size rows of size elements. Therefore the existing elements of the itendity_matrix are always preseved.
size_type size1 () const Returns the number of rows.
size_type size2 () const Returns the number of columns.
const_reference operator () (size_type i, size_type j) const Returns the value of the j-th element in the i-th row.
identity_matrix &operator = (const identity_matrix &m) The assignment operator.
identity_matrix &assign_temporary (identity_matrix &m) Assigns a temporary. May change the identity matrix m .
void swap (identity_matrix &m) Swaps the contents of the identity matrices.
const_iterator1 begin1 () const Returns a const_iterator1 pointing to the beginning of the identity_matrix.
const_iterator1 end1 () const Returns a const_iterator1 pointing to the end of the identity_matrix.
const_iterator2 begin2 () const Returns a const_iterator2 pointing to the beginning of the identity_matrix.
const_iterator2 end2 () const Returns a const_iterator2 pointing to the end of the identity_matrix.
const_reverse_iterator1 rbegin1 () const Returns a const_reverse_iterator1 pointing to the beginning of the reversed identity_matrix.
const_reverse_iterator1 rend1 () const Returns a const_reverse_iterator1 pointing to the end of the reversed identity_matrix.
const_reverse_iterator2 rbegin2 () const Returns a const_reverse_iterator2 pointing to the beginning of the reversed identity_matrix.
const_reverse_iterator2 rend2 () const Returns a const_reverse_iterator2 pointing to the end of the reversed identity_matrix.

Zero Matrix

Description

The templated class zero_matrix<T> represents zero matrices. For a (m x n)-dimensional zero matrix and 0 <= i < m, 0 <= j < n holds zi, j = 0.

Example

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

int main () {
    using namespace boost::numeric::ublas;
    zero_matrix<double> m (3, 3);
    std::cout << m << std::endl;
}

Definition

Defined in the header matrix.hpp.

Template parameters

Parameter Description Default
T The type of object stored in the matrix. int

Model of

Matrix .

Type requirements

None, except for those imposed by the requirements of Matrix .

Public base classes

matrix_container<zero_matrix<T> >

Members

Member Description
zero_matrix () Constructs a zero_matrix that holds zero rows of zero elements.
zero_matrix (size_type size1, size_type size2) Constructs a zero_matrix that holds size1 rows of size2 elements.
zero_matrix (const zero_matrix &m) The copy constructor.
void resize (size_type size1, size_type size2, bool preserve = true) Resizes a zero_matrix to hold size1 rows of size2 elements. Therefore the existing elements of the zero_matrix are always preseved.
size_type size1 () const Returns the number of rows.
size_type size2 () const Returns the number of columns.
const_reference operator () (size_type i, size_type j) const Returns the value of the j-th element in the i-th row.
zero_matrix &operator = (const zero_matrix &m) The assignment operator.
zero_matrix &assign_temporary (zero_matrix &m) Assigns a temporary. May change the zero matrix m .
void swap (zero_matrix &m) Swaps the contents of the zero matrices.
const_iterator1 begin1 () const Returns a const_iterator1 pointing to the beginning of the zero_matrix.
const_iterator1 end1 () const Returns a const_iterator1 pointing to the end of the zero_matrix.
const_iterator2 begin2 () const Returns a const_iterator2 pointing to the beginning of the zero_matrix.
const_iterator2 end2 () const Returns a const_iterator2 pointing to the end of the zero_matrix.
const_reverse_iterator1 rbegin1 () const Returns a const_reverse_iterator1 pointing to the beginning of the reversed zero_matrix.
const_reverse_iterator1 rend1 () const Returns a const_reverse_iterator1 pointing to the end of the reversed zero_matrix.
const_reverse_iterator2 rbegin2 () const Returns a const_reverse_iterator2 pointing to the beginning of the reversed zero_matrix.
const_reverse_iterator2 rend2 () const Returns a const_reverse_iterator2 pointing to the end of the reversed zero_matrix.

Scalar Matrix

Description

The templated class scalar_matrix<T> represents scalar matrices. For a (m x n)-dimensional scalar matrix and 0 <= i < m, 0 <= j < n holds zi, j = s.

Example

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

int main () {
    using namespace boost::numeric::ublas;
    scalar_matrix<double> m (3, 3);
    std::cout << m << std::endl;
}

Definition

Defined in the header matrix.hpp.

Template parameters

Parameter Description Default
T The type of object stored in the matrix. int

Model of

Matrix .

Type requirements

None, except for those imposed by the requirements of Matrix .

Public base classes

matrix_container<scalar_matrix<T> >

Members

Member Description
scalar_matrix () Constructs a scalar_matrix that holds scalar rows of zero elements.
scalar_matrix (size_type size1, size_type size2, const value_type &value) Constructs a scalar_matrix that holds size1 rows of size2 elements each of the specified value.
scalar_matrix (const scalar_matrix &m) The copy constructor.
void resize (size_type size1, size_type size2, bool preserve = true) Resizes a scalar_matrix to hold size1 rows of size2 elements. Therefore the existing elements of the scalar_matrix are always preseved.
size_type size1 () const Returns the number of rows.
size_type size2 () const Returns the number of columns.
const_reference operator () (size_type i, size_type j) const Returns the value of the j-th element in the i-th row.
scalar_matrix &operator = (const scalar_matrix &m) The assignment operator.
scalar_matrix &assign_temporary (scalar_matrix &m) Assigns a temporary. May change the scalar matrix m .
void swap (scalar_matrix &m) Swaps the contents of the scalar matrices.
const_iterator1 begin1 () const Returns a const_iterator1 pointing to the beginning of the scalar_matrix.
const_iterator1 end1 () const Returns a const_iterator1 pointing to the end of the scalar_matrix.
const_iterator2 begin2 () const Returns a const_iterator2 pointing to the beginning of the scalar_matrix.
const_iterator2 end2 () const Returns a const_iterator2 pointing to the end of the scalar_matrix.
const_reverse_iterator1 rbegin1 () const Returns a const_reverse_iterator1 pointing to the beginning of the reversed scalar_matrix.
const_reverse_iterator1 rend1 () const Returns a const_reverse_iterator1 pointing to the end of the reversed scalar_matrix.
const_reverse_iterator2 rbegin2 () const Returns a const_reverse_iterator2 pointing to the beginning of the reversed scalar_matrix.
const_reverse_iterator2 rend2 () const Returns a const_reverse_iterator2 pointing to the end of the reversed scalar_matrix.

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
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.