OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
DynamicRectMatrix< Real > Class Template Reference

Rectangular matrix class with contiguous flat storage. More...

#include "math/DynamicRectMatrix.hpp"

Public Types

using ElemType = Real
using ElemPoinerType = Real*
using SelfType = DynamicRectMatrix<Real>

Public Member Functions

 DynamicRectMatrix ()
 default constructor
 DynamicRectMatrix (unsigned int nrow, unsigned int ncol)
 DynamicRectMatrix (unsigned int nrow, unsigned int ncol, Real s)
 Constructs and initializes every element of this matrix to a scalar.
 DynamicRectMatrix (unsigned int nrow, unsigned int ncol, Real *array)
 DynamicRectMatrix (const SelfType &m)=default
 copy constructor
 DynamicRectMatrix (SelfType &&m) noexcept=default
 move constructor
 ~DynamicRectMatrix ()=default
 destructor
DynamicRectMatrix< Real > & operator= (const DynamicRectMatrix< Real > &m)=default
 copy assignment operator
DynamicRectMatrix< Real > & operator= (DynamicRectMatrix< Real > &&m) noexcept=default
 move assignment operator
Real & operator() (unsigned int i, unsigned int j)
 Returns the reference of a single element of this matrix.
Real operator() (unsigned int i, unsigned int j) const
 Returns the value of a single element of this matrix.
void getArray (Real *array) const
 Copies the internal data to an array (row-major order).
Real * getArrayPointer ()
 Returns a pointer to the contiguous internal storage (row-major).
const Real * getArrayPointer () const
DynamicVector< Real > getRow (unsigned int row)
 Returns a row of this matrix as a vector.
void setRow (unsigned int row, const DynamicVector< Real > &v)
 Sets a row of this matrix.
DynamicVector< Real > getColumn (unsigned int col)
 Returns a column of this matrix as a vector.
void setColumn (unsigned int col, const DynamicVector< Real > &v)
 Sets a column of this matrix.
void swapRow (unsigned int i, unsigned int j)
 swap two rows of this matrix
void swapColumn (unsigned int i, unsigned int j)
 swap two columns of this matrix
DynamicVector< Real > diagonals () const
 Returns a DynamicVector of the diagonal elements.
bool operator== (const DynamicRectMatrix< Real > &m) const
 Tests if this matrix is identical to matrix m.
bool operator!= (const DynamicRectMatrix< Real > &m) const
 Tests if this matrix is not equal to matrix m.
void negate ()
 Negates the value of this matrix in place.
void negate (const DynamicRectMatrix< Real > &m)
 Sets the value of this matrix to the negation of matrix m.
void add (const DynamicRectMatrix< Real > &m)
 Sets the value of this matrix to the sum of itself and m (*this += m).
void add (const DynamicRectMatrix< Real > &m1, const DynamicRectMatrix< Real > &m2)
 Sets the value of this matrix to the sum of m1 and m2 (*this = m1 + m2).
void sub (const DynamicRectMatrix< Real > &m)
 Sets the value of this matrix to the difference of itself and m (*this -= m).
void sub (const DynamicRectMatrix< Real > &m1, const DynamicRectMatrix< Real > &m2)
 Sets the value of this matrix to the difference of matrix m1 and m2 (*this = m1 - m2).
void mul (Real s)
 Sets the value of this matrix to the scalar multiplication of itself (*this *= s).
void mul (Real s, const DynamicRectMatrix< Real > &m)
 Sets the value of this matrix to the scalar multiplication of matrix m (*this = s * m).
void div (Real s)
 Sets the value of this matrix to the scalar division of itself (*this /= s).
void div (Real s, const DynamicRectMatrix< Real > &m)
 Sets the value of this matrix to the scalar division of matrix m (*this = m / s).
DynamicRectMatrix< Real > & operator*= (const Real s)
 Multiples a scalar onto every element of this matrix.
DynamicRectMatrix< Real > & operator/= (const Real s)
 Divides every element of this matrix by a scalar.
DynamicRectMatrix< Real > & operator+= (const DynamicRectMatrix< Real > &m)
 Sets the value of this matrix to the sum of the other matrix and itself (*this += m).
