Jpp  18.0.1-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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:
JMATH::JMatrixND JMATH::JMatrixNS JFIT::JMatrixNZ

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...
 

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 36 of file JMatrixND.hh.

Constructor & Destructor Documentation

JMATH::JMatrixND_t::JMatrixND_t ( )
inline

Default constructor.

Definition at line 40 of file JMatrixND.hh.

40  :
41  __p(NULL),
42  __n(0),
43  __m(0)
44  {}
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
double * __p
pointer to data
Definition: JMatrixND.hh:314
size_t __m
capacity of matrix
Definition: JMatrixND.hh:316
JMATH::JMatrixND_t::JMatrixND_t ( const JMatrixND_t A)
inline

Copy constructor.

Parameters
Amatrix

Definition at line 52 of file JMatrixND.hh.

52  :
53  JMatrixND_t()
54  {
55  set(A);
56  }
void set(const JMatrixND_t &A)
Set matrix.
Definition: JMatrixND.hh:130
JMatrixND_t()
Default constructor.
Definition: JMatrixND.hh:40
JMATH::JMatrixND_t::JMatrixND_t ( JMatrixND_t &&  A)
inline

Move constructor.

Parameters
Amatrix

Definition at line 64 of file JMatrixND.hh.

64  :
65  JMatrixND_t()
66  {
67  swap(A);
68  }
JMatrixND_t()
Default constructor.
Definition: JMatrixND.hh:40
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:143
JMATH::JMatrixND_t::~JMatrixND_t ( )
inline

Destructor.

Definition at line 74 of file JMatrixND.hh.

75  {
76  clear();
77  }
void clear()
Clear memory.
Definition: JMatrixND.hh:83

Member Function Documentation

void JMATH::JMatrixND_t::clear ( )
inline

Clear memory.

Definition at line 83 of file JMatrixND.hh.

84  {
85  if (__p != NULL) {
86  delete [] __p;
87  }
88 
89  __p = NULL;
90  __n = 0;
91  __m = 0;
92  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
double * __p
pointer to data
Definition: JMatrixND.hh:314
size_t __m
capacity of matrix
Definition: JMatrixND.hh:316
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 102 of file JMatrixND.hh.

103  {
104  if (size != this->__n) {
105 
106  if (size > this->__m) {
107 
108  if (__p != NULL) {
109  delete[] __p;
110  }
111 
112  __m = size;
113  __p = new double[__m*__m];
114 
115  if (__p == NULL) {
116  THROW(JNewException, "JMatrixND::resize(" << size << "): Memory allocation failure.");
117  }
118  }
119 
120  __n = size;
121  }
122  }
#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:177
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
double * __p
pointer to data
Definition: JMatrixND.hh:314
size_t __m
capacity of matrix
Definition: JMatrixND.hh:316
void JMATH::JMatrixND_t::set ( const JMatrixND_t A)
inline

Set matrix.

Parameters
Amatrix

Definition at line 130 of file JMatrixND.hh.

131  {
132  this->resize(A.size());
133 
134  memcpy(this->data(), A.data(), A.size() * A.size() * sizeof(double));
135  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:102
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
void JMATH::JMatrixND_t::swap ( JMatrixND_t A)
inline

Swap matrices.

Parameters
Amatrix

Definition at line 143 of file JMatrixND.hh.

144  {
145  using std::swap;
146 
147  swap(this->__p, A.__p);
148  swap(this->__n, A.__n);
149  swap(this->__m, A.__m);
150  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
double * __p
pointer to data
Definition: JMatrixND.hh:314
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:143
size_t __m
capacity of matrix
Definition: JMatrixND.hh:316
JMatrixND_t& JMATH::JMatrixND_t::transpose ( )
inline

Transpose.

Returns
this matrix

Definition at line 158 of file JMatrixND.hh.

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

Get dimension of matrix.

Returns
dimension

Definition at line 177 of file JMatrixND.hh.

178  {
179  return __n;
180  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
size_t JMATH::JMatrixND_t::capacity ( ) const
inline

Get capacity of dimension.

Returns
capacity

Definition at line 188 of file JMatrixND.hh.

189  {
190  return __m;
191  }
size_t __m
capacity of matrix
Definition: JMatrixND.hh:316
bool JMATH::JMatrixND_t::empty ( ) const
inline

Check emptyness.

Returns
true if empty; else false

Definition at line 199 of file JMatrixND.hh.

200  {
201  return __n == 0;
202  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
const double* JMATH::JMatrixND_t::data ( ) const
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 210 of file JMatrixND.hh.

211  {
212  return __p;
213  }
double * __p
pointer to data
Definition: JMatrixND.hh:314
double* JMATH::JMatrixND_t::data ( )
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 221 of file JMatrixND.hh.

222  {
223  return __p;
224  }
double * __p
pointer to data
Definition: JMatrixND.hh:314
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 233 of file JMatrixND.hh.

234  {
235  return __p + row*__n;
236  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
double * __p
pointer to data
Definition: JMatrixND.hh:314
double* JMATH::JMatrixND_t::operator[] ( size_t  row)
inline

Get row data.

Parameters
rowrow number
Returns
pointer to row data

Definition at line 245 of file JMatrixND.hh.

246  {
247  return __p + row*__n;
248  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
double * __p
pointer to data
Definition: JMatrixND.hh:314
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 258 of file JMatrixND.hh.

259  {
260  return *(__p + row*__n + col);
261  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
double * __p
pointer to data
Definition: JMatrixND.hh:314
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 271 of file JMatrixND.hh.

272  {
273  return *(__p + row*__n + col);
274  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:315
double * __p
pointer to data
Definition: JMatrixND.hh:314
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 284 of file JMatrixND.hh.

285  {
286  if (row >= this->size() ||
287  col >= this->size()) {
288  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
289  }
290 
291  return (*this)(row, col);
292  }
#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:177
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 302 of file JMatrixND.hh.

303  {
304  if (row >= this->size() ||
305  col >= this->size()) {
306  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
307  }
308 
309  return (*this)(row, col);
310  }
#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:177

Member Data Documentation

double* JMATH::JMatrixND_t::__p
protected

pointer to data

Definition at line 314 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__n
protected

dimension of matrix

Definition at line 315 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__m
protected

capacity of matrix

Definition at line 316 of file JMatrixND.hh.


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