linbox
Data Structures | Public Types | Public Member Functions
BlasMatrix< _Element > Class Template Reference

Dense matrix representation. More...

#include <blas-matrix.h>

Data Structures

class  IndexedIterator
 Indexed Iterator. More...

Public Types

typedef _Element Element
 Element type.
typedef RawVector< Element >::Dense Rep
 Actually a std::vector<Element> (or alike.)
typedef Rep::pointer pointer
 pointer type to elements
typedef const pointer const_pointer
 const pointer type
typedef BlasMatrix< ElementSelf_t
 Self type.

Public Member Functions

 BlasMatrix ()
 Allocates a new $ 0 \times 0$ matrix.
template<class Field >
 BlasMatrix (MatrixStream< Field > &ms)
 Constructor from a matrix stream.
template<class Matrix >
 BlasMatrix (const Matrix &A)
 Generic copy constructor from either a blackbox or a matrix container.
template<class Matrix >
 BlasMatrix (const Matrix &A, const size_t i0, const size_t j0, const size_t m, const size_t n)
 Generic copy constructor from either a blackbox or a matrix container (allow submatrix).
template<class _Matrix , class _Field >
 BlasMatrix (const _Matrix &A, const _Field &F)
 Constructor.
 BlasMatrix (const BlasMatrix< Element > &A)
 Copy Constructor of a matrix (copying data).
 BlasMatrix (const std::vector< Element > &v, size_t m, size_t n)
 Create a BlasMatrix from a vector of elements.
 BlasMatrix (const _Element *v, size_t m, size_t n)
 Create a BlasMatrix from an array of elements.
 ~BlasMatrix ()
 Destructor.
BlasMatrix< Element > & operator= (const BlasMatrix< Element > &A)
 operator = (copying data)
size_t rowdim () const
 Get the number of rows in the matrix.
size_t coldim () const
 Get the number of columns in the matrix.
size_t getStride () const
  Get the stride of the matrix.
size_t & getWriteStride ()
 Get a reference to the stride of the matrix.
void resize (size_t m, size_t n, const Element &val=Element())
 Resize the matrix to the given dimensions.
pointer getPointer () const
  
pointergetWritePointer ()
  
void setEntry (size_t i, size_t j, const Element &a_ij)
 Set the entry at the (i, j) position to a_ij.
ElementrefEntry (size_t i, size_t j)
 Get a writeable reference to the entry in the (i, j) position.
const ElementgetEntry (size_t i, size_t j) const
 Get a read-only reference to the entry in the (i, j) position.
ElementgetEntry (Element &x, size_t i, size_t j) const
 Copy the (i, j) entry into x, and return a reference to x.
BlasMatrix< Elementtranspose (BlasMatrix< Element > &tM) const
 Creates a transposed matrix of *this.
void transpose ()
 Transpose (inplace).
void reverseRows ()
 Reverse the rows of a matrix.
void reverseCols ()
 Reverse the columns of a matrix.
void reverse ()
 Reverse the rows/columns of a matrix.
template<class Field >
std::istream & read (std::istream &file, const Field &F)
 Read the matrix from an input stream.
template<class Field >
std::ostream & write (std::ostream &os, const Field &F, bool mapleFormat=true) const
 Write the matrix to an output stream.
std::ostream & write (std::ostream &os, bool mapleFormat=true) const
 Write brutally the matrix to an output stream.
template<class Vector >
Vector & columnDensity (Vector &v) const
 Compute column density.
template<class T >
 BlasMatrix (unsigned int m, T n)
 Allocates a new $ m \times n$ matrix.
template<class T >
 BlasMatrix (long m, T n)
 Allocates a new $ m \times n$ matrix.
template<class T >
 BlasMatrix (unsigned long m, T n)
template<class T >
 BlasMatrix (int m, T n)
 Allocates a new $ m \times n$ matrix.
template<class T >
 BlasMatrix (Integer &m, T n)
Raw Indexed iterator

