Jpp
 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 35 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 41 of file JMatrixND.hh.

41  :
42  __p(NULL),
43  __n(0),
44  __m(0)
45  {}
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
double * __p
pointer to data
Definition: JMatrixND.hh:291
size_t __m
capacity of matrix
Definition: JMatrixND.hh:293
JMATH::JMatrixND_t::~JMatrixND_t ( )
inline

Destructor.

Definition at line 51 of file JMatrixND.hh.

52  {
53  clear();
54  }
void clear()
Clear memory.
Definition: JMatrixND.hh:60

Member Function Documentation

void JMATH::JMatrixND_t::clear ( )
inline

Clear memory.

Definition at line 60 of file JMatrixND.hh.

61  {
62  if (__p != NULL) {
63  delete [] __p;
64  }
65 
66  __p = NULL;
67  __n = 0;
68  __m = 0;
69  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
double * __p
pointer to data
Definition: JMatrixND.hh:291
size_t __m
capacity of matrix
Definition: JMatrixND.hh:293
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 79 of file JMatrixND.hh.

80  {
81  if (size != this->__n) {
82 
83  if (size > this->__m) {
84 
85  if (__p != NULL) {
86  delete[] __p;
87  }
88 
89  __m = size;
90  __p = new double[__m*__m];
91 
92  if (__p == NULL) {
93  THROW(JNewException, "JMatrixND::resize(" << size << "): Memory allocation failure.");
94  }
95  }
96 
97  __n = size;
98  }
99  }
#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:154
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
double * __p
pointer to data
Definition: JMatrixND.hh:291
size_t __m
capacity of matrix
Definition: JMatrixND.hh:293
void JMATH::JMatrixND_t::set ( const JMatrixND_t A)
inline

Set matrix.

Parameters
Amatrix

Definition at line 107 of file JMatrixND.hh.

108  {
109  this->resize(A.size());
110 
111  memcpy(this->data(), A.data(), A.size() * A.size() * sizeof(double));
112  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:154
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:79
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:187
void JMATH::JMatrixND_t::swap ( JMatrixND_t A)
inline

Swap matrices.

Parameters
Amatrix

Definition at line 120 of file JMatrixND.hh.

121  {
122  using std::swap;
123 
124  swap(this->__p, A.__p);
125  swap(this->__n, A.__n);
126  swap(this->__m, A.__m);
127  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
double * __p
pointer to data
Definition: JMatrixND.hh:291
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:120
size_t __m
capacity of matrix
Definition: JMatrixND.hh:293
JMatrixND_t& JMATH::JMatrixND_t::transpose ( )
inline

Transpose.

Returns
this matrix

Definition at line 135 of file JMatrixND.hh.

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

Get dimension of matrix.

Returns
dimension

Definition at line 154 of file JMatrixND.hh.

155  {
156  return __n;
157  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
size_t JMATH::JMatrixND_t::capacity ( ) const
inline

Get capacity of dimension.

Returns
capacity

Definition at line 165 of file JMatrixND.hh.

166  {
167  return __m;
168  }
size_t __m
capacity of matrix
Definition: JMatrixND.hh:293
bool JMATH::JMatrixND_t::empty ( ) const
inline

Check emptyness.

Returns
true if empty; else false

Definition at line 176 of file JMatrixND.hh.

177  {
178  return __n == 0;
179  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
const double* JMATH::JMatrixND_t::data ( ) const
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 187 of file JMatrixND.hh.

188  {
189  return __p;
190  }
double * __p
pointer to data
Definition: JMatrixND.hh:291
double* JMATH::JMatrixND_t::data ( )
inline

Get pointer to data.

Returns
pointer to data.

Definition at line 198 of file JMatrixND.hh.

199  {
200  return __p;
201  }
double * __p
pointer to data
Definition: JMatrixND.hh:291
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 210 of file JMatrixND.hh.

211  {
212  return __p + row*__n;
213  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
double * __p
pointer to data
Definition: JMatrixND.hh:291
double* JMATH::JMatrixND_t::operator[] ( size_t  row)
inline

Get row data.

Parameters
rowrow number
Returns
pointer to row data

Definition at line 222 of file JMatrixND.hh.

223  {
224  return __p + row*__n;
225  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
double * __p
pointer to data
Definition: JMatrixND.hh:291
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 235 of file JMatrixND.hh.

236  {
237  return *(__p + row*__n + col);
238  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
double * __p
pointer to data
Definition: JMatrixND.hh:291
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 248 of file JMatrixND.hh.

249  {
250  return *(__p + row*__n + col);
251  }
size_t __n
dimension of matrix
Definition: JMatrixND.hh:292
double * __p
pointer to data
Definition: JMatrixND.hh:291
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 261 of file JMatrixND.hh.

262  {
263  if (row >= this->size() ||
264  col >= this->size()) {
265  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
266  }
267 
268  return (*this)(row, col);
269  }
#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:154
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 279 of file JMatrixND.hh.

280  {
281  if (row >= this->size() ||
282  col >= this->size()) {
283  THROW(JIndexOutOfRange, "JMatrixND::at(" << row << "," << col << "): index out of range.");
284  }
285 
286  return (*this)(row, col);
287  }
#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:154
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 291 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__n
protected

dimension of matrix

Definition at line 292 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__m
protected

capacity of matrix

Definition at line 293 of file JMatrixND.hh.


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