EMatrix
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ematrix::Matrix< tData, tRows, tCols > Class Template Reference

#include <EMatrix.h>

Public Member Functions

virtual ~Matrix ()
 Virtual destructor, no need though. More...
 
 Matrix ()
 
 Matrix (const Matrix< tData, tRows, tCols > &R)
 
 Matrix (tData *tArray)
 
 Matrix (const std::initializer_list< tData > &l)
 
const Matrix< tData, tRows, tCols > & operator= (const Matrix< tData, tRows, tCols > &R)
 
const Matrix< tData, tRows, tCols > & operator= (const std::initializer_list< tData > &l)
 
void load (const tData *tArray)
 
tData * operator[] (size_t iRowIndex) const
 
tData & operator() (size_t iRowIndex, size_t iColIndex) const
 
tData & operator() (size_t iIndex) const
 
tData * pIJ (void) const
 
size_t rows (void) const
 
size_t cols (void) const
 
bool operator== (Matrix< tData, tRows, tCols > &R)
 
bool operator!= (Matrix< tData, tRows, tCols > &R)
 
Matrix< tData, tRows, tCols > operator+ ()
 
Matrix< tData, tRows, tCols > operator- ()
 
Matrix< tData, tRows, tCols > operator+ (const Matrix< tData, tRows, tCols > &R)
 
Matrix< tData, tRows, tCols > operator- (const Matrix< tData, tRows, tCols > &R)
 
Matrix< tData, tRows, tCols > operator* (const tData &scalar)
 
Matrix< tData, tRows, tCols > operator/ (const tData &scalar)
 
template<size_t tColsR>
Matrix< tData, tRows, tColsR > operator* (const Matrix< tData, tCols, tColsR > &R)
 
Matrix< tData, tRows, tCols > operator*= (const Matrix< tData, tRows, tCols > &R)
 
Matrix< tData, tRows, tCols > operator/= (const Matrix< tData, tRows, tCols > &R)
 
Matrix< tData, tRows, tCols > zeros (void)
 
Matrix< tData, tRows, tCols > ones (void)
 
Matrix< tData, tRows, tCols > eye (void)
 
Matrix< tData, tRows, tCols > randn (void)
 
tData n (void) const
 
Matrix< tData, tRows, 1 > u (void) const
 

Protected Member Functions

void matalloc (size_t iRowIndex, size_t iColIndex)
 

Protected Attributes

size_t iRows
 
size_t iCols
 
tData * ij [tRows]
 
tData storage [tRows *tCols]
 

Friends

template<class tData0 , size_t tRows0, size_t tCols0>
std::ostream & operator<< (std::ostream &s, const Matrix< tData0, tRows0, tCols0 > &A)
 
template<class tData0 , size_t tRows0, size_t tCols0>
std::ostream & octave (std::ostream &s, const Matrix< tData0, tRows0, tCols0 > &A, const char *Aname)
 
template<class tData0 , size_t tRows0, size_t tCols0>
std::ostream & octave (std::ostream &s, const Matrix< std::complex< tData0 >, tRows0, tCols0 > &A, const char *Aname)
 
template<class tData0 , size_t tRows0, size_t tCols0>
Matrix< tData0, tRows0, tCols0 > operator* (const tData0 &scalar, const Matrix< tData0, tRows0, tCols0 > &R)
 
template<class tData0 , size_t tCols0, size_t tRowsT, size_t tRowsB>
Matrix< tData0, tRowsT+tRowsB, tCols0 > operator& (const Matrix< tData0, tRowsT, tCols0 > &Top, const Matrix< tData0, tRowsB, tCols0 > &Bottom)
 
template<class tData0 , size_t tRows0, size_t tColsL, size_t tColsR>
Matrix< tData0, tRows0, tColsL+tColsR > operator| (const Matrix< tData0, tRows0, tColsL > &Left, const Matrix< tData0, tRows0, tColsR > &Right)
 
template<class tData0 , size_t tRows0, size_t tCols0>
Matrix< tData0, tCols0, tRows0 > trans (const Matrix< tData0, tRows0, tCols0 > &R)
 
template<size_t tRows0, size_t tCols0>
Matrix< std::complex< float >, tCols0, tRows0 > trans (const Matrix< std::complex< float >, tRows0, tCols0 > &R)
 
template<size_t tRows0, size_t tCols0>
Matrix< std::complex< double >, tCols0, tRows0 > trans (const Matrix< std::complex< double >, tRows0, tCols0 > &R)
 
