yat  0.20.3pre
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Related Functions | List of all members
theplu::yat::utility::MatrixView Class Reference

Interface to GSL matrix_view. More...

#include <yat/utility/MatrixView.h>

Inheritance diagram for theplu::yat::utility::MatrixView:
theplu::yat::utility::MatrixMutable theplu::yat::utility::MatrixBase theplu::yat::utility::BasicMatrix< MatrixBase >

Public Types

typedef double & reference
 
typedef Container2DIterator< MatrixMutable, double, double & > iterator
 
typedef StrideIterator< double * > column_iterator
 
typedef StrideIterator< double * > row_iterator
 
typedef double value_type
 
typedef const double & const_reference
 
typedef Container2DIterator< const MatrixBase, const double, const double & > const_iterator
 
typedef StrideIterator< const double * > const_column_iterator
 
typedef StrideIterator< const double * > const_row_iterator
 
typedef MatrixBase derived_type
 

Public Member Functions

 MatrixView (void)
 
 MatrixView (MatrixView &other)
 
 MatrixView (MatrixMutable &other)
 
 MatrixView (MatrixMutable &other, size_t row_offset, size_t col_offset, size_t rows, size_t columns)
 
 MatrixView (gsl_matrix *m)
 
 MatrixView (double *p, size_t rows, size_t cols)
 
 MatrixView (double *p, size_t rows, size_t cols, size_t tda)
 
 ~MatrixView (void)
 Destructor.
 
gsl_matrix * gsl_matrix_p (void)
 
const gsl_matrix * gsl_matrix_p (void) const
 
MatrixViewoperator= (const MatrixView &other)
 
 MatrixView (proxy p)
 create a MatrixView from an internal proxy class.
 
 operator proxy ()
 
MatrixMutableoperator= (const MatrixMutable &other)
 The assignment operator. More...
 
MatrixMutableoperator= (const MatrixBase &other)
 The assignment operator.
 
template<class T >
MatrixMutableoperator= (const MatrixExpression< T > &rhs)
 
MatrixMutableoperator= (MatrixMutable &&other)
 Move assignment operator.
 
template<class T >
MatrixMutableoperator= (MatrixExpression< T > &&rhs)
 
void all (const double value)
 
iterator begin (void)
 
const_iterator begin (void) const
 
const_iterator begin (void) const
 
column_iterator begin_column (size_t i)
 
const_column_iterator begin_column (size_t i) const
 
const_column_iterator begin_column (size_t i) const
 
row_iterator begin_row (size_t i)
 
const_row_iterator begin_row (size_t i) const
 
const_row_iterator begin_row (size_t i) const
 
VectorView column_view (size_t i)
 
void div (const MatrixBase &b)
 
iterator end (void)
 
const_iterator end (void) const
 
const_iterator end (void) const
 
column_iterator end_column (size_t i)
 
const_column_iterator end_column (size_t i) const
 
const_column_iterator end_column (size_t i) const
 
row_iterator end_row (size_t i)
 
const_row_iterator end_row (size_t i) const
 
const_row_iterator end_row (size_t i) const
 
virtual const gsl_matrix * gsl_matrix_p (void) const=0
 
void mul (const MatrixBase &b)
 
VectorView row_view (size_t)
 
void swap_columns (const size_t i, const size_t j)
 Swap columns i and j. More...
 
void swap_rowcol (const size_t i, const size_t j)
 Swap row i and column j. More...
 
void swap_rows (const size_t i, const size_t j)
 Swap rows i and j. More...
 
double & operator() (size_t row, size_t column)
 Element access operator. More...
 
const double & operator() (size_t row, size_t column) const
 Element access operator. More...
 
const MatrixMutableoperator+= (const MatrixBase &b)
 Add and assign operator. More...
 
template<class T >
MatrixMutableoperator+= (const MatrixExpression< T > &rhs)
 Addition and assign operator. More...
 
const MatrixMutableoperator+= (const double d)
 Add and assign operator. More...
 
