[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]

| Matrix Class Template Reference |
--- | --- | ---

`#include "vigra/matrix.hxx"`

Inheritance diagram for Matrix:

## Public Types

typedef Matrix< T, ALLOC > | matrix_type
typedef MultiArrayView< 2, T, UnstridedArrayTag > | view_type
typedef BaseType::value_type | value_type
typedef BaseType::pointer | pointer
typedef BaseType::const_pointer | const_pointer
typedef BaseType::reference | reference
typedef BaseType::const_reference | const_reference
typedef BaseType::difference_type | difference_type
typedef ALLOC | allocator_type
typedef BaseType::SquaredNormType | SquaredNormType
typedef BaseType::NormType | NormType

## Public Methods

| Matrix ()
| Matrix (ALLOC const &alloc)
| Matrix (const difference_type &shape, ALLOC const &alloc=allocator_type())
| Matrix (unsigned int rows, unsigned int columns, ALLOC const &alloc=allocator_type())
| Matrix (const difference_type &shape, const_reference init, allocator_type const &alloc=allocator_type())
| Matrix (unsigned int rows, unsigned int columns, const_reference init, allocator_type const &alloc=allocator_type())
| Matrix (const difference_type &shape, const_pointer init, RawArrayMemoryLayout layout=RowMajor, allocator_type const &alloc=allocator_type())
| Matrix (unsigned int rows, unsigned int columns, const_pointer init, RawArrayMemoryLayout layout=RowMajor, allocator_type const &alloc=allocator_type())
| Matrix (const Matrix &rhs)
| Matrix (const TemporaryMatrix< T, ALLOC > &rhs)
template<class U, class C> | Matrix (const MultiArrayView< 2, U, C > &rhs)
Matrix & | operator= (const Matrix &rhs)
Matrix & | operator= (const TemporaryMatrix< T, ALLOC > &rhs)
template<class U, class C> Matrix & | operator= (const MultiArrayView< 2, U, C > &rhs)
view_type | rowVector (unsigned int d) const
view_type | columnVector (unsigned int d) const
unsigned int | rowCount () const
unsigned int | columnCount () const
unsigned int | elementCount () const
bool | isSymmetric () const
value_type & | operator() (unsigned int row, unsigned int column)
value_type | operator() (unsigned int row, unsigned int column) const
SquaredNormType | squaredNorm () const
NormType | norm () const
Matrix & | transpose ()
template<class U, class C> Matrix & | operator+= (MultiArrayView< 2, U, C > const &other)
template<class U, class C> Matrix & | operator-= (MultiArrayView< 2, U, C > const &other)
Matrix & | operator *= (T other)
Matrix & | operator/= (T other)

## Detailed Description

### template<class T, class ALLOC = std::allocator<T>>
class vigra::linalg::Matrix< T, ALLOC >

Matrix class.