Like the raw iterator, the indexed iterator is a method for accessing all entries in the matrix in some unspecified order.

At each position of the the indexed iterator, it also provides the row and column indices of the currently referenced entry. This is provided through it's rowIndex() and colIndex() functions.

IndexedIterator IndexedBegin ()
IndexedIterator IndexedEnd ()
ConstIndexedIterator IndexedBegin () const
ConstIndexedIterator IndexedEnd () const
Row operator[] (size_t i)
 Retrieve a reference to a row.
ConstRow operator[] (size_t i) const
 Retrieve a reference to a row.

Column of rows iterator

The column of rows iterator traverses the rows of the matrix in ascending order.

Dereferencing the iterator yields a row vector in dense format

typedef Subvector< typename
Rep::iterator, typename
Rep::const_iterator > 
Row
typedef Subvector< typename
Rep::const_iterator > 
ConstRow
RowIterator rowBegin ()
RowIterator rowEnd ()
ConstRowIterator rowBegin () const
ConstRowIterator rowEnd () const

Row of columns iterator

The row of columns iterator traverses the columns of the matrix in ascending order.

Dereferencing the iterator yields a column vector in dense format

typedef Subvector< Subiterator
< typename Rep::iterator > > 
Col
typedef Subvector< Subiterator
< typename Rep::const_iterator > > 
ConstCol
typedef Col Column
typedef ConstCol ConstColumn
ColIterator colBegin ()
ColIterator colEnd ()
ConstColIterator colBegin () const
ConstColIterator colEnd () const

Iterator

The iterator is a method for accessing all entries in the matrix in some unspecified order.

This can be used, e.g. to reduce all matrix entries modulo a prime before passing the matrix into an algorithm.

typedef Rep::iterator Iterator
typedef Rep::const_iterator ConstIterator
Iterator Begin ()
Iterator End ()
ConstIterator Begin () const
ConstIterator End () const

Detailed Description

template<class _Element>
class LinBox::BlasMatrix< _Element >

Dense matrix representation.

A BlasMatrix is a matrix of _Element, with the structure of BLAS matrices. It is basically a vector of _Element. In the Mother model, a BlasMatrix is allocated by the user.

Examples:
examples/checksolve.C, and examples/echelon.C.

Constructor & Destructor Documentation

BlasMatrix ( unsigned int  m,
n 
)

Allocates a new $ m \times n$ matrix.

Parameters:
mrows
ncols
BlasMatrix ( long  m,
n 
)

Allocates a new $ m \times n$ matrix.

Parameters:
mrows
ncols
BlasMatrix ( unsigned long  m,
n 
)
BlasMatrix ( int  m,
n 
)

Allocates a new $ m \times n$ matrix.

Parameters:
mrows
ncols
BlasMatrix ( Integer &  m,
n 
)
Todo:
check m,n not too big ?
BlasMatrix ( MatrixStream< Field > &  ms)

Constructor from a matrix stream.

Parameters:
msmatrix stream.
BlasMatrix ( const Matrix &  A)

Generic copy constructor from either a blackbox or a matrix container.

Parameters:
Amatrix to be copied
BlasMatrix ( const Matrix &  A,
const size_t  i0,
const size_t  j0,
const size_t  m,
const size_t  n 
)

Generic copy constructor from either a blackbox or a matrix container (allow submatrix).

Parameters:
Amatrix to be copied
i0
j0
mrows
ncolumns
BlasMatrix ( const _Matrix &  A,
const _Field &  F 
)

Constructor.

Parameters:
Amatrix to be copied
FField
BlasMatrix ( const BlasMatrix< Element > &  A)

Copy Constructor of a matrix (copying data).

Parameters:
Amatrix to be copied.
BlasMatrix ( const std::vector< Element > &  v,
size_t  m,
size_t  n 
)

Create a BlasMatrix from a vector of elements.

Parameters:
Amatrix to be copied.
BlasMatrix ( const _Element *  v,
size_t  m,
size_t  n 
)

Create a BlasMatrix from an array of elements.

