Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
JMATH::JMatrixND_t Struct Reference

Basic NxN matrix. More...

#include <JMatrixND.hh>

Inheritance diagram for JMATH::JMatrixND_t:
JLANG::JSingleton< T > JMATH::JMatrixND JMATH::JMatrixNS JFIT::JMatrixNZ

Public Types

typedef T data_type
 

Public Member Functions

 JMatrixND_t ()
 Default constructor. More...
 
 JMatrixND_t (const JMatrixND_t &A)
 Copy constructor. More...
 
 JMatrixND_t (JMatrixND_t &&A)
 Move constructor. More...
 
 ~JMatrixND_t ()
 Destructor. More...
 
void clear ()
 Clear memory. More...
 
void resize (const size_t size)
 Resize matrix. More...
 
void set (const JMatrixND_t &A)
 Set matrix. More...
 
void swap (JMatrixND_t &A)
 Swap matrices. More...
 
JMatrixND_ttranspose ()
 Transpose. More...
 
size_t size () const
 Get dimension of matrix. More...
 
size_t capacity () const
 Get capacity of dimension. More...
 
bool empty () const
 Check emptyness. More...
 
const double * data () const
 Get pointer to data. More...
 
double * data ()
 Get pointer to data. More...
 
const double * operator[] (size_t row) const
 Get row data. More...
 
double * operator[] (size_t row)
 Get row data. More...
 
double operator() (const size_t row, const size_t col) const
 Get matrix element. More...
 
double & operator() (const size_t row, const size_t col)
 Get matrix element. More...
 
double at (size_t row, size_t col) const
 Get matrix element. More...
 
double & at (size_t row, size_t col)
 Get matrix element. More...
 

Static Public Member Functions

static data_typegetInstance ()
 Get unique instance of template class. More...
 

Protected Attributes

double * __p
 pointer to data More...
 
size_t __n
 dimension of matrix More...
 
size_t __m
 capacity of matrix More...
 

Detailed Description

Basic NxN matrix.

Definition at line 38 of file JMatrixND.hh.

Member Typedef Documentation

template<class T>
typedef T JLANG::JSingleton< T >::data_type
inherited

Definition at line 20 of file JSingleton.hh.

Constructor & Destructor Documentation

JMATH::JMatrixND_t::JMatrixND_t ( )
inline

Default constructor.

Definition at line 44 of file JMatrixND.hh.

44  :
45  __p(NULL),
46  __n(0),
47  __m(0)
48  {}
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
double * __p
pointer to data
Definition: JMatrixND.hh:318
size_t __m
capacity of matrix
Definition: JMatrixND.hh:320
JMATH::JMatrixND_t::JMatrixND_t ( const JMatrixND_t A)
inline

Copy constructor.

Parameters
Amatrix

Definition at line 56 of file JMatrixND.hh.

56  :
57  JMatrixND_t()
58  {
59  set(A);
60  }
void set(const JMatrixND_t &A)
Set matrix.
Definition: JMatrixND.hh:134
JMatrixND_t()
Default constructor.
Definition: JMatrixND.hh:44
JMATH::JMatrixND_t::JMatrixND_t ( JMatrixND_t &&  A)
inline

Move constructor.

Parameters
Amatrix

Definition at line 68 of file JMatrixND.hh.

68  :
69  JMatrixND_t()
70  {
71  swap(A);
72  }
JMatrixND_t()
Default constructor.
Definition: JMatrixND.hh:44
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:147
JMATH::JMatrixND_t::~JMatrixND_t ( )
inline

Destructor.

Definition at line 78 of file JMatrixND.hh.

79  {
80  clear();
81  }
void clear()
Clear memory.
Definition: JMatrixND.hh:87

Member Function Documentation

void JMATH::JMatrixND_t::clear ( )
inline

Clear memory.

Definition at line 87 of file JMatrixND.hh.