This is the basic class for all linear algebra computations. Matrices are strored in a column-major format, i.e. the row index is varying fastest. This is the same format as in the lapack and gmm++ libraries, so it will be easy to interface these libraries. In fact, if you need optimized high performance code, you should use them. The VIGRA linear algebra functionality is provided for smaller problems and rapid prototyping (no one wants to spend half the day installing a new library just to discover that the new algorithm idea didn't work anyway).

See also:

- Matrix functions

#include "vigra/matrix.hxx" or
#include "vigra/linear_algebra.hxx"
Namespaces: vigra and vigra::linalg

## Member Typedef Documentation

typedef ALLOC allocator_type

| the allocator type used to allocate the memory Reimplemented from MultiArray< 2, T, ALLOC >.

typedef BaseType::const_pointer const_pointer

| const pointer type Reimplemented from MultiArray< 2, T, ALLOC >.

typedef BaseType::const_reference const_reference

| const reference type (result of operator[] const) Reimplemented from MultiArray< 2, T, ALLOC >.

typedef BaseType::difference_type difference_type

| difference type (used for offsetting) Reimplemented from MultiArray< 2, T, ALLOC >.

typedef Matrix<T, ALLOC> matrix_type

| the matrix type associated with this array. Reimplemented from MultiArray< 2, T, ALLOC >.

typedef BaseType::NormType NormType

| the norm type (return type of norm(array)). Reimplemented from MultiArray< 2, T, ALLOC >.

typedef BaseType::pointer pointer

| pointer type Reimplemented from MultiArray< 2, T, ALLOC >.

typedef BaseType::reference reference

| reference type (result of operator[]) Reimplemented from MultiArray< 2, T, ALLOC >.

typedef BaseType::SquaredNormType SquaredNormType

| the squared norm type (return type of squaredNorm(array)). Reimplemented from MultiArray< 2, T, ALLOC >.

typedef BaseType::value_type value_type

| the array's value type Reimplemented from MultiArray< 2, T, ALLOC >.

typedef MultiArrayView<2, T, UnstridedArrayTag> view_type

| the view type associated with this array. Reimplemented from MultiArray< 2, T, ALLOC >.

## Constructor & Destructor Documentation

Matrix | ( |  | ) | `[inline]`

| default constructor

Matrix | ( | ALLOC const & | alloc | ) | `[inline, explicit]`

| construct with given allocator

Matrix | ( | const difference_type & | shape,
|  | ALLOC const & | alloc = allocator_type()
| ) | `[inline, explicit]`

| construct with given shape and init all elements with zero. Note that the order of the axes is `difference_type(rows, columns)` which is the opposite of the usual VIGRA convention.

Matrix | ( | unsigned int | rows,
|  | unsigned int | columns,
|  | ALLOC const & | alloc = allocator_type()
| ) | `[inline]`

| construct with given shape and init all elements with zero. Note that the order of the axes is `(rows, columns)` which is the opposite of the usual VIGRA convention.

Matrix | ( | const difference_type & | shape,
|  | const_reference | init,
|  | allocator_type const & | alloc = allocator_type()
| ) | `[inline]`

| construct with given shape and init all elements with the constant init. Note that the order of the axes is `difference_type(rows, columns)` which is the opposite of the usual VIGRA convention.

Matrix | ( | unsigned int | rows,
|  | unsigned int | columns,
|  | const_reference | init,
|  | allocator_type const & | alloc = allocator_type()
| ) | `[inline]`

| construct with given shape and init all elements with the constant init. Note that the order of the axes is `(rows, columns)` which is the opposite of the usual VIGRA convention.

Matrix | ( | const difference_type & | shape,
|  | const_pointer | init,
|  | RawArrayMemoryLayout | layout = RowMajor,
|  | allocator_type const & | alloc = allocator_type()
| ) | `[inline]`

| construct with given shape and copy data from C-style array init. Unless layout is `ColumnMajor`, the elements in this array are assumed to be given in row-major order (the C standard order) and will automatically be converted to the required column-major format. Note that the order of the axes is `difference_type(rows, columns)` which is the opposite of the usual VIGRA convention.

Matrix | ( | unsigned int | rows,
|  | unsigned int | columns,
|  | const_pointer | init,
|  | RawArrayMemoryLayout | layout = RowMajor,
|  | allocator_type const & | alloc = allocator_type()
| ) | `[inline]`

| construct with given shape and copy data from C-style array init. Unless layout is `ColumnMajor`, the elements in this array are assumed to be given in row-major order (the C standard order) and will automatically be converted to the required column-major format. Note that the order of the axes is `(rows, columns)` which is the opposite of the usual VIGRA convention.

Matrix | ( | const Matrix< T, ALLOC > & | rhs | ) | `[inline]`

| copy constructor. Allocates new memory and copies tha data.

Matrix | ( | const TemporaryMatrix< T, ALLOC > & | rhs | ) | `[inline]`

construct from temporary matrix, which looses its data.

This operation is equivalent to

                    TemporaryMatrix<T> temp = ...;

                    Matrix<T> m;
                    m.swap(temp);

Matrix | ( | const MultiArrayView< 2, U, C > & | rhs | ) | `[inline]`

| construct from a MultiArrayView. Allocates new memory and copies tha data. rhs is assumed to be in column-major order already.

## Member Function Documentation

unsigned int columnCount | ( |  | ) | const`[inline]`

| number of columns (width) of the matrix.

view_type columnVector | ( | unsigned int | d | ) | const`[inline]`

| Create a matrix view that represents the column vector of column d.

unsigned int elementCount | ( |  | ) | const`[inline]`

| number of elements (width*height) of the matrix. Reimplemented from MultiArrayView< N, T >.

bool isSymmetric | ( |  | ) | const`[inline]`

| check whether the matrix is symmetric.

NormType norm | ( |  | ) | const`[inline]`

| Frobenius norm. Root of sum of squares of the matrix elements. Reimplemented from MultiArrayView< N, T >.

Matrix< T, ALLOC > & operator *= | ( | T | other | ) |

| scalar multiply this with other

value_type operator() | ( | unsigned int | row,
|  | unsigned int | column
| ) | const

| read access to matrix element `(row, column)`. Note that the order of the argument is the opposite of the usual VIGRA convention due to column-major matrix order.

value_type& operator() | ( | unsigned int | row,
|  | unsigned int | column
| ) |

| read/write access to matrix element `(row, column)`. Note that the order of the argument is the opposite of the usual VIGRA convention due to column-major matrix order.

Matrix< T, ALLOC > & operator+= | ( | MultiArrayView< 2, U, C > const & | other | ) |

| add other to this (sizes must match).

Matrix< T, ALLOC > & operator-= | ( | MultiArrayView< 2, U, C > const & | other | ) |

| subtract other from this (sizes must match).

Matrix< T, ALLOC > & operator/= | ( | T | other | ) |

| scalar devide this by other

Matrix& operator= | ( | const MultiArrayView< 2, U, C > & | rhs | ) | `[inline]`

| assignment from arbitrary 2-dimensional MultiArrayView. If the size of rhs is the same as the matrix's old size, only the data are copied. Otherwise, new storage is allocated, which invalidates all objects (array views, iterators) depending on the matrix. rhs is assumed to be in column-major order already.

Matrix& operator= | ( | const TemporaryMatrix< T, ALLOC > & | rhs | ) | `[inline]`

| assign a temporary matrix. This is implemented by swapping the data between the two matrices, so that all depending objects (array views, iterators) ar invalidated.

Matrix& operator= | ( | const Matrix< T, ALLOC > & | rhs | ) | `[inline]`

| assignment. If the size of rhs is the same as the matrix's old size, only the data are copied. Otherwise, new storage is allocated, which invalidates all objects (array views, iterators) depending on the matrix.

unsigned int rowCount | ( |  | ) | const`[inline]`

| number of rows (height) of the matrix.

view_type rowVector | ( | unsigned int | d | ) | const`[inline]`

| Create a matrix view that represents the row vector of row d.

SquaredNormType squaredNorm | ( |  | ) | const`[inline]`

| squared Frobenius norm. Sum of squares of the matrix elements. Reimplemented from MultiArrayView< N, T >.

Matrix< T, ALLOC > & transpose | ( |  | ) |

| transpose matrix in-place (precondition: matrix must be square)

The documentation for this class was generated from the following file:

- vigra/matrix.hxx

© Ullrich Köthe (koethe@informatik.uni-hamburg.de) Cognitive Systems Group, University of Hamburg, Germany | html generated using doxygen and Python VIGRA 1.4.0 (21 Dec 2005)