DynamicRectMatrix< Real > & operator-= (const DynamicRectMatrix< Real > &m)
 Sets the value of this matrix to the difference of itself and the other matrix (*this -= m).
DynamicRectMatrix< Real > transpose () const
 Return the transpose of this matrix.
unsigned int getNRow () const
unsigned int getNCol () const
template<class MatrixType>
void setSubMatrix (unsigned int beginRow, unsigned int beginCol, const MatrixType &m)
template<class MatrixType>
void getSubMatrix (unsigned int beginRow, unsigned int beginCol, MatrixType &m)

Protected Attributes

unsigned int nrow_
unsigned int ncol_
std::vector< Real > data_

Detailed Description

template<typename Real>
class DynamicRectMatrix< Real >

Rectangular matrix class with contiguous flat storage.

Elements are stored in row-major order in a single contiguous std::vector<Real>. Element (i,j) is at data_[i*ncol_ + j]. The contiguous layout allows direct interop with BLAS/LAPACK (via getArrayPointer()) without an intermediate copy.

Definition at line 78 of file DynamicRectMatrix.hpp.

Member Typedef Documentation

◆ ElemPoinerType

template<typename Real>
using OpenMD::DynamicRectMatrix< Real >::ElemPoinerType = Real*

Definition at line 81 of file DynamicRectMatrix.hpp.

◆ ElemType

template<typename Real>
using OpenMD::DynamicRectMatrix< Real >::ElemType = Real

Definition at line 80 of file DynamicRectMatrix.hpp.

◆ SelfType

template<typename Real>
using OpenMD::DynamicRectMatrix< Real >::SelfType = DynamicRectMatrix<Real>

Definition at line 82 of file DynamicRectMatrix.hpp.

Constructor & Destructor Documentation

◆ DynamicRectMatrix() [1/4]

template<typename Real>
OpenMD::DynamicRectMatrix< Real >::DynamicRectMatrix ( )
inline

default constructor

Definition at line 85 of file DynamicRectMatrix.hpp.

◆ DynamicRectMatrix() [2/4]

template<typename Real>
OpenMD::DynamicRectMatrix< Real >::DynamicRectMatrix ( unsigned int nrow,
unsigned int ncol )
inline

Definition at line 87 of file DynamicRectMatrix.hpp.

◆ DynamicRectMatrix() [3/4]

template<typename Real>
OpenMD::DynamicRectMatrix< Real >::DynamicRectMatrix ( unsigned int nrow,
unsigned int ncol,
Real s )
inline

Constructs and initializes every element of this matrix to a scalar.

Definition at line 91 of file DynamicRectMatrix.hpp.

◆ DynamicRectMatrix() [4/4]

template<typename Real>
OpenMD::DynamicRectMatrix< Real >::DynamicRectMatrix ( unsigned int nrow,
unsigned int ncol,
Real * array )
inline

Definition at line 94 of file DynamicRectMatrix.hpp.

Member Function Documentation