const MatrixMutableoperator-= (const MatrixBase &)
 Subtract and assign operator. More...
 
template<class T >
MatrixMutableoperator-= (const MatrixExpression< T > &rhs)
 Subtraction and assign operator. More...
 
const MatrixMutableoperator-= (const double d)
 Subtract and assign operator. More...
 
const MatrixMutableoperator*= (double d)
 Multiply and assignment operator. More...
 
const VectorConstView column_const_view (size_t) const
 
size_t columns (void) const
 
bool equal (const MatrixBase &, const double precision=0) const
 Check whether matrices are equal within a user defined precision, set by precision. More...
 
size_t rows (void) const
 
const VectorConstView row_const_view (size_t) const
 
bool operator== (const MatrixBase &other) const
 Comparison operator. Takes squared time. More...
 
bool operator!= (const MatrixBase &other) const
 Comparison operator. Takes squared time. More...
 

Protected Member Functions

void copy_assign (const gsl_matrix *rhs)
 
void move_assign (MatrixMutable &&rhs)
 
void move_assign (gsl_matrix *&&rhs)
 
void copy_assign (const MatrixBase &other)
 Behaves like operator=(const MatrixBase&)
 
virtual void copy_assign (const gsl_matrix *rhs)=0
 Behaves like operator=(const MatrixBase&)
 
void copy_assign (const MatrixBase &other)
 Behaves like operator=(const MatrixBase&)
 
gsl_matrix * create_gsl_matrix_copy (void) const
 Create a new copy of the internal GSL matrix. More...
 

Protected Attributes

gsl_matrix * blas_result_
 

Related Functions

(Note that these are not member functions.)

void swap (MatrixMutable &, MatrixMutable &)
 Exchange all elements between the matrices by copying. More...
 
void minmax_index (const MatrixBase &M, std::pair< size_t, size_t > &min, std::pair< size_t, size_t > &max)
 Locate the maximum and minimum element in the matrix, M. More...
 
std::ostream & operator<< (std::ostream &s, const MatrixBase &)
 The output operator for the MatrixBase class.
 

Detailed Description

Interface to GSL matrix_view.

Class provides a way to have a mutable view into a Matrix. See GSL documentation (gsl_matrix_view) for design details. A view can be a view of the entire Matrix or a contiguous sub-matrix defined by the left- and right columns as well as the upper and lower rows.

The semantics of the class is very much like a mutable reference. That means that assignment implies that the underlying data is changed and in the assignment operators and the size of left and tight-hand-side must be the same. It is not possible to reassign which Matrix the MatrixView views into, again similar to how a reference cannot be reassigned to reference another object.

Since
New in yat 0.20

Member Typedef Documentation

◆ column_iterator

Mutable iterator that iterates over one column

◆ const_column_iterator

Read-only iterator that iterates over one column

◆ const_iterator

typedef Container2DIterator<const MatrixBase, const double, const double&> theplu::yat::utility::MatrixBase::const_iterator
inherited

Read-only iterator that iterates over all elements

◆ const_reference

typedef const double& theplu::yat::utility::MatrixBase::const_reference
inherited

const_reference type is const double&

Since
New in yat 0.5

◆ const_row_iterator

Read-only iterator that iterates over one row

◆ derived_type

Class that inherits from BasicMatrix

◆ iterator

Mutable iterator that iterates over all elements

◆ reference

reference type is double&

Since
New in yat 0.5

◆ row_iterator

Mutable iterator that iterates over one row

◆ value_type

value_type is double

Since
New in yat 0.5

Constructor & Destructor Documentation

◆ MatrixView() [1/7]

theplu::yat::utility::MatrixView::MatrixView ( void  )

Default constructor. Constructed view behaves like viewing into an empty Matrix.

◆ MatrixView() [2/7]

theplu::yat::utility::MatrixView::MatrixView ( MatrixView other)

Copy constructor. To keep const correctness, the argument cannot be const here, parallel with how one cannot create a Matrix& from a const Matrix.

