CTL  0.6.1
Computed Tomography Library
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
CTL::mat::MatrixBase< Rows, Cols > Class Template Reference

Helper base class that provides an access interface to the Matrix template class and its scalar specialization. More...

#include <matrix.h>

Inheritance diagram for CTL::mat::MatrixBase< Rows, Cols >:
Inheritance graph
[legend]

Public Member Functions

 MatrixBase (double fillValue)
 
 MatrixBase (const double(&initArray)[Rows *Cols])
 
template<typename... Doubles>
 MatrixBase (double firstElement, Doubles... matrixElements)
 
double * operator[] (uint row)
 
const double * operator[] (uint row) const
 
double & operator() (uint row, uint column)
 
double operator() (uint row, uint column) const
 
double & at (uint row, uint column) noexcept(false)
 
double at (uint row, uint column) const noexcept(false)
 
template<uint row, uint column>
double & get () noexcept
 
template<uint row, uint column>
double get () const noexcept
 
double & operator() (uint n)
 
double operator() (uint n) const
 
double & at (uint n)
 
double at (uint n) const
 
template<uint n>
double & get () noexcept
 
template<uint n>
double get () const noexcept
 
double * data ()
 
const double * data () const
 
const double * constData () const
 
double * begin ()
 
const double * begin () const
 
const double * constBegin () const
 
double * end ()
 
const double * end () const
 
const double * constEnd () const
 
constexpr size_t size () const
 
std::string info (const char *lineModifier="") const
 
double norm () const
 
bool operator== (const MatrixBase< Rows, Cols > &rhs) const
 
bool operator!= (const MatrixBase< Rows, Cols > &rhs) const
 

Static Public Attributes

static char & SEPARATOR_CHARACTER_FOR_INFO_STRING = details::SeparatorCharacter<>::c
 global separator character for formatting
 

Private Attributes

double _m [Rows *Cols]
 array with matrix elements
 

Detailed Description

template<uint Rows, uint Cols>
class CTL::mat::MatrixBase< Rows, Cols >

Helper base class that provides an access interface to the Matrix template class and its scalar specialization.

Constructor & Destructor Documentation

◆ MatrixBase() [1/3]

template<uint Rows, uint Cols>
CTL::mat::MatrixBase< Rows, Cols >::MatrixBase ( double  fillValue)
inlineexplicit

Construct an instance and initialize all elements with a fillValue.

◆ MatrixBase() [2/3]

template<uint Rows, uint Cols>
CTL::mat::MatrixBase< Rows, Cols >::MatrixBase ( const double(&)  initArray[Rows *Cols])
inlineexplicit

Construct an instance from a C-style array. The array length must match the total number of matrix elements, otherwise it results in a compilation error.

◆ MatrixBase() [3/3]

template<uint Rows, uint Cols>
template<typename... Doubles>
CTL::mat::MatrixBase< Rows, Cols >::MatrixBase ( double  firstElement,
Doubles...  matrixElements 
)
inline

Directly initialize the underlying C-style array double[] using the passed elements.

Member Function Documentation

◆ at() [1/4]

template<uint Rows, uint Cols>
double & CTL::mat::MatrixBase< Rows, Cols >::at ( uint  row,
uint  column 
)
noexcept

Returns a reference to the element with index (row, column). A run time boundary check is performed and an exception is thrown if an index exceeds the matrix dimensions (throws out_of_range).

◆ at() [2/4]

template<uint Rows, uint Cols>
double CTL::mat::MatrixBase< Rows, Cols >::at ( uint  row,
uint  column 
) const
noexcept

Returns the element with index (row, column). A run time boundary check is performed and an exception is thrown if an index exceeds the matrix dimensions (throws out_of_range).

◆ at() [3/4]

template<uint Rows, uint Cols>
double & CTL::mat::MatrixBase< Rows, Cols >::at ( uint  n)
noexcept

Returns a reference to the element from a 1D index lookup n, where the matrix elements are stored in row major order. This function is handy in particular when dealing with vectors. A run time boundary check is performed and an exception is thrown if an index exceeds the matrix dimensions (throws out_of_range).

See also
at(uint row, uint column)

◆ at() [4/4]