◆ add() [1/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::add ( const DynamicRectMatrix< Real > & m)
inline

Sets the value of this matrix to the sum of itself and m (*this += m).

Parameters
mthe other matrix

Definition at line 255 of file DynamicRectMatrix.hpp.

◆ add() [2/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::add ( const DynamicRectMatrix< Real > & m1,
const DynamicRectMatrix< Real > & m2 )
inline

Sets the value of this matrix to the sum of m1 and m2 (*this = m1 + m2).

Parameters
m1the first matrix
m2the second matrix

Definition at line 266 of file DynamicRectMatrix.hpp.

◆ diagonals()

template<typename Real>
DynamicVector< Real > OpenMD::DynamicRectMatrix< Real >::diagonals ( ) const
inline

Returns a DynamicVector of the diagonal elements.

Definition at line 209 of file DynamicRectMatrix.hpp.

◆ div() [1/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::div ( Real s)
inline

Sets the value of this matrix to the scalar division of itself (*this /= s).

Parameters
sthe scalar value

Definition at line 323 of file DynamicRectMatrix.hpp.

◆ div() [2/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::div ( Real s,
const DynamicRectMatrix< Real > & m )
inline

Sets the value of this matrix to the scalar division of matrix m (*this = m / s).

Parameters
sthe scalar value
mthe matrix

Definition at line 333 of file DynamicRectMatrix.hpp.

◆ getArray()

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::getArray ( Real * array) const
inline

Copies the internal data to an array (row-major order).

Parameters
arraythe pointer of destination array

Definition at line 134 of file DynamicRectMatrix.hpp.

◆ getArrayPointer() [1/2]

template<typename Real>
Real * OpenMD::DynamicRectMatrix< Real >::getArrayPointer ( )
inline

Returns a pointer to the contiguous internal storage (row-major).

Definition at line 140 of file DynamicRectMatrix.hpp.

◆ getArrayPointer() [2/2]

template<typename Real>
const Real * OpenMD::DynamicRectMatrix< Real >::getArrayPointer ( ) const
inline

Definition at line 141 of file DynamicRectMatrix.hpp.

◆ getColumn()

template<typename Real>
DynamicVector< Real > OpenMD::DynamicRectMatrix< Real >::getColumn ( unsigned int col)
inline

Returns a column of this matrix as a vector.

Parameters
colthe column index

Definition at line 169 of file DynamicRectMatrix.hpp.

◆ getNCol()

template<typename Real>
unsigned int OpenMD::DynamicRectMatrix< Real >::getNCol ( ) const
inline

Definition at line 387 of file DynamicRectMatrix.hpp.

◆ getNRow()

template<typename Real>
unsigned int OpenMD::DynamicRectMatrix< Real >::getNRow ( ) const
inline

Definition at line 386 of file DynamicRectMatrix.hpp.

◆ getRow()

template<typename Real>
DynamicVector< Real > OpenMD::DynamicRectMatrix< Real >::getRow ( unsigned int row)
inline

Returns a row of this matrix as a vector.

Parameters
rowthe row index

Definition at line 147 of file DynamicRectMatrix.hpp.

◆ getSubMatrix()

template<typename Real>
template<class MatrixType>
void OpenMD::DynamicRectMatrix< Real >::getSubMatrix ( unsigned int beginRow,
unsigned int beginCol,
MatrixType & m )
inline

Definition at line 400 of file DynamicRectMatrix.hpp.

◆ mul() [1/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::mul ( Real s)
inline

Sets the value of this matrix to the scalar multiplication of itself (*this *= s).

Parameters
sthe scalar value

Definition at line 302 of file DynamicRectMatrix.hpp.

◆ mul() [2/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::mul ( Real s,
const DynamicRectMatrix< Real > & m )
inline

Sets the value of this matrix to the scalar multiplication of matrix m (*this = s * m).

Parameters
sthe scalar value
mthe matrix

Definition at line 312 of file DynamicRectMatrix.hpp.

◆ negate() [1/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::negate ( )
inline

Negates the value of this matrix in place.

Definition at line 237 of file DynamicRectMatrix.hpp.

◆ negate() [2/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::negate ( const DynamicRectMatrix< Real > & m)
inline

Sets the value of this matrix to the negation of matrix m.

Parameters
mthe source matrix

Definition at line 245 of file DynamicRectMatrix.hpp.

◆ operator!=()

template<typename Real>
bool OpenMD::DynamicRectMatrix< Real >::operator!= ( const DynamicRectMatrix< Real > & m) const
inline

Tests if this matrix is not equal to matrix m.

Parameters
mmatrix to be compared

Definition at line 232 of file DynamicRectMatrix.hpp.

◆ operator()() [1/2]

template<typename Real>
Real & OpenMD::DynamicRectMatrix< Real >::operator() ( unsigned int i,
unsigned int j )
inline

Returns the reference of a single element of this matrix.

Parameters
irow index
jcolumn index

Definition at line 117 of file DynamicRectMatrix.hpp.

◆ operator()() [2/2]

template<typename Real>
Real OpenMD::DynamicRectMatrix< Real >::operator() ( unsigned int i,
unsigned int j ) const
inline

Returns the value of a single element of this matrix.

Parameters
irow index
jcolumn index

Definition at line 126 of file DynamicRectMatrix.hpp.

◆ operator*=()

template<typename Real>
DynamicRectMatrix< Real > & OpenMD::DynamicRectMatrix< Real >::operator*= ( const Real s)
inline

Multiples a scalar onto every element of this matrix.

Parameters
sthe scalar value

Definition at line 343 of file DynamicRectMatrix.hpp.

◆ operator+=()

template<typename Real>
DynamicRectMatrix< Real > & OpenMD::DynamicRectMatrix< Real >::operator+= ( const DynamicRectMatrix< Real > & m)
inline

Sets the value of this matrix to the sum of the other matrix and itself (*this += m).

Parameters
mthe other matrix

Definition at line 362 of file DynamicRectMatrix.hpp.

◆ operator-=()

template<typename Real>
DynamicRectMatrix< Real > & OpenMD::DynamicRectMatrix< Real >::operator-= ( const DynamicRectMatrix< Real > & m)
inline

Sets the value of this matrix to the difference of itself and the other matrix (*this -= m).

Parameters
mthe other matrix

Definition at line 372 of file DynamicRectMatrix.hpp.

◆ operator/=()

template<typename Real>
DynamicRectMatrix< Real > & OpenMD::DynamicRectMatrix< Real >::operator/= ( const Real s)
inline

Divides every element of this matrix by a scalar.

Parameters
sthe scalar value

Definition at line 352 of file DynamicRectMatrix.hpp.

◆ operator==()

template<typename Real>
bool OpenMD::DynamicRectMatrix< Real >::operator== ( const DynamicRectMatrix< Real > & m) const
inline

Tests if this matrix is identical to matrix m.

Parameters
mmatrix to be compared

Definition at line 221 of file DynamicRectMatrix.hpp.

◆ setColumn()

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::setColumn ( unsigned int col,
const DynamicVector< Real > & v )
inline

Sets a column of this matrix.

Parameters
colthe column index
vthe vector to be set

Definition at line 181 of file DynamicRectMatrix.hpp.

◆ setRow()

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::setRow ( unsigned int row,
const DynamicVector< Real > & v )
inline

Sets a row of this matrix.

Parameters
rowthe row index
vthe vector to be set

Definition at line 159 of file DynamicRectMatrix.hpp.

◆ setSubMatrix()

template<typename Real>
template<class MatrixType>
void OpenMD::DynamicRectMatrix< Real >::setSubMatrix ( unsigned int beginRow,
unsigned int beginCol,
const MatrixType & m )
inline

Definition at line 390 of file DynamicRectMatrix.hpp.

◆ sub() [1/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::sub ( const DynamicRectMatrix< Real > & m)
inline

Sets the value of this matrix to the difference of itself and m (*this -= m).

Parameters
mthe other matrix

Definition at line 278 of file DynamicRectMatrix.hpp.

◆ sub() [2/2]

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::sub ( const DynamicRectMatrix< Real > & m1,
const DynamicRectMatrix< Real > & m2 )
inline

Sets the value of this matrix to the difference of matrix m1 and m2 (*this = m1 - m2).

Parameters
m1the first matrix
m2the second matrix

Definition at line 290 of file DynamicRectMatrix.hpp.

◆ swapColumn()

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::swapColumn ( unsigned int i,
unsigned int j )
inline

swap two columns of this matrix

Parameters
ithe first column
jthe second column

Definition at line 202 of file DynamicRectMatrix.hpp.

◆ swapRow()

template<typename Real>
void OpenMD::DynamicRectMatrix< Real >::swapRow ( unsigned int i,
unsigned int j )
inline

swap two rows of this matrix

Parameters
ithe first row
jthe second row

Definition at line 191 of file DynamicRectMatrix.hpp.

◆ transpose()

template<typename Real>
DynamicRectMatrix< Real > OpenMD::DynamicRectMatrix< Real >::transpose ( ) const
inline

Return the transpose of this matrix.

Definition at line 378 of file DynamicRectMatrix.hpp.

Member Data Documentation

◆ data_

template<typename Real>
std::vector<Real> OpenMD::DynamicRectMatrix< Real >::data_
protected

Definition at line 412 of file DynamicRectMatrix.hpp.

◆ ncol_

template<typename Real>
unsigned int OpenMD::DynamicRectMatrix< Real >::ncol_
protected

Definition at line 411 of file DynamicRectMatrix.hpp.

◆ nrow_

template<typename Real>
unsigned int OpenMD::DynamicRectMatrix< Real >::nrow_
protected

Definition at line 410 of file DynamicRectMatrix.hpp.


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