◆ MatrixView() [3/7]

theplu::yat::utility::MatrixView::MatrixView ( MatrixMutable other)
explicit

Create a view into a matrix other.

◆ MatrixView() [4/7]

theplu::yat::utility::MatrixView::MatrixView ( MatrixMutable other,
size_t  row_offset,
size_t  col_offset,
size_t  rows,
size_t  columns 
)

for (size_t i=0; i<matrix.rows(); ++i)

Create view into sub-matrix into other.

view(0,) will view into other(row_offset, col_offset) and have dimension row x column.

◆ MatrixView() [5/7]

theplu::yat::utility::MatrixView::MatrixView ( gsl_matrix *  m)
explicit

Create a view into m.

◆ MatrixView() [6/7]

theplu::yat::utility::MatrixView::MatrixView ( double *  p,
size_t  rows,
size_t  cols 
)

Create a view with rows rows and cols columns. Data are stored in row-major order such that p[1] correspond to view(0,1).

◆ MatrixView() [7/7]

theplu::yat::utility::MatrixView::MatrixView ( double *  p,
size_t  rows,
size_t  cols,
size_t  tda 
)

Create a view with rows rows and cols columns. The physical row dimension is tda, i.e., the first element on the second row is p[tda].

Member Function Documentation

◆ all()

void theplu::yat::utility::MatrixMutable::all ( const double  value)
inherited

Set all elements to value.

◆ begin() [1/3]

const_iterator theplu::yat::utility::MatrixBase::begin
inherited

Iterator iterates along a row. When end of row is reached it jumps to beginning of next row.

Returns
const_iterator pointing to upper-left element.

◆ begin() [2/3]

iterator theplu::yat::utility::MatrixMutable::begin ( void  )
inherited

Iterator iterates along a row. When end of row is reached it jumps to beginning of next row.

Returns
iterator pointing to upper-left element.

◆ begin() [3/3]

const_iterator theplu::yat::utility::MatrixBase::begin ( void  ) const
inherited

Iterator iterates along a row. When end of row is reached it jumps to beginning of next row.

Returns
const_iterator pointing to upper-left element.

◆ begin_column() [1/3]

const_column_iterator theplu::yat::utility::MatrixBase::begin_column
inherited

Iterator iterates along a column.

Returns
const_iterator pointing to first element of column i.

◆ begin_column() [2/3]

column_iterator theplu::yat::utility::MatrixMutable::begin_column ( size_t  i)
inherited

Iterator iterates along a column.

Returns
iterator pointing to first element of column i.

◆ begin_column() [3/3]

const_column_iterator theplu::yat::utility::MatrixBase::begin_column ( size_t  i) const
inherited

Iterator iterates along a column.

Returns
const_iterator pointing to first element of column i.

◆ begin_row() [1/3]

const_row_iterator theplu::yat::utility::MatrixBase::begin_row
inherited

Iterator iterates along a row.

Returns
const_iterator pointing to first element of row i.

◆ begin_row() [2/3]

row_iterator theplu::yat::utility::MatrixMutable::begin_row ( size_t  i)
inherited

Iterator iterates along a row.

Returns
iterator pointing to first element of row i.

◆ begin_row() [3/3]

const_row_iterator theplu::yat::utility::MatrixBase::begin_row ( size_t  i) const
inherited

Iterator iterates along a row.

Returns
const_iterator pointing to first element of row i.

◆ column_const_view()

const VectorConstView theplu::yat::utility::MatrixBase::column_const_view ( size_t  ) const
inherited
Returns
const vector view of column i

◆ column_view()

VectorView theplu::yat::utility::MatrixMutable::column_view ( size_t  i)
inherited
Returns
Vector view of column i

◆ columns()

size_t theplu::yat::utility::MatrixBase::columns ( void  ) const
inherited
Returns
The number of columns in the matrix.

◆ copy_assign()

void theplu::yat::utility::MatrixView::copy_assign ( const gsl_matrix *  rhs)
protectedvirtual

