Jpp  15.0.1
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 Member Functions | Protected Attributes | Friends | List of all members
JMATH::JMatrixND Struct Reference

NxN matrix. More...

#include <JMatrixND.hh>

Inheritance diagram for JMATH::JMatrixND:
JMATH::JMatrixND_t JMATH::JMath< JMatrixND > JLANG::JEquals< JFirst_t, JSecond_t > JLANG::JSingleton< T > JMATH::JMatrixNS JFIT::JMatrixNZ

Public Types

typedef T data_type
 

Public Member Functions

 JMatrixND ()
 Default constructor. More...
 
 JMatrixND (const size_t size)
 Constructor. More...
 
 JMatrixND (const JMatrixND &A)
 Copy constructor. More...
 
JMatrixNDoperator= (const JMatrixND &A)
 Assignment operator. More...
 
void resize (const size_t size)
 Resize matrix. More...
 
JMatrixNDreset ()
 Set matrix to the null matrix. More...
 
JMatrixNDsetIdentity ()
 Set to identity matrix. More...
 
JMatrixNDnegate ()
 Negate matrix. More...
 
JMatrixNDadd (const JMatrixND &A)
 Matrix addition. More...
 
JMatrixNDsub (const JMatrixND &A)
 Matrix subtraction. More...
 
JMatrixNDmul (const double factor)
 Scale matrix. More...
 
JMatrixNDdiv (const double factor)
 Scale matrix. More...
 
JMatrixNDmul (const JMatrixND &A, const JMatrixND &B)
 Matrix multiplication. More...
 
bool equals (const JMatrixND &A, const double eps=std::numeric_limits< double >::min()) const
 Equality. More...
 
bool isIdentity (const double eps=std::numeric_limits< double >::min()) const
 Test identity. More...
 
bool isSymmetric (const double eps=std::numeric_limits< double >::min()) const
 Test symmetry. More...
 
double getDot (const JVectorND &v) const
 Get dot product. More...
 
void clear ()
 Clear memory. 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...
 
JMatrixNDmul (const JNullType &object)
 Multiply with object. More...
 

Static Public Member Functions

static data_typegetInstance ()
 Get unique instance of template class. More...
 

Protected Member Functions

void rswap (size_t r1, size_t r2)
 
void cswap (size_t c1, size_t c2)
 Swap columns. More...
 

Protected Attributes

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

Friends

JReaderoperator>> (JReader &in, JMatrixND &A)
 Read matrix from input. More...
 
JWriteroperator<< (JWriter &out, const JMatrixND &A)
 Write matrix to output. More...
 
std::ostream & operator<< (std::ostream &out, const JMatrixND &A)
 Print ASCII formatted output. More...
 

Detailed Description

NxN matrix.

Definition at line 303 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::JMatrixND ( )
inline

Default constructor.

Definition at line 313 of file JMatrixND.hh.

314  {}
JMATH::JMatrixND::JMatrixND ( const size_t  size)
inline

Constructor.

The matrix is set to zero.

Parameters
sizedimension

Definition at line 324 of file JMatrixND.hh.

325  {
326  resize(size);
327  reset();
328  }
JMatrixND & reset()
Set matrix to the null matrix.
Definition: JMatrixND.hh:375
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:362
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
JMATH::JMatrixND::JMatrixND ( const JMatrixND A)
inline

Copy constructor.

Parameters
Amatrix

Definition at line 336 of file JMatrixND.hh.

337  {
338  set(A);
339  }
void set(const JMatrixND_t &A)
Set matrix.
Definition: JMatrixND.hh:110

Member Function Documentation

JMatrixND& JMATH::JMatrixND::operator= ( const JMatrixND A)
inline

Assignment operator.

Parameters
Amatrix

Definition at line 347 of file JMatrixND.hh.

348  {
349  this->set(A);
350 
351  return *this;
352  }
void set(const JMatrixND_t &A)
Set matrix.
Definition: JMatrixND.hh:110
void JMATH::JMatrixND::resize ( const size_t  size)
inline

Resize matrix.

Note that this method does not maintain data in the matrix.

Parameters
sizedimension

Definition at line 362 of file JMatrixND.hh.

