Jpp  18.5.2
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...
 
JMatrixND_treset ()
 Set matrix to the null 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:337
double * __p
pointer to data
Definition: JMatrixND.hh:336
size_t __m
capacity of matrix
Definition: JMatrixND.hh:338
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:152
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:165
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:337
double * __p
pointer to data
Definition: JMatrixND.hh:336
size_t __m
capacity of matrix
Definition: JMatrixND.hh:338
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:712
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:199
size_t __n
dimension of matrix
Definition: JMatrixND.hh:337
double * __p
pointer to data
Definition: JMatrixND.hh:336
size_t __m
capacity of matrix
Definition: JMatrixND.hh:338
JMatrixND_t& JMATH::JMatrixND_t::reset ( )
inline

Set matrix to the null matrix.

Returns
this matrix

Definition at line 130 of file JMatrixND.hh.

131  {
132  double* p0 = this->data();
133  double* p1 = this->data();
134 
135  for (size_t i = this->size(); i != 0; --i, ++p1) {
136  *p1 = 0.0;
137  }
138 
139  for (size_t i = this->size(); i != 1; --i, p1 += this->size()) {
140  memcpy(p1, p0, this->size() * sizeof(double));
141  }
142 
143  return *this;
144  }
TPaveText * p1
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:199
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:232
void JMATH::JMatrixND_t::set ( const JMatrixND_t A)
inline

Set matrix.

Parameters
Amatrix

Definition at line 152 of file JMatrixND.hh.

153  {
154  this->resize(A.size());
155 
156  memcpy(this->data(), A.data(), A.size() * A.size() * sizeof(double));
157  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:199
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:102
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:232
void JMATH::JMatrixND_t::swap ( JMatrixND_t A)
inline

Swap matrices.

Parameters
Amatrix

Definition at line 165 of file JMatrixND.hh.

166  {
167  using std::swap;
168 
169  swap(this->__p, A.__p);
170  swap(this->__n, A.__n);
171  swap(this->__m, A.__m);
172  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:337
double * __p
pointer to data
Definition: JMatrixND.hh:336
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:165
size_t __m
capacity of matrix
Definition: JMatrixND.hh:338
JMatrixND_t& JMATH::JMatrixND_t::transpose ( )
inline

Transpose.

Returns
this matrix

Definition at line 180 of file JMatrixND.hh.

181  {
182  using std::swap;
183 
184  for (size_t row = 0; row != this->size(); ++row) {
185  for (size_t col = 0; col != row; ++col) {
186  swap((*this)(row,col), (*this)(col,row));
187  }
188  }
189 
190  return *this;
191  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:199
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:165
size_t JMATH::JMatrixND_t::size ( ) const
inline

Get dimension of matrix.

Returns
dimension

Definition at line 199 of file JMatrixND.hh.

200  {
201  return __n;
202  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:337
size_t JMATH::JMatrixND_t::capacity ( ) const
inline

Get capacity of dimension.

Returns
capacity

Definition at line 210 of file JMatrixND.hh.

211  {
212  return __m;
213  }
size_t __m
capacity of matrix
Definition: JMatrixND.hh:338
bool JMATH::JMatrixND_t::empty ( ) const
inline

Check emptyness.

Returns
true if empty; else false

Definition at line 221 of file JMatrixND.hh.

222  {
223  return __n == 0;
224  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:337
const double* JMATH::JMatrixND_t::data ( ) const
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 232 of file JMatrixND.hh.

233  {
234  return __p;
235  }
double * __p
pointer to data
Definition: JMatrixND.hh:336
double* JMATH::JMatrixND_t::data ( )
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 243 of file JMatrixND.hh.

244  {
245  return __p;
246  }
double * __p
pointer to data
Definition: JMatrixND.hh:336
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 255 of file JMatrixND.hh.

256  {
257  return __p + row*__n;
258  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:337
double * __p
pointer to data
Definition: JMatrixND.hh:336
double* JMATH::JMatrixND_t::operator[] ( size_t  row)
inline

Get row data.

Parameters
rowrow number
Returns
pointer to row data

Definition at line 267 of file JMatrixND.hh.

268  {
269  return __p + row*__n;
270  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:337
double * __p
pointer to data
Definition: JMatrixND.hh:336
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 280 of file JMatrixND.hh.

281  {
282  return *(__p + row*__n + col);
283  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:337
double * __p
pointer to data
Definition: JMatrixND.hh:336
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 293 of file JMatrixND.hh.

294  {
295  return *(__p + row*__n + col);
296  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:337
double * __p
pointer to data
Definition: JMatrixND.hh:336
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 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:712
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:199
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 324 of file JMatrixND.hh.

325  {
326  if (row >= this->size() ||
327  col >= this->size()) {
328  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
329  }
330 
331  return (*this)(row, col);
332  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:199

Member Data Documentation

double* JMATH::JMatrixND_t::__p
protected

pointer to data

Definition at line 336 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__n
protected

dimension of matrix

Definition at line 337 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__m
protected

capacity of matrix

Definition at line 338 of file JMatrixND.hh.


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