Parameters:
Amatrix to be copied.

Member Function Documentation

size_t rowdim ( ) const

Get the number of rows in the matrix.

Returns:
Number of rows in matrix

Reimplemented in BlasBlackbox< _Field >, BlasBlackbox< Modular< double > >, and BlasBlackbox< Domain >.

size_t coldim ( ) const

Get the number of columns in the matrix.

Returns:
Number of columns in matrix

Reimplemented in BlasBlackbox< _Field >, BlasBlackbox< Modular< double > >, and BlasBlackbox< Domain >.

size_t & getWriteStride ( )

Get a reference to the stride of the matrix.

Modify stride this way.

void resize ( size_t  m,
size_t  n,
const Element val = Element() 
)

Resize the matrix to the given dimensions.

The state of the matrix's entries after a call to this method is undefined

Parameters:
mNumber of rows
nNumber of columns
val
void setEntry ( size_t  i,
size_t  j,
const Element a_ij 
)

Set the entry at the (i, j) position to a_ij.

Parameters:
iRow number, 0...rowdim () - 1
jColumn number 0...coldim () - 1
a_ijElement to set
_Element & refEntry ( size_t  i,
size_t  j 
)

Get a writeable reference to the entry in the (i, j) position.

Parameters:
iRow index of entry
jColumn index of entry
Returns:
Reference to matrix entry
const _Element & getEntry ( size_t  i,
size_t  j 
) const

Get a read-only reference to the entry in the (i, j) position.

Parameters:
iRow index
jColumn index
Returns:
Const reference to matrix entry
_Element & getEntry ( Element x,
size_t  i,
size_t  j 
) const

Copy the (i, j) entry into x, and return a reference to x.

This form is more in the Linbox style and is provided for interface compatibility with other parts of the library

Parameters:
xElement in which to store result
iRow index
jColumn index
Returns:
Reference to x
BlasMatrix< _Element > transpose ( BlasMatrix< Element > &  tM) const

Creates a transposed matrix of *this.

Parameters:
[in]tM
Returns:
the transposed matrix of this.
void transpose ( )

Transpose (inplace).

If rows and columns agree, we can transpose inplace.

void reverseRows ( )

Reverse the rows of a matrix.

This is done inplace. Let J=antiDiag(1) (or the matrix of the reverse permutation or the matrix (i,j) = (i+j+1==m)). Then, we compute A <- J.A;

void reverseCols ( )

Reverse the columns of a matrix.

This is done inplace. This is A <- J.A

void reverse ( )

Reverse the rows/columns of a matrix.

This is done inplace. This is A <- J.A.J

std::istream & read ( std::istream &  file,
const Field &  F 
)

Read the matrix from an input stream.

The stream is in SMS or DENSE format

Parameters:
fileInput stream from which to read
FField over which to read
std::ostream & write ( std::ostream &  os,
const Field &  F,
bool  mapleFormat = true 
) const

Write the matrix to an output stream.

Todo:
factorise writing matrices code.
Parameters:
osOutput stream to which to write
FField over which to write
mapleFormatwrite in Maple format ?
Warning:
matrix base does not provide this field(), maybe should? _M.field ().write (os, *pe); os << *pe; fixed by using extra field
std::ostream & write ( std::ostream &  os,
bool  mapleFormat = true 
) const

Write brutally the matrix to an output stream.

This a raw version of write(os,F) (no field is given).

Parameters:
osOutput stream to which to write
mapleFormatwrite in maple format ?
BlasMatrix< _Element >::Row operator[] ( size_t  i)

Retrieve a reference to a row.

Since rows may also be indexed, this allows A[i][j] notation to be used.

Parameters:
iRow index
BlasMatrix< _Element >::ConstRow operator[] ( size_t  i) const

Retrieve a reference to a row.

Since rows may also be indexed, this allows A[i][j] notation to be used.

Parameters:
iRow index
Vector & columnDensity ( Vector &  v) const

Compute column density.

Parameters:
v

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