363  {
364  static_cast<JMatrixND_t&>(*this).resize(size);
365 
366  getInstance().resize(size);
367  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
static data_type & getInstance()
Get unique instance of template class.
Definition: JSingleton.hh:27
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:82
Basic NxN matrix.
Definition: JMatrixND.hh:38
JMatrixND& JMATH::JMatrixND::reset ( )
inline

Set matrix to the null matrix.

Returns
this matrix

Definition at line 375 of file JMatrixND.hh.

376  {
378 
379  double* p = A.data();
380 
381  for (size_t i = this->size(); i != 0; --i, ++p) {
382  *p = 0.0;
383  }
384 
385  p = this->data();
386 
387  for (size_t i = this->size(); i != 0; --i, p += this->size()) {
388  memcpy(p, A.data(), this->size() * sizeof(double));
389  }
390 
391  return *this;
392  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
static data_type & getInstance()
Get unique instance of template class.
Definition: JSingleton.hh:27
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
Basic NxN matrix.
Definition: JMatrixND.hh:38
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A
JMatrixND& JMATH::JMatrixND::setIdentity ( )
inline

Set to identity matrix.

Returns
this matrix

Definition at line 400 of file JMatrixND.hh.

401  {
402  reset();
403 
404  for (size_t i = 0; i != this->size(); ++i) {
405  (*this)(i,i) = 1.0;
406  }
407 
408  return *this;
409  }
JMatrixND & reset()
Set matrix to the null matrix.
Definition: JMatrixND.hh:375
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
JMatrixND& JMATH::JMatrixND::negate ( )
inline

Negate matrix.

Returns
this matrix

Definition at line 417 of file JMatrixND.hh.

418  {
419  double* p = this->data();
420 
421  for (size_t i = this->size()*this->size(); i != 0; --i, ++p) {
422  *p = -*p;
423  }
424 
425  return *this;
426  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
JMatrixND& JMATH::JMatrixND::add ( const JMatrixND A)
inline

Matrix addition.

Parameters
Amatrix
Returns
this matrix

Definition at line 435 of file JMatrixND.hh.

436  {
437  if (this->size() == A.size()) {
438 
439  double* p = this->data();
440  const double* q = A.data();
441 
442  for (size_t i = this->size()*this->size(); i != 0; --i, ++p, ++q) {
443  *p += *q;
444  }
445 
446  } else {
447  THROW(JException, "JMatrixND::add() inconsistent matrix dimensions " << this->size() << ' ' << A.size());
448  }
449  }
#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
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
JMatrixND& JMATH::JMatrixND::sub ( const JMatrixND A)
inline

Matrix subtraction.

Parameters
Amatrix
Returns
this matrix

Definition at line 458 of file JMatrixND.hh.

459  {
460  if (this->size() == A.size()) {
461 
462  double* p = this->data();
463  const double* q = A.data();
464 
465  for (size_t i = this->size()*this->size(); i != 0; --i, ++p, ++q) {
466  *p -= *q;
467  }
468 
469  } else {
470  THROW(JException, "JMatrixND::sub() inconsistent matrix dimensions " << this->size() << ' ' << A.size());
471  }
472 
473  return *this;
474  }
#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
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
JMatrixND& JMATH::JMatrixND::mul ( const double  factor)
inline

Scale matrix.

Parameters
factorfactor
Returns
this matrix

Definition at line 483 of file JMatrixND.hh.

484  {
485  double* p = this->data();
486 
487  for (size_t i = this->size()*this->size(); i != 0; --i, ++p) {
488  *p *= factor;
489  }
490 
491  return *this;
492  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
JMatrixND& JMATH::JMatrixND::div ( const double  factor)
inline

Scale matrix.

Parameters
factorfactor
Returns
this matrix

Definition at line 501 of file JMatrixND.hh.

502  {
503  double* p = this->data();
504 
505  for (size_t i = this->size()*this->size(); i != 0; --i, ++p) {
506  *p /= factor;
507  }
508 
509  return *this;
510  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
JMatrixND& JMATH::JMatrixND::mul ( const JMatrixND A,
const JMatrixND B 
)
inline

Matrix multiplication.

Parameters
Amatrix
Bmatrix
Returns
this matrix

Definition at line 520 of file JMatrixND.hh.

522  {
523  if (A.size() == B.size()) {
524 
525  this->resize(A.size());
526 
527  if (!this->empty()) {
528 
530 
531  C.set(B);
532  C.transpose();
533 
534  size_t i, row;
535 
536  for (row = 0; row + 4 <= this->size(); row += 4) { // process rows by four
537 
538  double* p0 = (*this)[row + 0];
539  double* p1 = (*this)[row + 1];
540  double* p2 = (*this)[row + 2];
541  double* p3 = (*this)[row + 3];
542 
543  for (size_t col = 0; col != this->size(); ++col, ++p0, ++p1, ++p2, ++p3) {
544 
545  double w0 = 0.0;
546  double w1 = 0.0;
547  double w2 = 0.0;
548  double w3 = 0.0;
549 
550  const double* a0 = A[row + 0];
551  const double* a1 = A[row + 1];
552  const double* a2 = A[row + 2];
553  const double* a3 = A[row + 3];
554 
555  const double* c0 = C[col];
556 
557  for (i = 0; i + 4 <= this->size(); i += 4, a0 += 4, a1 += 4, a2 += 4, a3 += 4, c0 += 4) {
558  w0 += a0[0] * c0[0] + a0[1] * c0[1] + a0[2] * c0[2] + a0[3] * c0[3];
559  w1 += a1[0] * c0[0] + a1[1] * c0[1] + a1[2] * c0[2] + a1[3] * c0[3];
560  w2 += a2[0] * c0[0] + a2[1] * c0[1] + a2[2] * c0[2] + a2[3] * c0[3];
561  w3 += a3[0] * c0[0] + a3[1] * c0[1] + a3[2] * c0[2] + a3[3] * c0[3];
562  }
563 
564  for ( ; i != this->size(); ++i, ++a0, ++a1, ++a2, ++a3, ++c0) {
565  w0 += (*a0) * (*c0);
566  w1 += (*a1) * (*c0);
567  w2 += (*a2) * (*c0);
568  w3 += (*a3) * (*c0);
569  }
570 
571  *p0 = w0;
572  *p1 = w1;
573  *p2 = w2;
574  *p3 = w3;
575  }
576  }
577 
578  for ( ; row != this->size(); ++row) { // remaining rows
579 
580  double* p0 = (*this)[row + 0];
581 
582  for (size_t col = 0; col != this->size(); ++col, ++p0) {
583 
584  double w0 = 0.0;
585 
586  const double* a0 = A[row + 0];
587  const double* c0 = C[col];
588 
589  for (i = 0; i + 4 <= this->size(); i += 4, a0 += 4, c0 += 4) {
590  w0 += a0[0] * c0[0] + a0[1] * c0[1] + a0[2] * c0[2] + a0[3] * c0[3];
591  }
592 
593  for ( ; i != this->size(); ++i, ++a0, ++c0) {
594  w0 += (*a0) * (*c0);
595  }
596 
597  *p0 = w0;
598  }
599  }
600  }
601 
602  } else {
603  THROW(JException, "JMatrixND::mul() inconsistent matrix dimensions " << A.size() << ' ' << B.size());
604  }
605 
606  return *this;
607  }
TPaveText * p1
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:362
static const double C
Physics constants.
void set(const JMatrixND_t &A)
Set matrix.
Definition: JMatrixND.hh:110
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
p2
Definition: module-Z:fit.sh:74
static data_type & getInstance()
Get unique instance of template class.
Definition: JSingleton.hh:27
JMatrixND_t & transpose()
Transpose.
Definition: JMatrixND.hh:138
bool empty() const
Check emptyness.
Definition: JMatrixND.hh:179
p3
Definition: module-Z:fit.sh:74
Basic NxN matrix.
Definition: JMatrixND.hh:38
bool JMATH::JMatrixND::equals ( const JMatrixND A,
const double  eps = std::numeric_limits<double>::min() 
) const
inline

Equality.

Parameters
Amatrix
epsnumerical precision
Returns
true if matrices identical; else false

Definition at line 617 of file JMatrixND.hh.

619  {
620  if (this->size() == A.size()) {
621 
622  for (size_t row = 0; row != this->size(); ++row) {
623 
624  const double* p = (*this)[row];
625  const double* q = A [row];
626 
627  for (size_t i = this->size(); i != 0; --i, ++p, ++q) {
628  if (fabs(*p - *q) > eps) {
629  return false;
630  }
631  }
632  }
633 
634  return true;
635 
636  } else {
637  THROW(JException, "JMatrixND::equals() inconsistent matrix dimensions " << this->size() << ' ' << A.size());
638  }
639  }
#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
bool JMATH::JMatrixND::isIdentity ( const double  eps = std::numeric_limits<double>::min()) const
inline

Test identity.

Parameters
epsnumerical precision
Returns
true if identity matrix; else false

Definition at line 648 of file JMatrixND.hh.

649  {
650  for (size_t i = 0; i != this->size(); ++i) {
651 
652  if (fabs(1.0 - (*this)(i,i)) > eps) {
653  return false;
654  };
655 
656  for (size_t j = 0; j != i; ++j) {
657  if (fabs((*this)(i,j)) > eps || fabs((*this)(j,i)) > eps) {
658  return false;
659  };
660  }
661  }
662 
663  return true;
664  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
int j
Definition: JPolint.hh:666
bool JMATH::JMatrixND::isSymmetric ( const double  eps = std::numeric_limits<double>::min()) const
inline

Test symmetry.

Parameters
epsnumerical precision
Returns
true if symmetric matrix; else false

Definition at line 673 of file JMatrixND.hh.

674  {
675  for (size_t i = 0; i != this->size(); ++i) {
676  for (size_t j = 0; j != i; ++j) {
677  if (fabs((*this)(i,j) - (*this)(j,i)) > eps) {
678  return false;
679  };
680  }
681  }
682 
683  return true;
684  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
int j
Definition: JPolint.hh:666
double JMATH::JMatrixND::getDot ( const JVectorND v) const
inline

Get dot product.

The dot product corresponds to

\[ v^{T} \times A \times v \]

.

Parameters
vvector
Returns
dot product

Definition at line 695 of file JMatrixND.hh.

696  {
697  double dot = 0.0;
698 
699  for (size_t i = 0; i != v.size(); ++i) {
700 
701  const double* p = (*this)[i];
702 
703  double w = 0.0;
704 
705  for (JVectorND::const_iterator y = v.begin(); y != v.end(); ++y, ++p) {
706  w += (*p) * (*y);
707  }
708 
709  dot += v[i] * w;
710  }
711 
712  return dot;
713  }
data_type w[N+1][M+1]
Definition: JPolint.hh:741
void JMATH::JMatrixND::rswap ( size_t  r1,
size_t  r2 
)
inlineprotected

Definition at line 795 of file JMatrixND.hh.

796  {
798 
799  memcpy(A.data(), (*this)[r1], this->size() * sizeof(double));
800  memcpy((*this)[r1], (*this)[r2], this->size() * sizeof(double));
801  memcpy((*this)[r2], A.data(), this->size() * sizeof(double));
802  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
static data_type & getInstance()
Get unique instance of template class.
Definition: JSingleton.hh:27
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
Basic NxN matrix.
Definition: JMatrixND.hh:38
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A
void JMATH::JMatrixND::cswap ( size_t  c1,
size_t  c2 
)
inlineprotected

Swap columns.

Parameters
c1column
c2column

Definition at line 811 of file JMatrixND.hh.

812  {
813  using std::swap;
814 
815  double* p1 = this->data() + c1;
816  double* p2 = this->data() + c2;
817 
818  for (size_t i = this->size(); i != 0; --i, p1 += this->size(), p2 += this->size()) {
819  swap(*p1, *p2);
820  }
821  }
TPaveText * p1
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
TCanvas * c1
Global variables to handle mouse events.
p2
Definition: module-Z:fit.sh:74
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:123
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
void JMATH::JMatrixND_t::clear ( )
inlineinherited

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::set ( const JMatrixND_t A)
inlineinherited

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)
inlineinherited

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 ( )
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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 ( )
inlineinherited

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
inlineinherited

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)
inlineinherited

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
inlineinherited

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 
)
inlineinherited

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
inlineinherited

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 
)
inlineinherited

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  }
JMatrixND & JMATH::JMath< JMatrixND , JNullType >::mul ( const JNullType object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 357 of file JMath.hh.

358  {
359  return static_cast<JFirst_t&>(*this) = JCalculator<JFirst_t>::calculator.mul(static_cast<const JFirst_t&>(*this), object);
360  }
Auxiliary class for arithmetic operations on objects.
Definition: JCalculator.hh:18

Friends And Related Function Documentation

JReader& operator>> ( JReader in,
JMatrixND A 
)
friend

Read matrix from input.

Parameters
inreader
Amatrix
Returns
reader

Definition at line 723 of file JMatrixND.hh.

724  {
725  size_t size;
726 
727  in >> size;
728 
729  A.resize(size);
730 
731  size_t n = A.size() * A.size();
732 
733  for (double* p = A.data(); n != 0; --n, ++p) {
734  in >> *p;
735  }
736 
737  return in;
738  }
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:362
const int n
Definition: JPolint.hh:660
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
JWriter& operator<< ( JWriter out,
const JMatrixND A 
)
friend

Write matrix to output.

Parameters
outwriter
Amatrix
Returns
writer

Definition at line 748 of file JMatrixND.hh.

749  {
750  out << A.size();
751 
752  size_t n = A.size() * A.size();
753 
754  for (const double* p = A.data(); n != 0; --n, ++p) {
755  out << *p;
756  }
757 
758  return out;
759  }
const int n
Definition: JPolint.hh:660
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:190
std::ostream& operator<< ( std::ostream &  out,
const JMatrixND A 
)
friend

Print ASCII formatted output.

Parameters
outoutput stream
Amatrix
Returns
output stream

Definition at line 769 of file JMatrixND.hh.

770  {
771  using namespace std;
772 
773  const JFormat format(out, getFormat<JMatrixND>(JFormat_t(10, 3, std::ios::fixed | std::ios::showpos)));
774 
775  for (size_t row = 0; row != A.size(); ++row) {
776 
777  for (size_t col = 0; col != A.size(); ++col) {
778  out << format << A(row,col) << ' ';
779  }
780 
781  out << endl;
782  }
783 
784  return out;
785  }
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:632
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:157
Data structure for format specifications.
Definition: JManip.hh:522
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A

Member Data Documentation

double* JMATH::JMatrixND_t::__p
protectedinherited

pointer to data

Definition at line 294 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__n
protectedinherited

dimension of matrix

Definition at line 295 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__m
protectedinherited

capacity of matrix

Definition at line 296 of file JMatrixND.hh.


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