template<uint Rows, uint Cols>
double CTL::mat::MatrixBase< Rows, Cols >::at ( uint  n) const
noexcept

Returns the element from a 1D index lookup n, where the matrix elements are stored in row major order. This function is handy in particular when dealing with vectors. A run time boundary check is performed and an exception is thrown if an index exceeds the matrix dimensions (throws out_of_range).

See also
at(uint row, uint column) const

◆ begin() [1/2]

template<uint Rows, uint Cols>
double * CTL::mat::MatrixBase< Rows, Cols >::begin ( )

Returns a pointer to the first element of the matrix. The elements are internally stored in a linear array in row major order. Same as data().

◆ begin() [2/2]

template<uint Rows, uint Cols>
const double * CTL::mat::MatrixBase< Rows, Cols >::begin ( ) const

Returns a pointer to the first element of the matrix. This const version prohibits manipulations of the matrix elements through dereferencing the pointer. The elements are internally stored in a linear array in row major order. Same as data().

◆ constBegin()

template<uint Rows, uint Cols>
const double * CTL::mat::MatrixBase< Rows, Cols >::constBegin ( ) const

Returns a pointer to the first element of the matrix. This const version prohibits manipulations of the matrix elements through dereferencing the pointer, even when this methods is called from a non-const instance. The elements are internally stored in a linear array in row major order. Same as constData().

◆ constData()

template<uint Rows, uint Cols>
const double * CTL::mat::MatrixBase< Rows, Cols >::constData ( ) const

Returns a pointer to the first element of the matrix. This const version prohibits manipulations of the matrix elements through dereferencing the pointer, even when this methods is called from a non-const instance. The elements are internally stored in a linear array in row major order. Same as constBegin().

◆ constEnd()

template<uint Rows, uint Cols>
const double * CTL::mat::MatrixBase< Rows, Cols >::constEnd ( ) const

Returns a pointer to the element following the last element of the matrix. This const version prohibits manipulations of the matrix elements through dereferencing the pointer, even when this methods is called from a non-const instance. This pointer is useful for having a boundary when looping over the matrix elements. However, attempting to access it results in undefined behavior.

◆ data() [1/2]

template<uint Rows, uint Cols>
double * CTL::mat::MatrixBase< Rows, Cols >::data ( )

Returns a pointer to the first element of the matrix. The elements are internally stored in a linear array in row major order. Same as begin().

◆ data() [2/2]

template<uint Rows, uint Cols>
const double * CTL::mat::MatrixBase< Rows, Cols >::data ( ) const

Returns a pointer to the first element of the matrix. This const version prohibits manipulations of the matrix elements through dereferencing the pointer. The elements are internally stored in a linear array in row major order. Same as begin().

◆ end() [1/2]

template<uint Rows, uint Cols>
double * CTL::mat::MatrixBase< Rows, Cols >::end ( )

Returns a pointer to the element following the last element of the matrix. This pointer is useful for having a boundary when looping over the matrix elements. However, attempting to access it results in undefined behavior.

◆ end() [2/2]

template<uint Rows, uint Cols>
const double * CTL::mat::MatrixBase< Rows, Cols >::end ( ) const

Returns a pointer to the element following the last element of the matrix. This pointer is useful for having a boundary when looping over the matrix elements. However, attempting to access it results in undefined behavior.

◆ get() [1/4]

template<uint Rows, uint Cols>
template<uint row, uint column>
double & CTL::mat::MatrixBase< Rows, Cols >::get ( )
noexcept

Returns a reference to the element with index (row, column). A compile time boundary check is performed. This function never fails.

◆ get() [2/4]

template<uint Rows, uint Cols>
template<uint row, uint column>
double CTL::mat::MatrixBase< Rows, Cols >::get ( ) const
noexcept

Returns the element with index (row, column). A compile time boundary check is performed. This function never fails.

◆ get() [3/4]

template<uint Rows, uint Cols>
template<uint n>
double & CTL::mat::MatrixBase< Rows, Cols >::get ( )
noexcept

Returns a reference to the element from a 1D index lookup n, where the matrix elements are stored in row major order. This function is handy in particular when dealing with vectors. A compile time boundary check is performed. This function never fails.