template<class tData0 , size_t tRows0>
Matrix< tData0, tRows0, 1 > diag (const Matrix< tData0, tRows0, tRows0 > &R)
 
template<class tData0 , size_t tRows0>
Matrix< tData0, tRows0, tRows0 > diag (const Matrix< tData0, tRows0, 1 > &R)
 
template<class tData0 , size_t tCols0>
Matrix< tData0, tCols0, tCols0 > diag (const Matrix< tData0, 1, tCols0 > &R)
 
template<class tData0 >
Matrix< tData0, 3, 3 > skew (const Matrix< tData0, 3, 1 > &R)
 
template<class tData0 >
Matrix< tData0, 3, 1 > cross (const Matrix< tData0, 3, 1 > &L, const Matrix< tData0, 3, 1 > &R)
 
template<class tData0 , size_t tRows0>
tData0 dot (const Matrix< tData0, tRows0, 1 > &L, const Matrix< tData0, tRows0, 1 > &R)
 
template<class tData0 , size_t tRows0>
tData0 norm (const Matrix< tData0, tRows0, 1 > &R)
 
template<size_t tRows0>
Matrix< float, tRows0, tRows0 > inv (const Matrix< float, tRows0, tRows0 > &R)
 
template<size_t tRows0>
Matrix< std::complex< float >, tRows0, tRows0 > inv (const Matrix< std::complex< float >, tRows0, tRows0 > &R)
 
template<size_t tRows0>
Matrix< double, tRows0, tRows0 > inv (const Matrix< double, tRows0, tRows0 > &R)
 
template<size_t tRows0>
Matrix< std::complex< double >, tRows0, tRows0 > inv (const Matrix< std::complex< double >, tRows0, tRows0 > &R)
 
template<size_t tRows0>
float det (const Matrix< float, tRows0, tRows0 > &R)
 
template<size_t tRows0>
double det (const Matrix< double, tRows0, tRows0 > &R)
 
template<size_t tRows0>
std::complex< float > det (const Matrix< std::complex< float >, tRows0, tRows0 > &R)
 
template<size_t tRows0>
std::complex< double > det (const Matrix< std::complex< double >, tRows0, tRows0 > &R)
 
template<class tData0 >
Matrix< tData0, 3, 3 > R (tData0 angle, char axis)
 

Detailed Description

template<typename tData, size_t tRows, size_t tCols>
class ematrix::Matrix< tData, tRows, tCols >

Definition at line 54 of file EMatrix.h.

Constructor & Destructor Documentation

◆ ~Matrix()

template<class tData , size_t tRows, size_t tCols>
ematrix::Matrix< tData, tRows, tCols >::~Matrix ( )
virtual

Virtual destructor, no need though.

Definition at line 419 of file EMatrix.h.

419  { // Tag:tested
420  // HERE;
421 }

◆ Matrix() [1/4]

template<class tData , size_t tRows, size_t tCols>
ematrix::Matrix< tData, tRows, tCols >::Matrix ( )

Default constructor Usage: Matrix<double,2,3> A;

Definition at line 424 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::matalloc().