Copy values in rhs into this. Dimensions must agree. It's safe to call this function when data of rhs and gsl_matrix_p() overlap.

Implements theplu::yat::utility::MatrixMutable.

◆ create_gsl_matrix_copy()

gsl_matrix* theplu::yat::utility::MatrixBase::create_gsl_matrix_copy ( void  ) const
protectedinherited

Create a new copy of the internal GSL matrix.

Necessary memory for the new GSL matrix is allocated and the caller is responsible for freeing the allocated memory.

Returns
A pointer to a copy of the internal GSL matrix.
Exceptions
GSL_errorif memory cannot be allocated for the new copy, or if dimensions mismatch.

◆ div()

void theplu::yat::utility::MatrixMutable::div ( const MatrixBase b)
inherited

Elementwise division of the elements of the calling matrix by the elements of matrix b, $ a_{ij} = a_{ij} / b_{ij} \; \forall i,j $. The result is stored into the calling matrix.

Exceptions
GSL_errorif dimensions mismatch.

◆ end() [1/3]

const_iterator theplu::yat::utility::MatrixBase::end ( void  ) const
inherited
Returns
const_iterator pointing to end of matrix

◆ end() [2/3]

const_iterator theplu::yat::utility::MatrixBase::end
inherited
Returns
const_iterator pointing to end of matrix

◆ end() [3/3]

iterator theplu::yat::utility::MatrixMutable::end ( void  )
inherited
Returns
iterator pointing to end of matrix

◆ end_column() [1/3]

const_column_iterator theplu::yat::utility::MatrixBase::end_column
inherited
Returns
const_iterator pointing to end of column i

◆ end_column() [2/3]

const_column_iterator theplu::yat::utility::MatrixBase::end_column ( size_t  i) const
inherited
Returns
const_iterator pointing to end of column i

◆ end_column() [3/3]

column_iterator theplu::yat::utility::MatrixMutable::end_column ( size_t  i)
inherited
Returns
iterator pointing to end of column i

◆ end_row() [1/3]

const_row_iterator theplu::yat::utility::MatrixBase::end_row
inherited
Returns
const_iterator pointing to end of row i

◆ end_row() [2/3]

const_row_iterator theplu::yat::utility::MatrixBase::end_row ( size_t  i) const
inherited
Returns
const_iterator pointing to end of row i

◆ end_row() [3/3]

row_iterator theplu::yat::utility::MatrixMutable::end_row ( size_t  i)
inherited
Returns
iterator pointing to end of row i

◆ equal()

bool theplu::yat::utility::MatrixBase::equal ( const MatrixBase ,
const double  precision = 0 
) const
inherited

Check whether matrices are equal within a user defined precision, set by precision.

Returns
True if each element deviates less or equal than d. If any matrix contain a NaN, false is always returned.
See also
operator== and operator!=

◆ gsl_matrix_p() [1/3]

gsl_matrix* theplu::yat::utility::MatrixView::gsl_matrix_p ( void  )
virtual
Returns
A pointer to the internal GSL matrix

Implements theplu::yat::utility::MatrixMutable.

◆ gsl_matrix_p() [2/3]

const gsl_matrix* theplu::yat::utility::MatrixView::gsl_matrix_p ( void  ) const
virtual
Returns
A const pointer to the internal GSL matrix

Implements theplu::yat::utility::MatrixMutable.

◆ gsl_matrix_p() [3/3]

virtual const gsl_matrix* theplu::yat::utility::MatrixBase::gsl_matrix_p
inherited
Returns
A const pointer to the internal GSL matrix.

◆ move_assign() [1/2]

void theplu::yat::utility::MatrixView::move_assign ( MatrixMutable &&  rhs)
protectedvirtual

Copy values in rhs into this

Reimplemented from theplu::yat::utility::MatrixMutable.

◆ move_assign() [2/2]

void theplu::yat::utility::MatrixView::move_assign ( gsl_matrix *&&  rhs)
protectedvirtual