◆ get() [4/4]

template<uint Rows, uint Cols>
template<uint n>
double CTL::mat::MatrixBase< Rows, Cols >::get ( ) const
noexcept

Returns the element from a 1D index lookup n, where the matrix elements are stored in row major order. This function is handy in particular when dealing with vectors. A compile time boundary check is performed. This function never fails.

◆ info()

template<uint Rows, uint Cols>
std::string CTL::mat::MatrixBase< Rows, Cols >::info ( const char *  lineModifier = "") const

Prints the content of the matrix into the returned string. The lineModifier may be used to annotate or emphasis the output by prefixing each line by a character sequence.

Matrix<2, 4> M{ 1.1, -1.2, -1.3, 1.4,
-2.1, 2.2, -2.3, 2.4 };
std::cout << M.info("important 2 rows: ");
// possible output:
// important 2 rows: |_1.100000___-1.200000___-1.300000____1.400000|
// important 2 rows: |-2.100000____2.200000___-2.300000____2.400000|

The conversion from double to string is performed using std::to_string. You may switch between language specific decimal "." or "," using the function

std::setlocale(LC_NUMERIC, "en_US.UTF-8");

or

std::setlocale(LC_NUMERIC, "de_DE.UTF-8");

◆ norm()

template<uint Rows, uint Cols>
double CTL::mat::MatrixBase< Rows, Cols >::norm ( ) const

Returns the Euclidian norm of a row or column vector, i.e. from a Matrix<1, N> or Matrix<N, 1>.

If the macro ENABLE_FROBENIUS_NORM is defined (before matrix.h), it can be also used for arbitrary matrices. In this case it computes the Frobenius norm of the matrix (sqrt of the sum of squared elements).

◆ operator!=()

template<uint Rows, uint Cols>
bool CTL::mat::MatrixBase< Rows, Cols >::operator!= ( const MatrixBase< Rows, Cols > &  rhs) const

Returns true if there is at least one element that is not equal for both matrices, which means the matrices does not have the equal (byte) representation.

◆ operator()() [1/4]

template<uint Rows, uint Cols>
double & CTL::mat::MatrixBase< Rows, Cols >::operator() ( uint  row,
uint  column 
)

Returns a reference to the element with index (row, column). A run time boundary check is not performed.

◆ operator()() [2/4]

template<uint Rows, uint Cols>
double CTL::mat::MatrixBase< Rows, Cols >::operator() ( uint  row,
uint  column 
) const

Returns the element with index (row, column). A run time boundary check is not performed.

◆ operator()() [3/4]

template<uint Rows, uint Cols>
double & CTL::mat::MatrixBase< Rows, Cols >::operator() ( uint  n)

Returns a reference to the element from a 1D index lookup n, where the matrix elements are stored in row major order. This function is handy in particular when dealing with vectors. A run time boundary check is not performed.

◆ operator()() [4/4]

template<uint Rows, uint Cols>
double CTL::mat::MatrixBase< Rows, Cols >::operator() ( uint  n) const

Returns a reference to the element from a 1D index lookup n, where the matrix elements are stored in row major order. This function is handy in particular when dealing with vectors. A run time boundary check is not performed.

◆ operator==()

template<uint Rows, uint Cols>
bool CTL::mat::MatrixBase< Rows, Cols >::operator== ( const MatrixBase< Rows, Cols > &  rhs) const

Returns true if all elements are equal, which means they have the equal (byte) representation of all elements; otherwise false.

◆ operator[]() [1/2]

template<uint Rows, uint Cols>
double * CTL::mat::MatrixBase< Rows, Cols >::operator[] ( uint  row)

Returns a pointer to the first element in a row. A run time boundary check is not performed. Elements are stored in row major order.

◆ operator[]() [2/2]

template<uint Rows, uint Cols>
const double * CTL::mat::MatrixBase< Rows, Cols >::operator[] ( uint  row) const

Returns a pointer to the first element in a row. A run time boundary check is not performed. Elements are stored in row major order.

◆ size()

template<uint Rows, uint Cols>
constexpr size_t CTL::mat::MatrixBase< Rows, Cols >::size ( ) const

Returns the total number of elements that is Rows*Cols.


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