425  : iRows(tRows), iCols(tCols) {
426  matalloc(tRows,tCols);
427 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
void matalloc(size_t iRowIndex, size_t iColIndex)
Definition: EMatrix.h:410

◆ Matrix() [2/4]

template<class tData , size_t tRows, size_t tCols>
ematrix::Matrix< tData, tRows, tCols >::Matrix ( const Matrix< tData, tRows, tCols > &  R)
inline

Copy constructor (not to be confused with the assignment operator) Usage: Matrix<float,2,3> A; Matrix<float,2,3> B=A;

Definition at line 430 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, ematrix::Matrix< tData, tRows, tCols >::iRows, and ematrix::Matrix< tData, tRows, tCols >::matalloc().

431  : iRows (R.iRows), iCols (R.iCols) {
432  matalloc(R.iRows, R.iCols);
433  std::memcpy(ij[0], R.ij[0], sizeof (tData) * iRows * iCols);
434 }
size_t iCols
Definition: EMatrix.h:59
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61
void matalloc(size_t iRowIndex, size_t iColIndex)
Definition: EMatrix.h:410

◆ Matrix() [3/4]

template<class tData , size_t tRows, size_t tCols>
ematrix::Matrix< tData, tRows, tCols >::Matrix ( tData *  tArray)

Array initialize contructor Usage: float a[2][3] = {{1.0,2.0,3.0},{4.0,5.0,6.0}}; Matrix<float,2,3> A(&a[0][0]);

Definition at line 437 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::matalloc(), and ematrix::Matrix< tData, tRows, tCols >::storage.

438  : iRows (tRows), iCols (tCols) {
439  matalloc(tRows,tCols);
440  std::memcpy(storage, tArray, sizeof(storage));
441 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData storage[tRows *tCols]
Definition: EMatrix.h:62
void matalloc(size_t iRowIndex, size_t iColIndex)
Definition: EMatrix.h:410

◆ Matrix() [4/4]

template<class tData , size_t tRows, size_t tCols>
ematrix::Matrix< tData, tRows, tCols >::Matrix ( const std::initializer_list< tData > &  l)

STL list initialize contructor (C++11) Usage: Matrix<double,3,3> A = {1.,2.,3.,0.,0.,0.,0,0,0};

Definition at line 444 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, ematrix::Matrix< tData, tRows, tCols >::iRows, and ematrix::Matrix< tData, tRows, tCols >::matalloc().

445  : iRows(tRows), iCols(tCols) {
446  assert( iRows*iCols == l.size() );
447  matalloc( iRows, iCols);
448  for(size_t i = 0; i<(iRows*iCols); i++) {
449  ij[0][i] = *(l.begin() + i);
450  }
451 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61
void matalloc(size_t iRowIndex, size_t iColIndex)
Definition: EMatrix.h:410

Member Function Documentation

◆ cols()

template<typename tData, size_t tRows, size_t tCols>
size_t ematrix::Matrix< tData, tRows, tCols >::cols ( void  ) const
inline

Get the number of cols in a matrix Usage: size_t i = A.cols();

Definition at line 185 of file EMatrix.h.

References ematrix::operator*(), and ematrix::R().

Referenced by main(), and ematrix::Matrix< tData, tRows, tCols >::operator*().

185  { // Tag:tested
186  return iCols;
187  }
size_t iCols
Definition: EMatrix.h:59

◆ eye()

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::eye ( void  )

Set contents to the identity matrix Usage: A.eye();

Definition at line 702 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

Referenced by ematrix::inv(), and main().

702  { // Tag:tested
703  assert(tRows==tCols);
704  std::memset (ij[0], 0x0, sizeof(tData) * iRows * iCols);
705 
706  tData * pThis = ij[0];
707  for (size_t iIndex = 0; iIndex < iRows; iIndex++, pThis+=iCols)
708  (*pThis++) = tData(1);
709  return *this;
710 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ load()

template<class tData , size_t tRows, size_t tCols>
void ematrix::Matrix< tData, tRows, tCols >::load ( const tData *  tArray)

Array assignment Usage: double a[2][3] = {{1.1,2.1,3.1},{4.0,5.0,6.0}}; Matrix<double,2,3> A; A.load(&a[0][0]); Warning: Not congnizant of size, can read from unintended memory location;

Definition at line 472 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::storage.

Referenced by main().

472  { // Tag:tested
473  std::memcpy(storage, tArray, sizeof(storage));
474 }
tData storage[tRows *tCols]
Definition: EMatrix.h:62

◆ matalloc()

template<class tData , size_t tRows, size_t tCols>
void ematrix::Matrix< tData, tRows, tCols >::matalloc ( size_t  iRowIndex,
size_t  iColIndex 
)
protected

Definition at line 410 of file EMatrix.h.

Referenced by ematrix::Matrix< tData, tRows, tCols >::Matrix().

410  { // Tag:tested
411  ij[0] = &storage[0];
412  for (size_t iIndex = 1; iIndex < iRowIndex; iIndex++)
413  ij[iIndex] = ij[iIndex - 1] + iColIndex;
414 
415  std::memset (storage, 0x0, sizeof(storage));
416 }
tData * ij[tRows]
Definition: EMatrix.h:61
tData storage[tRows *tCols]
Definition: EMatrix.h:62

◆ n()

template<class tData , size_t tRows, size_t tCols>
tData ematrix::Matrix< tData, tRows, tCols >::n ( void  ) const

Take the norm of two vectors Usage: norm_a = a.n();

Definition at line 814 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::dot.

Referenced by ematrix::det(), ematrix::inv(), main(), and ematrix::Matrix< tData, tRows, tCols >::u().

814  { // Tag:tested
815  return std::sqrt(dot(*this,*this));
816 }
friend tData0 dot(const Matrix< tData0, tRows0, 1 > &L, const Matrix< tData0, tRows0, 1 > &R)

◆ ones()

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::ones ( void  )

Set contents to tData(1) Usage: A.ones();

Definition at line 694 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

Referenced by main().

694  { // Tag:tested
695  tData * pThis = ij[0];
696  for (size_t iIndex = 0; iIndex < iRows * iCols; iIndex++)
697  (*pThis++) = tData(1);
698  return *this;
699 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator!=()

template<class tData , size_t tRows, size_t tCols>
bool ematrix::Matrix< tData, tRows, tCols >::operator!= ( Matrix< tData, tRows, tCols > &  R)

Boolean != operator Usage: if (A != B) ...

Definition at line 555 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::R.

555  { // Tag:tested
556  return !(*this == R);
557 }
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)

◆ operator()() [1/2]

template<class tData , size_t tRows, size_t tCols>
tData & ematrix::Matrix< tData, tRows, tCols >::operator() ( size_t  iRowIndex,
size_t  iColIndex 
) const
inline

Data access operator for Octave and FORTRAN indexing ... From 1 to n Note this does not imply FORTRAN memory storage Usage: Matrix<double,3,2> A = {1,2,3,4,5,6}; A(1,1) = 8; cerr << A(3,2) << endl; Note this looks similar to the deprecated memory initialize c_tor that uses va_arg. but is not the same thing

Definition at line 477 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

477  { // Tag:tested
478  iRowIndex--;
479  iColIndex--;
480  assert(0<=iRowIndex && iRowIndex<iRows);
481  assert(0<=iColIndex && iColIndex<iCols);
482  return ij[iRowIndex][iColIndex];
483 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator()() [2/2]

template<class tData , size_t tRows, size_t tCols>
tData & ematrix::Matrix< tData, tRows, tCols >::operator() ( size_t  iIndex) const
inline

Vector Data access operator for Octave and FORTRAN indexing ... From 1 to n Usage: Matrix<double,6,1> V = {1,2,3,4,5,6}; V(1) = 8; cerr << V(6) << endl; Usage: Matrix<double,1,6> U = {1,2,3,4,5,6}; U(1) = 8; cerr << U(6) << endl; Note a non 1xn or nx1 matrix will assertion fail. Could not determine a way to force compile time error.

Definition at line 486 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

486  { // Tag:tested
487  iIndex--;
488  assert(iRows==1 || iCols==1);
489  if(iCols == 1) {
490  assert(0<=iIndex && iIndex<iRows);
491  return ij[iIndex][0];
492  } else { // (iRows == 1)
493  assert(0<=iIndex && iIndex<iCols);
494  return ij[0][iIndex];
495  }
496 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator*() [1/2]

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::operator* ( const tData &  scalar)

Scalar multiplication operator Usage: C = A * scalar;

Definition at line 600 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

600  { // Tag:tested
601  Matrix< tData, tRows, tCols > Result = (*this);
602  tData * pResult = Result.ij[0];
603  for (size_t iIndex = 0; iIndex < iRows * iCols; iIndex++)
604  (*pResult++) *= scalar;
605  return Result;
606 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59

◆ operator*() [2/2]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tColsR>
Matrix< tData, tRows, tColsR > ematrix::Matrix< tData, tRows, tCols >::operator* ( const Matrix< tData, tCols, tColsR > &  R)
inline

Matrix multiplication operator Usage: C = A * B;

Definition at line 239 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::cols(), ematrix::cross(), ematrix::det(), ematrix::diag(), ematrix::dot(), ematrix::inv(), ematrix::norm(), ematrix::operator&(), ematrix::operator|(), ematrix::R(), ematrix::Matrix< tData, tRows, tCols >::rows(), ematrix::skew(), and ematrix::trans().

239  { // Tag:tested
240  tData x;
241  Matrix< tData, tRows, tColsR > Result;
242 
243  for (size_t iIndex=0; iIndex<iRows; iIndex++) {
244  for (size_t jIndex=0; jIndex<R.cols(); jIndex++) {
245  x = tData(0);
246  for (size_t kIndex=0; kIndex<R.rows(); kIndex++) {
247  x += ij[iIndex][kIndex] * R[kIndex][jIndex];
248  }
249  Result[iIndex][jIndex] = x;
250  }
251  }
252  return Result;
253  }
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator*=()

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::operator*= ( const Matrix< tData, tRows, tCols > &  R)

Array multiplication operator Usage: C = (A *= B); Must use parentheses This mimics Octave's A .* B operator and not C's x *= 5 operator

Definition at line 630 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

630  { // Tag:tested
631  Matrix< tData, tRows, tCols > Result;
632  tData * pLeft = ij[0];
633  tData * pRight = R.ij[0];
634  tData * pResult = Result.ij[0];
635  for (size_t iIndex = 0; iIndex < iRows*iCols; iIndex++)
636  (*pResult++) = (*pLeft++) * tData(*pRight++);
637  return Result;
638 }
size_t iCols
Definition: EMatrix.h:59
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator+() [1/2]

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::operator+ ( )

Unary + operator Usage: C = (+B); Just returns *this;

Definition at line 560 of file EMatrix.h.

560  { // Tag:tested
561  return *this;
562 }

◆ operator+() [2/2]

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::operator+ ( const Matrix< tData, tRows, tCols > &  R)

Addition operator Usage: C = A + B;

Definition at line 575 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

575  { // Tag:tested
576  Matrix< tData, tRows, tCols > Result;
577  tData * pLeft = ij[0];
578  tData * pRight = R.ij[0];
579  tData * pResult = Result.ij[0];
580 
581  for (size_t iIndex = 0; iIndex < iRows * iCols; iIndex++)
582  (*pResult++) = (*pLeft++) + (*pRight++);
583 
584  return Result;
585 }
size_t iCols
Definition: EMatrix.h:59
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator-() [1/2]

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::operator- ( )

Unary - operator Usage: C = (-A);

Definition at line 565 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

565  { // Tag:tested
566  Matrix< tData, tRows, tCols > Result;
567  tData * pLeft = ij[0];
568  tData * pResult = Result.ij[0];
569  for (size_t iIndex = 0; iIndex < iRows * iCols; iIndex++)
570  (*pResult++) = (-(*pLeft++));
571  return Result;
572 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator-() [2/2]

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::operator- ( const Matrix< tData, tRows, tCols > &  R)

Subtaction operator Usage: C = A - B;

Definition at line 588 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

588  { // Tag:tested
589  Matrix< tData, tRows, tCols > Result;
590  tData * pLeft = ij[0];
591  tData * pRight = R.ij[0];
592  tData * pResult = Result.ij[0];
593 
594  for (size_t iIndex = 0; iIndex < iRows * iCols; iIndex++)
595  (*pResult++) = (*pLeft++) - (*pRight++);
596  return Result;
597 }
size_t iCols
Definition: EMatrix.h:59
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator/()

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::operator/ ( const tData &  scalar)

Scalar division operator Usage: C = A / scalar;

Definition at line 620 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

620  { // Tag:tested
621  assert(scalar);
622  Matrix< tData, tRows, tCols > Result = (*this);
623  tData * pResult = Result.ij[0];
624  for (size_t iIndex = 0; iIndex < iRows * iCols; iIndex++)
625  (*pResult++) /= scalar;
626  return Result;
627 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59

◆ operator/=()

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::operator/= ( const Matrix< tData, tRows, tCols > &  R)

Array division operator Usage: C = (A /= B); Must use parentheses This mimics Octave's A ./ B operator and not C's x /= 5 operator

Definition at line 641 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

641  { // Tag:tested
642  Matrix< tData, tRows, tCols > Result;
643  tData * pLeft = ij[0];
644  tData * pRight = R.ij[0];
645  tData * pResult = Result.ij[0];
646  for (size_t iIndex = 0; iIndex < iRows * iCols; iIndex++) {
647  assert(*pRight != 0.0);
648  (*pResult++) = (*pLeft++) / tData(*pRight++);
649  }
650  return Result;
651 }
size_t iCols
Definition: EMatrix.h:59
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator=() [1/2]

template<class tData , size_t tRows, size_t tCols>
const Matrix< tData, tRows, tCols > & ematrix::Matrix< tData, tRows, tCols >::operator= ( const Matrix< tData, tRows, tCols > &  R)
inline

Assignment operator (not to be confused with the copy constructor) Usage: Y = X - Z;

Definition at line 454 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

454  { // Tag:tested
455  assert((iRows == R.iRows) && (iCols == R.iCols));
456  if( this != &R ) {
457  std::memcpy (ij[0], R.ij[0], sizeof(tData)*iRows*iCols);
458  }
459  return *this;
460 }
size_t iCols
Definition: EMatrix.h:59
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator=() [2/2]

template<class tData , size_t tRows, size_t tCols>
const Matrix< tData, tRows, tCols > & ematrix::Matrix< tData, tRows, tCols >::operator= ( const std::initializer_list< tData > &  l)
inline

STL initializer_list assignment (C++11) Usage: Matrix<double,3,2> A; A = {1.1,2.1,3.1,0.0,0.0,0.0};

Definition at line 463 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

463  { // Tag:tested
464  assert( iRows*iCols == l.size() );
465  for(size_t i = 0; i<(iRows*iCols); i++) {
466  ij[0][i] = *(l.begin() + i);
467  }
468  return *this;
469 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator==()

template<class tData , size_t tRows, size_t tCols>
bool ematrix::Matrix< tData, tRows, tCols >::operator== ( Matrix< tData, tRows, tCols > &  R)

Boolean == operator Usage: if (A == B) ...

Definition at line 542 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

542  { // Tag:tested
543  tData * pLeft = ij[0];
544  tData * pRight = R.ij[0];
545 
546  for (size_t iIndex = 0; iIndex < iRows * iCols; iIndex++)
547  if((*pLeft++) != tData(*pRight++)) {
548  return false;
549  }
550 
551  return true;
552 }
size_t iCols
Definition: EMatrix.h:59
friend Matrix< tData0, 3, 3 > R(tData0 angle, char axis)
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ operator[]()

template<typename tData, size_t tRows, size_t tCols>
tData* ematrix::Matrix< tData, tRows, tCols >::operator[] ( size_t  iRowIndex) const
inline

C like element access (0 to n-1), get and set. Usage: Matrix<double,3,2> A = {1,2,3,4,5,6}; A[0][0] = 7; cerr << A[2][1] << endl; Row operator returns the matrix row corresponding to iRowIndex, Warning: Does not provide column access safety.

Definition at line 117 of file EMatrix.h.

References ematrix::octave().

117  { // Tag:tested
118  assert(iRowIndex<iRows);
119  return ij[iRowIndex];
120  }
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ pIJ()

template<typename tData, size_t tRows, size_t tCols>
tData* ematrix::Matrix< tData, tRows, tCols >::pIJ ( void  ) const
inline

Get the storage pointer for the data in the matrix This is really only here for the friend functions Try not to use it Usage: tData* ptr = A.pIJ();

Definition at line 171 of file EMatrix.h.

Referenced by ematrix::det(), ematrix::dot(), ematrix::inv(), main(), and ematrix::skew().

171  { // Tag:tested
172  return ij[0];
173  }
tData * ij[tRows]
Definition: EMatrix.h:61

◆ randn()

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::randn ( void  )

Set all elements of the current matrix random ~N(0,1); Usage: u.randn();

Definition at line 713 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

Referenced by main().

713  { // Tag:tested
714  std::default_random_engine generator;
715  std::normal_distribution<tData> distribution;
716  for (size_t iIndex = 0; iIndex < iRows*iCols; iIndex++) {
717  ij[0][iIndex] = distribution(generator);
718  }
719  return *this;
720 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

◆ rows()

template<typename tData, size_t tRows, size_t tCols>
size_t ematrix::Matrix< tData, tRows, tCols >::rows ( void  ) const
inline

Get the number of rows in a matrix Usage: size_t i = A.rows();

Definition at line 178 of file EMatrix.h.

Referenced by main(), and ematrix::Matrix< tData, tRows, tCols >::operator*().

178  { // Tag:tested
179  return iRows;
180  }
size_t iRows
Definition: EMatrix.h:59

◆ u()

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, 1 > ematrix::Matrix< tData, tRows, tCols >::u ( void  ) const

return a unit vector in the direction of V Usage: u_v = V.u()

Definition at line 824 of file EMatrix.h.

References ematrix::cgesv_(), ematrix::dgesv_(), ematrix::Matrix< tData, tRows, tCols >::n(), ematrix::sgesv_(), and ematrix::zgesv_().

Referenced by main(), and ematrix::uv_to_ae().

824  { // Tag:tested
825  tData den = n();
826  assert(den != 0.0);
827  Matrix< tData, tRows, 1 > Result = *this;
828  return Result*(1.0/den);
829 }
tData n(void) const
Definition: EMatrix.h:814

◆ zeros()

template<class tData , size_t tRows, size_t tCols>
Matrix< tData, tRows, tCols > ematrix::Matrix< tData, tRows, tCols >::zeros ( void  )

Set contents to 0x0 Usage: A.zeros();

Definition at line 688 of file EMatrix.h.

References ematrix::Matrix< tData, tRows, tCols >::iCols, ematrix::Matrix< tData, tRows, tCols >::ij, and ematrix::Matrix< tData, tRows, tCols >::iRows.

Referenced by main().

688  { // Tag:tested
689  std::memset (ij[0], 0x0, sizeof(tData) * iRows * iCols);
690  return *this;
691 }
size_t iCols
Definition: EMatrix.h:59
size_t iRows
Definition: EMatrix.h:59
tData * ij[tRows]
Definition: EMatrix.h:61

Friends And Related Function Documentation

◆ cross

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 >
Matrix< tData0, 3, 1 > cross ( const Matrix< tData0, 3, 1 > &  L,
const Matrix< tData0, 3, 1 > &  R 
)
friend

◆ det [1/4]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0>
float det ( const Matrix< float, tRows0, tRows0 > &  R)
friend

Matrix determinent, must link with Lapack Usage: A_det = det(A);

◆ det [2/4]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0>
double det ( const Matrix< double, tRows0, tRows0 > &  R)
friend

◆ det [3/4]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0>
std::complex<float> det ( const Matrix< std::complex< float >, tRows0, tRows0 > &  R)
friend

◆ det [4/4]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0>
std::complex<double> det ( const Matrix< std::complex< double >, tRows0, tRows0 > &  R)
friend

◆ diag [1/3]

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0>
Matrix< tData0, tRows0, 1 > diag ( const Matrix< tData0, tRows0, tRows0 > &  R)
friend

Matrix diagonal like Octave This friend function does not modify input contents. Usage: A_diag = diag(A);

◆ diag [2/3]

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0>
Matrix< tData0, tRows0, tRows0 > diag ( const Matrix< tData0, tRows0, 1 > &  R)
friend

◆ diag [3/3]

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tCols0>
Matrix< tData0, tCols0, tCols0 > diag ( const Matrix< tData0, 1, tCols0 > &  R)
friend

◆ dot

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0>
tData0 dot ( const Matrix< tData0, tRows0, 1 > &  L,
const Matrix< tData0, tRows0, 1 > &  R 
)
friend

◆ inv [1/4]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0>
Matrix< float, tRows0, tRows0 > inv ( const Matrix< float, tRows0, tRows0 > &  R)
friend

Matrix inverse, must link with Lapack Usage: A_inv = inv(A);

◆ inv [2/4]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0>
Matrix< std::complex<float>, tRows0, tRows0 > inv ( const Matrix< std::complex< float >, tRows0, tRows0 > &  R)
friend

◆ inv [3/4]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0>
Matrix< double, tRows0, tRows0 > inv ( const Matrix< double, tRows0, tRows0 > &  R)
friend

◆ inv [4/4]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0>
Matrix< std::complex<double>, tRows0, tRows0 > inv ( const Matrix< std::complex< double >, tRows0, tRows0 > &  R)
friend

◆ norm

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0>
tData0 norm ( const Matrix< tData0, tRows0, 1 > &  R)
friend

Take the norm of two vectors Usage: norm_a = norm(a);

Referenced by ematrix::uv_to_ae().

◆ octave [1/2]

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0, size_t tCols0>
std::ostream& octave ( std::ostream &  s,
const Matrix< tData0, tRows0, tCols0 > &  A,
const char *  Aname 
)
friend

Octave text output format, complex<double> Usage: Matrix< complex<double>,3,3 > ZA; octave(cout,ZA,"ZA") << endl; Can define: #define cout_octave(x) octave(cout,x,#x) for cout_octave(ZA) << endl;

Definition at line 531 of file EMatrix.h.

531  { // Tag:tested
532  s << "# name: " << Aname << std::endl;
533  s << "# type: matrix" << std::endl;
534  s << "# rows: " << A.iRows << std::endl;
535  s << "# columns: " << A.iCols << std::endl;
536  s << A;
537  s.flush();
538  return s;
539 }

◆ octave [2/2]

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0, size_t tCols0>
std::ostream& octave ( std::ostream &  s,
const Matrix< std::complex< tData0 >, tRows0, tCols0 > &  A,
const char *  Aname 
)
friend

Octave text output format, double Usage: Matrix<double,2,3> A(&a[0][0]); octave(cout,A,"A") << endl; Can define: #define cout_octave(x) octave(cout,x,#x) for cout_octave(A) << endl;

Definition at line 520 of file EMatrix.h.

520  { // Tag:tested
521  s << "# name: " << Aname << std::endl;
522  s << "# type: complex matrix" << std::endl;
523  s << "# rows: " << A.iRows << std::endl;
524  s << "# columns: " << A.iCols << std::endl;
525  s << A;
526  s.flush();
527  return s;
528 }

◆ operator&

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tCols0, size_t tRowsT, size_t tRowsB>
Matrix< tData0, tRowsT+tRowsB, tCols0 > operator & ( const Matrix< tData0, tRowsT, tCols0 > &  Top,
const Matrix< tData0, tRowsB, tCols0 > &  Bottom 
)
friend

Concatenate matrices top and botton Usage: C = (A & B); Must use parenthesis

Definition at line 654 of file EMatrix.h.

655  { // Tag:tested
656  Matrix< tData0, tRowsT+tRowsB, tCols0 > Result;
657 
658  size_t i,ii,j;
659  for(i=0; i<Top.iRows; i++)
660  for(j=0; j<Top.iCols; j++)
661  Result[i][j] = Top[i][j];
662 
663  for(i=Top.iRows,ii=0; i<(Top.iRows+Bottom.iRows); i++,ii++) {
664  for(j=0; j<Top.iCols; j++) {
665  Result[i][j] = Bottom[ii][j];
666  }
667  }
668  return Result;
669 }

◆ operator*

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0, size_t tCols0>
Matrix< tData0, tRows0, tCols0 > operator* ( const tData0 &  scalar,
const Matrix< tData0, tRows0, tCols0 > &  R 
)
friend

Friend scalar multiplication operator Usage: C = scalar * A;

◆ operator<<

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0, size_t tCols0>
std::ostream& operator<< ( std::ostream &  s,
const Matrix< tData0, tRows0, tCols0 > &  A 
)
friend

Overloaded output stream operator << Usage: log_file << A;

◆ operator|

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0, size_t tColsL, size_t tColsR>
Matrix< tData0, tRows0, tColsL+tColsR > operator| ( const Matrix< tData0, tRows0, tColsL > &  Left,
const Matrix< tData0, tRows0, tColsR > &  Right 
)
friend

Concatenate matrices Left to Right Usage: C = (A | B); Must use parenthesis

Definition at line 672 of file EMatrix.h.

673  { // Tag:tested
674  Matrix< tData0, tRows0, tColsL+tColsR > Result;
675  size_t i,j,jj;
676  for(i=0; i<Left.iRows; i++)
677  for(j=0; j<Left.iCols; j++)
678  Result[i][j] = Left[i][j];
679  for(i=0; i<Left.iRows; i++) {
680  for(j=Left.iCols,jj=0; j<(Left.iCols+Right.iCols); j++,jj++) {
681  Result[i][j] = Right[i][jj];
682  }
683  }
684  return Result;
685 }

◆ R

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 >
Matrix< tData0, 3, 3 > R ( tData0  angle,
char  axis 
)
friend

Simple Rotation Usage: Rx = R(angle_rad, 'x'); Note that r_ECEF = trans(R(ws*t, 'z'))*r_ECI if ws*t is a positive rotation about the z axis. This is backwards on purpose.

Referenced by ematrix::cross(), ematrix::det(), ematrix::inv(), ematrix::Matrix< tData, tRows, tCols >::operator!=(), ematrix::operator*(), ematrix::TEL(), ematrix::TIE(), and ematrix::trans().

◆ skew

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 >
Matrix< tData0, 3, 3 > skew ( const Matrix< tData0, 3, 1 > &  R)
friend

Referenced by ematrix::cross().

◆ trans [1/3]

template<typename tData, size_t tRows, size_t tCols>
template<class tData0 , size_t tRows0, size_t tCols0>
Matrix< tData0, tCols0, tRows0 > trans ( const Matrix< tData0, tRows0, tCols0 > &  R)
friend

◆ trans [2/3]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0, size_t tCols0>
Matrix< std::complex<float>, tCols0, tRows0 > trans ( const Matrix< std::complex< float >, tRows0, tCols0 > &  R)
friend

◆ trans [3/3]

template<typename tData, size_t tRows, size_t tCols>
template<size_t tRows0, size_t tCols0>
Matrix< std::complex<double>, tCols0, tRows0 > trans ( const Matrix< std::complex< double >, tRows0, tCols0 > &  R)
friend

Member Data Documentation

◆ iCols

template<typename tData, size_t tRows, size_t tCols>
size_t ematrix::Matrix< tData, tRows, tCols >::iCols
protected

◆ ij

template<typename tData, size_t tRows, size_t tCols>
tData* ematrix::Matrix< tData, tRows, tCols >::ij[tRows]
protected

◆ iRows

template<typename tData, size_t tRows, size_t tCols>
size_t ematrix::Matrix< tData, tRows, tCols >::iRows
protected

◆ storage

template<typename tData, size_t tRows, size_t tCols>
tData ematrix::Matrix< tData, tRows, tCols >::storage[tRows *tCols]
protected

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