88  {
89  if (__p != NULL) {
90  delete [] __p;
91  }
92 
93  __p = NULL;
94  __n = 0;
95  __m = 0;
96  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
double * __p
pointer to data
Definition: JMatrixND.hh:318
size_t __m
capacity of matrix
Definition: JMatrixND.hh:320
void JMATH::JMatrixND_t::resize ( const size_t  size)
inline

Resize matrix.

Note that this method does not maintain data in the matrix.

Parameters
sizedimension

Definition at line 106 of file JMatrixND.hh.

107  {
108  if (size != this->__n) {
109 
110  if (size > this->__m) {
111 
112  if (__p != NULL) {
113  delete[] __p;
114  }
115 
116  __m = size;
117  __p = new double[__m*__m];
118 
119  if (__p == NULL) {
120  THROW(JNewException, "JMatrixND::resize(" << size << "): Memory allocation failure.");
121  }
122  }
123 
124  __n = size;
125  }
126  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:181
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
double * __p
pointer to data
Definition: JMatrixND.hh:318
size_t __m
capacity of matrix
Definition: JMatrixND.hh:320
void JMATH::JMatrixND_t::set ( const JMatrixND_t A)
inline

Set matrix.

Parameters
Amatrix

Definition at line 134 of file JMatrixND.hh.

135  {
136  this->resize(A.size());
137 
138  memcpy(this->data(), A.data(), A.size() * A.size() * sizeof(double));
139  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:181
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:106
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:214
void JMATH::JMatrixND_t::swap ( JMatrixND_t A)
inline

Swap matrices.

Parameters
Amatrix

Definition at line 147 of file JMatrixND.hh.

148  {
149  using std::swap;
150 
151  swap(this->__p, A.__p);
152  swap(this->__n, A.__n);
153  swap(this->__m, A.__m);
154  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
double * __p
pointer to data
Definition: JMatrixND.hh:318
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:147
size_t __m
capacity of matrix
Definition: JMatrixND.hh:320
JMatrixND_t& JMATH::JMatrixND_t::transpose ( )
inline

Transpose.

Returns
this matrix

Definition at line 162 of file JMatrixND.hh.

163  {
164  using std::swap;
165 
166  for (size_t row = 0; row != this->size(); ++row) {
167  for (size_t col = 0; col != row; ++col) {
168  swap((*this)(row,col), (*this)(col,row));
169  }
170  }
171 
172  return *this;
173  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:181
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:147
size_t JMATH::JMatrixND_t::size ( ) const
inline

Get dimension of matrix.

Returns
dimension

Definition at line 181 of file JMatrixND.hh.

182  {
183  return __n;
184  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
size_t JMATH::JMatrixND_t::capacity ( ) const
inline

Get capacity of dimension.

Returns
capacity

Definition at line 192 of file JMatrixND.hh.

193  {
194  return __m;
195  }
size_t __m
capacity of matrix
Definition: JMatrixND.hh:320
bool JMATH::JMatrixND_t::empty ( ) const
inline

Check emptyness.

Returns
true if empty; else false

Definition at line 203 of file JMatrixND.hh.

204  {
205  return __n == 0;
206  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
const double* JMATH::JMatrixND_t::data ( ) const
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 214 of file JMatrixND.hh.

215  {
216  return __p;
217  }
double * __p
pointer to data
Definition: JMatrixND.hh:318
double* JMATH::JMatrixND_t::data ( )
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 225 of file JMatrixND.hh.

226  {
227  return __p;
228  }
double * __p
pointer to data
Definition: JMatrixND.hh:318
const double* JMATH::JMatrixND_t::operator[] ( size_t  row) const
inline

Get row data.

Parameters
rowrow number
Returns
pointer to row data

Definition at line 237 of file JMatrixND.hh.

238  {
239  return __p + row*__n;
240  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
double * __p
pointer to data
Definition: JMatrixND.hh:318
double* JMATH::JMatrixND_t::operator[] ( size_t  row)
inline

Get row data.

Parameters
rowrow number
Returns
pointer to row data

Definition at line 249 of file JMatrixND.hh.

250  {
251  return __p + row*__n;
252  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
double * __p
pointer to data
Definition: JMatrixND.hh:318
double JMATH::JMatrixND_t::operator() ( const size_t  row,
const size_t  col 
) const
inline

Get matrix element.

Parameters
rowrow number
colcolumn number
Returns
matrix element at (row,col)

Definition at line 262 of file JMatrixND.hh.

263  {
264  return *(__p + row*__n + col);
265  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
double * __p
pointer to data
Definition: JMatrixND.hh:318
double& JMATH::JMatrixND_t::operator() ( const size_t  row,
const size_t  col 
)
inline

Get matrix element.

Parameters
rowrow number
colcolumn number
Returns
matrix element at (row,col)

Definition at line 275 of file JMatrixND.hh.

276  {
277  return *(__p + row*__n + col);
278  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:319
double * __p
pointer to data
Definition: JMatrixND.hh:318
double JMATH::JMatrixND_t::at ( size_t  row,
size_t  col 
) const
inline

Get matrix element.

Parameters
rowrow number
colcolumn number
Returns
matrix element at (row,col)

Definition at line 288 of file JMatrixND.hh.

289  {
290  if (row >= this->size() ||
291  col >= this->size()) {
292  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
293  }
294 
295  return (*this)(row, col);
296  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:181
double& JMATH::JMatrixND_t::at ( size_t  row,
size_t  col 
)
inline

Get matrix element.

Parameters
rowrow number
colcolumn number
Returns
matrix element at (row,col)

Definition at line 306 of file JMatrixND.hh.

307  {
308  if (row >= this->size() ||
309  col >= this->size()) {
310  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
311  }
312 
313  return (*this)(row, col);
314  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:181
template<class T>
static data_type& JLANG::JSingleton< T >::getInstance ( )
inlinestaticinherited

Get unique instance of template class.

Returns
object

Definition at line 27 of file JSingleton.hh.

28  {
29  static data_type value;
30 
31  return value;
32  }

Member Data Documentation

double* JMATH::JMatrixND_t::__p
protected

pointer to data

Definition at line 318 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__n
protected

dimension of matrix

Definition at line 319 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__m
protected

capacity of matrix

Definition at line 320 of file JMatrixND.hh.


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