Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
 JMatrixND_t (const JMatrixND_t &A)
 Copy constructor.
 
 JMatrixND_t (JMatrixND_t &&A)
 Move constructor.
 
 ~JMatrixND_t ()
 Destructor.
 
void clear ()
 Clear memory.
 
void resize (const size_t size)
 Resize matrix.
 
JMatrixND_treset ()
 Set matrix to the null matrix.
 
void set (const JMatrixND_t &A)
 Set matrix.
 
void swap (JMatrixND_t &A)
 Swap matrices.
 
JMatrixND_ttranspose ()
 Transpose.
 
size_t size () const
 Get dimension of matrix.
 
size_t capacity () const
 Get capacity of dimension.
 
bool empty () const
 Check emptyness.
 
const double * data () const
 Get pointer to data.
 
double * data ()
 Get pointer to data.
 
const double * operator[] (size_t row) const
 Get row data.
 
double * operator[] (size_t row)
 Get row data.
 
double operator() (const size_t row, const size_t col) const
 Get matrix element.
 
double & operator() (const size_t row, const size_t col)
 Get matrix element.
 
double at (size_t row, size_t col) const
 Get matrix element.
 
double & at (size_t row, size_t col)
 Get matrix element.
 

Protected Attributes

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

Detailed Description

Basic NxN matrix.

Definition at line 36 of file JMatrixND.hh.

Constructor & Destructor Documentation

◆ JMatrixND_t() [1/3]

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 {}
double * __p
pointer to data
Definition JMatrixND.hh:339
size_t __m
capacity of matrix
Definition JMatrixND.hh:341
size_t __n
dimension of matrix
Definition JMatrixND.hh:340

◆ JMatrixND_t() [2/3]

JMATH::JMatrixND_t::JMatrixND_t ( const JMatrixND_t & A)
inline

Copy constructor.

Parameters
Amatrix

Definition at line 52 of file JMatrixND.hh.

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

◆ JMatrixND_t() [3/3]

JMATH::JMatrixND_t::JMatrixND_t ( JMatrixND_t && A)
inline

Move constructor.

Parameters
Amatrix

Definition at line 64 of file JMatrixND.hh.

64 :
66 {
67 swap(A);
68 }
void swap(JMatrixND_t &A)
Swap matrices.
Definition JMatrixND.hh:168

◆ ~JMatrixND_t()

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

◆ clear()

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 }

◆ resize()

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.
size_t size() const
Get dimension of matrix.
Definition JMatrixND.hh:202

◆ reset()

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 if (!this->empty()) {
136
137 for (size_t i = this->size(); i != 0; --i, ++p1) {
138 *p1 = 0.0;
139 }
140
141 for (size_t i = this->size(); i != 1; --i, p1 += this->size()) {
142 memcpy(p1, p0, this->size() * sizeof(double));
143 }
144 }
145
146 return *this;
147 }
TPaveText * p1
const double * data() const
Get pointer to data.
Definition JMatrixND.hh:235
bool empty() const
Check emptyness.
Definition JMatrixND.hh:224

◆ set()

void JMATH::JMatrixND_t::set ( const JMatrixND_t & A)
inline

Set matrix.

Parameters
Amatrix

Definition at line 155 of file JMatrixND.hh.

156 {
157 this->resize(A.size());
158
159 memcpy(this->data(), A.data(), A.size() * A.size() * sizeof(double));
160 }
void resize(const size_t size)
Resize matrix.
Definition JMatrixND.hh:102

◆ swap()

void JMATH::JMatrixND_t::swap ( JMatrixND_t & A)
inline

Swap matrices.

Parameters
Amatrix

Definition at line 168 of file JMatrixND.hh.

169 {
170 using std::swap;
171
172 swap(this->__p, A.__p);
173 swap(this->__n, A.__n);
174 swap(this->__m, A.__m);
175 }

◆ transpose()

JMatrixND_t & JMATH::JMatrixND_t::transpose ( )
inline

Transpose.

Returns
this matrix

Definition at line 183 of file JMatrixND.hh.

184 {
185 using std::swap;
186
187 for (size_t row = 0; row != this->size(); ++row) {
188 for (size_t col = 0; col != row; ++col) {
189 swap((*this)(row,col), (*this)(col,row));
190 }
191 }
192
193 return *this;
194 }

◆ size()

size_t JMATH::JMatrixND_t::size ( ) const
inline

Get dimension of matrix.

Returns
dimension

Definition at line 202 of file JMatrixND.hh.

203 {
204 return __n;
205 }

◆ capacity()

size_t JMATH::JMatrixND_t::capacity ( ) const
inline

Get capacity of dimension.

Returns
capacity

Definition at line 213 of file JMatrixND.hh.

214 {
215 return __m;
216 }

◆ empty()

bool JMATH::JMatrixND_t::empty ( ) const
inline

Check emptyness.

Returns
true if empty; else false

Definition at line 224 of file JMatrixND.hh.

225 {
226 return __n == 0;
227 }

◆ data() [1/2]

const double * JMATH::JMatrixND_t::data ( ) const
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 235 of file JMatrixND.hh.

236 {
237 return __p;
238 }

◆ data() [2/2]

double * JMATH::JMatrixND_t::data ( )
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 246 of file JMatrixND.hh.

247 {
248 return __p;
249 }

◆ operator[]() [1/2]

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

259 {
260 return __p + row*__n;
261 }

◆ operator[]() [2/2]

double * JMATH::JMatrixND_t::operator[] ( size_t row)
inline

Get row data.

Parameters
rowrow number
Returns
pointer to row data

Definition at line 270 of file JMatrixND.hh.

271 {
272 return __p + row*__n;
273 }

◆ operator()() [1/2]

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

284 {
285 return *(__p + row*__n + col);
286 }

◆ operator()() [2/2]

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

297 {
298 return *(__p + row*__n + col);
299 }

◆ at() [1/2]

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

310 {
311 if (row >= this->size() ||
312 col >= this->size()) {
313 THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
314 }
315
316 return (*this)(row, col);
317 }

◆ at() [2/2]

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

328 {
329 if (row >= this->size() ||
330 col >= this->size()) {
331 THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
332 }
333
334 return (*this)(row, col);
335 }

Member Data Documentation

◆ __p

double* JMATH::JMatrixND_t::__p
protected

pointer to data

Definition at line 339 of file JMatrixND.hh.

◆ __n

size_t JMATH::JMatrixND_t::__n
protected

dimension of matrix

Definition at line 340 of file JMatrixND.hh.

◆ __m

size_t JMATH::JMatrixND_t::__m
protected

capacity of matrix

Definition at line 341 of file JMatrixND.hh.


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