◆ mul()

void theplu::yat::utility::MatrixMutable::mul ( const MatrixBase b)
inherited

Multiply the elements of Matrix b with the elements of the calling Matrix , $ a_{ij} = a_{ij} * b_{ij} \; \forall i,j $. The result is stored into the calling Matrix.

Exceptions
GSL_errorif dimensions mismatch.

◆ operator proxy()

theplu::yat::utility::MatrixView::operator proxy ( )

Conversion operator to a private proxy class.

◆ operator!=()

bool theplu::yat::utility::MatrixBase::operator!= ( const MatrixBase other) const
inherited

Comparison operator. Takes squared time.

Checks are performed with exact matching, i.e., rounding off effects may destroy comparison. Use the equal function for comparing elements within a user defined precision.

Returns
False if all elements are equal otherwise true.
See also
equal

◆ operator()() [1/2]

const double& theplu::yat::utility::MatrixBase::operator() ( size_t  row,
size_t  column 
) const
inherited

Element access operator.

Returns
Const reference to the element position (row, column).
Exceptions
IfGSL range checks are enabled in the underlying GSL library a GSL_error exception is thrown if either index is out of range.

◆ operator()() [2/2]

double& theplu::yat::utility::MatrixMutable::operator() ( size_t  row,
size_t  column 
)
inherited

Element access operator.

Returns
Reference to the element position (row, column).
Exceptions
IfGSL range checks are enabled in the underlying GSL library a GSL_error exception is thrown if either index is out of range.

◆ operator*=()

const MatrixMutable& theplu::yat::utility::MatrixMutable::operator*= ( double  d)
inherited

Multiply and assignment operator.

Multiply the elements of the left hand side Matrix with a scalar d, $ a_{ij} = d * a_{ij} \; \forall i,j $.

Exceptions
GSL_errorif memory allocation fails.

◆ operator+=() [1/3]

const MatrixMutable& theplu::yat::utility::MatrixMutable::operator+= ( const MatrixBase b)
inherited

Add and assign operator.

Elementwise addition of the elements of Matrix b to the left hand side Matrix , $ a_{ij} = a_{ij} + b_{ij} \; \forall i,j $.

Returns
A const reference to the resulting Matrix.
Exceptions
GSL_errorif dimensions mismatch.

◆ operator+=() [2/3]

template<class T >
MatrixMutable& theplu::yat::utility::MatrixMutable::operator+= ( const MatrixExpression< T > &  rhs)
inlineinherited

Addition and assign operator.

Returns
A reference to resulting Matrix

◆ operator+=() [3/3]

const MatrixMutable& theplu::yat::utility::MatrixMutable::operator+= ( const double  d)
inherited

Add and assign operator.

Add the scalar value d to the left hand side Matrix, $ a_{ij} = a_{ij} + d \; \forall i,j $.

◆ operator-=() [1/3]

const MatrixMutable& theplu::yat::utility::MatrixMutable::operator-= ( const MatrixBase )
inherited

Subtract and assign operator.

Elementwise subtraction of the elements of Matrix b to the left hand side Matrix , $ a_{ij} = a_{ij} + b_{ij} \; \forall i,j $.

Returns
A const reference to the resulting Matrix.
Exceptions
GSL_errorif dimensions mismatch.

◆ operator-=() [2/3]

template<class T >
MatrixMutable& theplu::yat::utility::MatrixMutable::operator-= ( const MatrixExpression< T > &  rhs)
inlineinherited

Subtraction and assign operator.

Returns
A reference to the resulting VectorMutable.

◆ operator-=() [3/3]

const MatrixMutable& theplu::yat::utility::MatrixMutable::operator-= ( const double  d)
inherited

Subtract and assign operator.

Subtract the scalar value d to the left hand side Matrix, $ a_{ij} = a_{ij} + d \; \forall i,j $.

◆ operator=() [1/4]

template<class T >
MatrixMutable& theplu::yat::utility::MatrixMutable::operator= ( class T  )
inline

