Jpp  15.0.0-rc.2
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 ()
 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:295
double * __p
pointer to data
Definition: JMatrixND.hh:294
size_t __m
capacity of matrix
Definition: JMatrixND.hh:296
JMATH::JMatrixND_t::~JMatrixND_t ( )
inline

Destructor.

Definition at line 54 of file JMatrixND.hh.

55  {
56  clear();
57  }
void clear()
Clear memory.
Definition: JMatrixND.hh:63

Member Function Documentation

void JMATH::JMatrixND_t::clear ( )
inline

Clear memory.

Definition at line 63 of file JMatrixND.hh.

64  {
65  if (__p != NULL) {
66  delete [] __p;
67  }
68 
69  __p = NULL;
70  __n = 0;
71  __m = 0;
72  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
double * __p
pointer to data
Definition: JMatrixND.hh:294
size_t __m
capacity of matrix
Definition: JMatrixND.hh:296
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 82 of file JMatrixND.hh.

83  {
84  if (size != this->__n) {
85 
86  if (size > this->__m) {
87 
88  if (__p != NULL) {
89  delete[] __p;
90  }
91 
92  __m = size;
93  __p = new double[__m*__m];
94 
95  if (__p == NULL) {
96  THROW(JNewException, "JMatrixND::resize(" << size << "): Memory allocation failure.");
97  }
98  }
99 
100  __n = size;
101  }
102  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
double * __p
pointer to data
Definition: JMatrixND.hh:294
size_t __m
capacity of matrix
Definition: JMatrixND.hh:296
void JMATH::JMatrixND_t::set ( const JMatrixND_t A)
inline

Set matrix.

Parameters
Amatrix

Definition at line 110 of file JMatrixND.hh.

111  {
112  this->resize(A.size());
113 
114  memcpy(this->data(), A.data(), A.size() * A.size() * sizeof(double));
115  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:82
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
void JMATH::JMatrixND_t::swap ( JMatrixND_t A)
inline

Swap matrices.

Parameters
Amatrix

Definition at line 123 of file JMatrixND.hh.

124  {
125  using std::swap;
126 
127  swap(this->__p, A.__p);
128  swap(this->__n, A.__n);
129  swap(this->__m, A.__m);
130  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
double * __p
pointer to data
Definition: JMatrixND.hh:294
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:123
size_t __m
capacity of matrix
Definition: JMatrixND.hh:296
JMatrixND_t& JMATH::JMatrixND_t::transpose ( )
inline

Transpose.

Returns
this matrix

Definition at line 138 of file JMatrixND.hh.

139  {
140  using std::swap;
141 
142  for (size_t row = 0; row != this->size(); ++row) {
143  for (size_t col = 0; col != row; ++col) {
144  swap((*this)(row,col), (*this)(col,row));
145  }
146  }
147 
148  return *this;
149  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:123
size_t JMATH::JMatrixND_t::size ( ) const
inline

Get dimension of matrix.

Returns
dimension

Definition at line 157 of file JMatrixND.hh.

158  {
159  return __n;
160  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
size_t JMATH::JMatrixND_t::capacity ( ) const
inline

Get capacity of dimension.

Returns
capacity

Definition at line 168 of file JMatrixND.hh.

169  {
170  return __m;
171  }
size_t __m
capacity of matrix
Definition: JMatrixND.hh:296
bool JMATH::JMatrixND_t::empty ( ) const
inline

Check emptyness.

Returns
true if empty; else false

Definition at line 179 of file JMatrixND.hh.

180  {
181  return __n == 0;
182  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
const double* JMATH::JMatrixND_t::data ( ) const
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 190 of file JMatrixND.hh.

191  {
192  return __p;
193  }
double * __p
pointer to data
Definition: JMatrixND.hh:294
double* JMATH::JMatrixND_t::data ( )
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 201 of file JMatrixND.hh.

202  {
203  return __p;
204  }
double * __p
pointer to data
Definition: JMatrixND.hh:294
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 213 of file JMatrixND.hh.

214  {
215  return __p + row*__n;
216  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
double * __p
pointer to data
Definition: JMatrixND.hh:294
double* JMATH::JMatrixND_t::operator[] ( size_t  row)
inline

Get row data.

Parameters
rowrow number
Returns
pointer to row data

Definition at line 225 of file JMatrixND.hh.

226  {
227  return __p + row*__n;
228  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
double * __p
pointer to data
Definition: JMatrixND.hh:294
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 238 of file JMatrixND.hh.

239  {
240  return *(__p + row*__n + col);
241  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
double * __p
pointer to data
Definition: JMatrixND.hh:294
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 251 of file JMatrixND.hh.

252  {
253  return *(__p + row*__n + col);
254  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:295
double * __p
pointer to data
Definition: JMatrixND.hh:294
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 264 of file JMatrixND.hh.

265  {
266  if (row >= this->size() ||
267  col >= this->size()) {
268  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
269  }
270 
271  return (*this)(row, col);
272  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
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 282 of file JMatrixND.hh.

283  {
284  if (row >= this->size() ||
285  col >= this->size()) {
286  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
287  }
288 
289  return (*this)(row, col);
290  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
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 294 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__n
protected

dimension of matrix

Definition at line 295 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__m
protected

capacity of matrix

Definition at line 296 of file JMatrixND.hh.


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