Move assignment from a matrix expression. A matrix expression is the result of operator+, operator-, and operator*, or combinations of them.

A typical usage looks like

A = B * C + D;

where B, C, and D are all instances of class Matrix.

Invalidates references, iterators, and views.

Since
new in yat 0.15

◆ operator=() [2/4]

MatrixMutable& theplu::yat::utility::MatrixMutable::operator=

The assignment operator.

Note
If lhs needs to be resized, views and iterators are invalidated.
Returns
A const reference to the resulting Matrix.

◆ operator=() [3/4]

template<class T >
MatrixMutable& theplu::yat::utility::MatrixMutable::operator= ( class T  )
inline

Assignment from a matrix expression. A matrix expression is the result of operator+, operator-, and operator*, or combinations of them.

A typical usage looks like

A = B * C + D;

where A, B, C, and D are all instances of class Matrix.

Typically MatrixExpression only exists as rvalue, and this operator is not called but the rvalue version, operator=(MatrixExpression<T>&&)

Invalidates, references, iterators and views.

Since
new in yat 0.15

◆ operator=() [4/4]

MatrixView& theplu::yat::utility::MatrixView::operator= ( const MatrixView other)

Assign values in other to left-hand side. Dimensions of left-hand and right-hand sides must agree.

◆ operator==()

bool theplu::yat::utility::MatrixBase::operator== ( const MatrixBase other) const
inherited

Comparison operator. Takes squared time.

Checks are performed with exact matching, i.e., rounding off effects may destroy comparison. Use the equal function for comparing elements within a user defined precision.

Returns
True if all elements are equal otherwise false.
See also
equal

◆ row_const_view()

const VectorConstView theplu::yat::utility::MatrixBase::row_const_view ( size_t  ) const
inherited
Returns
const vector view of i

◆ row_view()

VectorView theplu::yat::utility::MatrixMutable::row_view ( size_t  )
inherited
Returns
Vector view of i

◆ rows()

size_t theplu::yat::utility::MatrixBase::rows ( void  ) const
inherited
Returns
The number of rows in the matrix.

◆ swap_columns()

void theplu::yat::utility::MatrixMutable::swap_columns ( const size_t  i,
const size_t  j 
)
inherited

Swap columns i and j.

Exceptions
GSL_errorif either index is out of bounds.

◆ swap_rowcol()

void theplu::yat::utility::MatrixMutable::swap_rowcol ( const size_t  i,
const size_t  j 
)
inherited

Swap row i and column j.

The Matrix must be square.

Exceptions
GSL_errorif either index is out of bounds, or if matrix is not square.

◆ swap_rows()

void theplu::yat::utility::MatrixMutable::swap_rows ( const size_t  i,
const size_t  j 
)
inherited

Swap rows i and j.

Exceptions
GSL_errorif either index is out of bounds.

Friends And Related Function Documentation

◆ minmax_index()

void minmax_index ( const MatrixBase M,
std::pair< size_t, size_t > &  min,
std::pair< size_t, size_t > &  max 
)
related

Locate the maximum and minimum element in the matrix, M.

The indices to the element with the minimum and maximum values of the matrix are returned through parameters min and max, respectively.

Note
Lower index has precedence (searching in row-major order).

◆ swap()

void swap ( MatrixMutable ,
MatrixMutable  
)
related

Exchange all elements between the matrices by copying.

This function swaps element by element and matrices must have the same size. References and iterators are not invalidated.

If you do not care about iterators and references, std::swap is typically faster (only swapping a couple of pointers).

Exceptions
GSL_errorif sizes are not equal.

Member Data Documentation

◆ blas_result_

gsl_matrix* theplu::yat::utility::MatrixMutable::blas_result_
protectedinherited

blas_result_ is used to temporarily store result in BLAS calls. Memory is not allocated for blas_result_ until it is needed.


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

Generated on Sat Feb 18 2023 03:31:45 for yat by  doxygen 1.8.14