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

Public Member Functions

 JMatrixND ()
 Default constructor. More...
 
 JMatrixND (const size_t size)
 Constructor. More...
 
 JMatrixND (const JMatrixND &A)
 Copy constructor. More...
 
 JMatrixND (JMatrixND &&A)
 Move constructor. More...
 
JMatrixNDoperator= (const JMatrixND &A)
 Assignment operator. More...
 
JMatrixNDoperator= (JMatrixND &&A)
 Move 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...
 

Protected Member Functions

JMatrixND_tgetInstance ()
 Get work space. More...
 
void rswap (size_t r1, size_t r2)
 
void cswap (size_t c1, size_t c2)
 Swap columns. More...
 

Protected Attributes

JMatrixND_t ws
 
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 323 of file JMatrixND.hh.

Constructor & Destructor Documentation

JMATH::JMatrixND::JMatrixND ( )
inline

Default constructor.

Definition at line 348 of file JMatrixND.hh.

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

Constructor.

The matrix is set to zero.

Parameters
sizedimension

Definition at line 359 of file JMatrixND.hh.

360  {
361  resize(size);
362  reset();
363  }
JMatrixND & reset()
Set matrix to the null matrix.
Definition: JMatrixND.hh:434
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:421
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
JMATH::JMatrixND::JMatrixND ( const JMatrixND A)
inline

Copy constructor.

Parameters
Amatrix

Definition at line 371 of file JMatrixND.hh.

372  {
373  set(A);
374  }
void set(const JMatrixND_t &A)
Set matrix.
Definition: JMatrixND.hh:130
JMATH::JMatrixND::JMatrixND ( JMatrixND &&  A)
inline

Move constructor.

Parameters
Amatrix

Definition at line 382 of file JMatrixND.hh.

383  {
384  swap(A);
385  }
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:143

Member Function Documentation

JMatrixND_t& JMATH::JMatrixND::getInstance ( )
inlineprotected

Get work space.

Returns
work space

Definition at line 336 of file JMatrixND.hh.

337  {
338  return ws;
339  }
JMatrixND_t ws
Definition: JMatrixND.hh:329
JMatrixND& JMATH::JMatrixND::operator= ( const JMatrixND A)
inline

Assignment operator.

Parameters
Amatrix

Definition at line 393 of file JMatrixND.hh.

394  {
395  this->set(A);
396 
397  return *this;
398  }
void set(const JMatrixND_t &A)
Set matrix.
Definition: JMatrixND.hh:130
JMatrixND& JMATH::JMatrixND::operator= ( JMatrixND &&  A)
inline

Move assignment operator.

Parameters
Amatrix

Definition at line 406 of file JMatrixND.hh.

407  {
408  this->swap(A);
409 
410  return *this;
411  }
void swap(JMatrixND_t &A)
Swap matrices.
Definition: JMatrixND.hh:143
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 421 of file JMatrixND.hh.

422  {
423  static_cast<JMatrixND_t&>(*this).resize(size);
424 
426  }
JMatrixND_t & getInstance()
Get work space.
Definition: JMatrixND.hh:336
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:102
Basic NxN matrix.
Definition: JMatrixND.hh:36
JMatrixND& JMATH::JMatrixND::reset ( )
inline

Set matrix to the null matrix.

Returns
this matrix

Definition at line 434 of file JMatrixND.hh.

435  {
437 
438  A.resize(this->size());
439 
440  double* p = A.data();
441 
442  for (size_t i = this->size(); i != 0; --i, ++p) {
443  *p = 0.0;
444  }
445 
446  p = this->data();
447 
448  for (size_t i = this->size(); i != 0; --i, p += this->size()) {
449  memcpy(p, A.data(), this->size() * sizeof(double));
450  }
451 
452  return *this;
453  }
JMatrixND_t & getInstance()
Get work space.
Definition: JMatrixND.hh:336
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:102
source $JPP_DIR setenv csh $JPP_DIR &dev null eval JShellParser o a A
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
Basic NxN matrix.
Definition: JMatrixND.hh:36
JMatrixND& JMATH::JMatrixND::setIdentity ( )
inline

Set to identity matrix.

Returns
this matrix

Definition at line 461 of file JMatrixND.hh.

462  {
463  reset();
464 
465  for (size_t i = 0; i != this->size(); ++i) {
466  (*this)(i,i) = 1.0;
467  }
468 
469  return *this;
470  }
JMatrixND & reset()
Set matrix to the null matrix.
Definition: JMatrixND.hh:434
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
JMatrixND& JMATH::JMatrixND::negate ( )
inline

Negate matrix.

Returns
this matrix

Definition at line 478 of file JMatrixND.hh.

479  {
480  double* p = this->data();
481 
482  for (size_t i = this->size()*this->size(); i != 0; --i, ++p) {
483  *p = -*p;
484  }
485 
486  return *this;
487  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
JMatrixND& JMATH::JMatrixND::add ( const JMatrixND A)
inline

Matrix addition.

Parameters
Amatrix
Returns
this matrix

Definition at line 496 of file JMatrixND.hh.

497  {
498  if (this->size() == A.size()) {
499 
500  double* p = this->data();
501  const double* q = A.data();
502 
503  for (size_t i = this->size()*this->size(); i != 0; --i, ++p, ++q) {
504  *p += *q;
505  }
506 
507  } else {
508  THROW(JException, "JMatrixND::add() inconsistent matrix dimensions " << this->size() << ' ' << A.size());
509  }
510  }
#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
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
JMatrixND& JMATH::JMatrixND::sub ( const JMatrixND A)
inline

Matrix subtraction.

Parameters
Amatrix
Returns
this matrix

Definition at line 519 of file JMatrixND.hh.

520  {
521  if (this->size() == A.size()) {
522 
523  double* p = this->data();
524  const double* q = A.data();
525 
526  for (size_t i = this->size()*this->size(); i != 0; --i, ++p, ++q) {
527  *p -= *q;
528  }
529 
530  } else {
531  THROW(JException, "JMatrixND::sub() inconsistent matrix dimensions " << this->size() << ' ' << A.size());
532  }
533 
534  return *this;
535  }
#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
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
JMatrixND& JMATH::JMatrixND::mul ( const double  factor)
inline

Scale matrix.

Parameters
factorfactor
Returns
this matrix

Definition at line 544 of file JMatrixND.hh.

545  {
546  double* p = this->data();
547 
548  for (size_t i = this->size()*this->size(); i != 0; --i, ++p) {
549  *p *= factor;
550  }
551 
552  return *this;
553  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
JMatrixND& JMATH::JMatrixND::div ( const double  factor)
inline

Scale matrix.

Parameters
factorfactor
Returns
this matrix

Definition at line 562 of file JMatrixND.hh.

563  {
564  double* p = this->data();
565 
566  for (size_t i = this->size()*this->size(); i != 0; --i, ++p) {
567  *p /= factor;
568  }
569 
570  return *this;
571  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
JMatrixND& JMATH::JMatrixND::mul ( const JMatrixND A,
const JMatrixND B 
)
inline

Matrix multiplication.

Parameters
Amatrix
Bmatrix
Returns
this matrix

Definition at line 581 of file JMatrixND.hh.

583  {
584  if (A.size() == B.size()) {
585 
586  this->resize(A.size());
587 
588  if (!this->empty()) {
589 
591 
592  C.set(B);
593  C.transpose();
594 
595  size_t i, row;
596 
597  for (row = 0; row + 4 <= this->size(); row += 4) { // process rows by four
598 
599  double* p0 = (*this)[row + 0];
600  double* p1 = (*this)[row + 1];
601  double* p2 = (*this)[row + 2];
602  double* p3 = (*this)[row + 3];
603 
604  for (size_t col = 0; col != this->size(); ++col, ++p0, ++p1, ++p2, ++p3) {
605 
606  double w0 = 0.0;
607  double w1 = 0.0;
608  double w2 = 0.0;
609  double w3 = 0.0;
610 
611  const double* a0 = A[row + 0];
612  const double* a1 = A[row + 1];
613  const double* a2 = A[row + 2];
614  const double* a3 = A[row + 3];
615 
616  const double* c0 = C[col];
617 
618  for (i = 0; i + 4 <= this->size(); i += 4, a0 += 4, a1 += 4, a2 += 4, a3 += 4, c0 += 4) {
619  w0 += a0[0] * c0[0] + a0[1] * c0[1] + a0[2] * c0[2] + a0[3] * c0[3];
620  w1 += a1[0] * c0[0] + a1[1] * c0[1] + a1[2] * c0[2] + a1[3] * c0[3];
621  w2 += a2[0] * c0[0] + a2[1] * c0[1] + a2[2] * c0[2] + a2[3] * c0[3];
622  w3 += a3[0] * c0[0] + a3[1] * c0[1] + a3[2] * c0[2] + a3[3] * c0[3];
623  }
624 
625  for ( ; i != this->size(); ++i, ++a0, ++a1, ++a2, ++a3, ++c0) {
626  w0 += (*a0) * (*c0);
627  w1 += (*a1) * (*c0);
628  w2 += (*a2) * (*c0);
629  w3 += (*a3) * (*c0);
630  }
631 
632  *p0 = w0;
633  *p1 = w1;
634  *p2 = w2;
635  *p3 = w3;
636  }
637  }
638 
639  for ( ; row != this->size(); ++row) { // remaining rows
640 
641  double* p0 = (*this)[row + 0];
642 
643  for (size_t col = 0; col != this->size(); ++col, ++p0) {
644 
645  double w0 = 0.0;
646 
647  const double* a0 = A[row + 0];
648  const double* c0 = C[col];
649 
650  for (i = 0; i + 4 <= this->size(); i += 4, a0 += 4, c0 += 4) {
651  w0 += a0[0] * c0[0] + a0[1] * c0[1] + a0[2] * c0[2] + a0[3] * c0[3];
652  }
653 
654  for ( ; i != this->size(); ++i, ++a0, ++c0) {
655  w0 += (*a0) * (*c0);
656  }
657 
658  *p0 = w0;
659  }
660  }
661  }
662 
663  } else {
664  THROW(JException, "JMatrixND::mul() inconsistent matrix dimensions " << A.size() << ' ' << B.size());
665  }
666 
667  return *this;
668  }
TPaveText * p1
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:421
JMatrixND_t & getInstance()
Get work space.
Definition: JMatrixND.hh:336
static const double C
Physics constants.
void set(const JMatrixND_t &A)
Set matrix.
Definition: JMatrixND.hh:130
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
p2
Definition: module-Z:fit.sh:74
JMatrixND_t & transpose()
Transpose.
Definition: JMatrixND.hh:158
bool empty() const
Check emptyness.
Definition: JMatrixND.hh:199
p3
Definition: module-Z:fit.sh:74
Basic NxN matrix.
Definition: JMatrixND.hh:36
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 678 of file JMatrixND.hh.

680  {
681  if (this->size() == A.size()) {
682 
683  for (size_t row = 0; row != this->size(); ++row) {
684 
685  const double* p = (*this)[row];
686  const double* q = A [row];
687 
688  for (size_t i = this->size(); i != 0; --i, ++p, ++q) {
689  if (fabs(*p - *q) > eps) {
690  return false;
691  }
692  }
693  }
694 
695  return true;
696 
697  } else {
698  THROW(JException, "JMatrixND::equals() inconsistent matrix dimensions " << this->size() << ' ' << A.size());
699  }
700  }
#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
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 709 of file JMatrixND.hh.

710  {
711  for (size_t i = 0; i != this->size(); ++i) {
712 
713  if (fabs(1.0 - (*this)(i,i)) > eps) {
714  return false;
715  };
716 
717  for (size_t j = 0; j != i; ++j) {
718  if (fabs((*this)(i,j)) > eps || fabs((*this)(j,i)) > eps) {
719  return false;
720  };
721  }
722  }
723 
724  return true;
725  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
int j
Definition: JPolint.hh:703
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 734 of file JMatrixND.hh.

735  {
736  for (size_t i = 0; i != this->size(); ++i) {
737  for (size_t j = 0; j != i; ++j) {
738  if (fabs((*this)(i,j) - (*this)(j,i)) > eps) {
739  return false;
740  };
741  }
742  }
743 
744  return true;
745  }
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
int j
Definition: JPolint.hh:703
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 756 of file JMatrixND.hh.

757  {
758  double dot = 0.0;
759 
760  for (size_t i = 0; i != v.size(); ++i) {
761 
762  const double* p = (*this)[i];
763 
764  double w = 0.0;
765 
766  for (JVectorND::const_iterator y = v.begin(); y != v.end(); ++y, ++p) {
767  w += (*p) * (*y);
768  }
769 
770  dot += v[i] * w;
771  }
772 
773  return dot;
774  }
data_type w[N+1][M+1]
Definition: JPolint.hh:778
void JMATH::JMatrixND::rswap ( size_t  r1,
size_t  r2 
)
inlineprotected

Definition at line 856 of file JMatrixND.hh.

857  {
859 
860  A.resize(this->size());
861 
862  memcpy(A.data(), (*this)[r1], this->size() * sizeof(double));
863  memcpy((*this)[r1], (*this)[r2], this->size() * sizeof(double));
864  memcpy((*this)[r2], A.data(), this->size() * sizeof(double));
865  }
JMatrixND_t & getInstance()
Get work space.
Definition: JMatrixND.hh:336
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:102
source $JPP_DIR setenv csh $JPP_DIR &dev null eval JShellParser o a A
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
Basic NxN matrix.
Definition: JMatrixND.hh:36
void JMATH::JMatrixND::cswap ( size_t  c1,
size_t  c2 
)
inlineprotected

Swap columns.

Parameters
c1column
c2column

Definition at line 874 of file JMatrixND.hh.

875  {
876  using std::swap;
877 
878  double* p1 = this->data() + c1;
879  double* p2 = this->data() + c2;
880 
881  for (size_t i = this->size(); i != 0; --i, p1 += this->size(), p2 += this->size()) {
882  swap(*p1, *p2);
883  }
884  }
TPaveText * p1
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
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:143
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
void JMATH::JMatrixND_t::clear ( )
inlineinherited

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

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

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

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
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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

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
inlineinherited

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

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
inlineinherited

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

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
inlineinherited

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

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

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355  {
356  return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357  }

Friends And Related Function Documentation

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

Read matrix from input.

Parameters
inreader
Amatrix
Returns
reader

Definition at line 784 of file JMatrixND.hh.

785  {
786  size_t size;
787 
788  in >> size;
789 
790  A.resize(size);
791 
792  size_t n = A.size() * A.size();
793 
794  for (double* p = A.data(); n != 0; --n, ++p) {
795  in >> *p;
796  }
797 
798  return in;
799  }
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:421
const int n
Definition: JPolint.hh:697
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
JWriter& operator<< ( JWriter out,
const JMatrixND A 
)
friend

Write matrix to output.

Parameters
outwriter
Amatrix
Returns
writer

Definition at line 809 of file JMatrixND.hh.

810  {
811  out << A.size();
812 
813  size_t n = A.size() * A.size();
814 
815  for (const double* p = A.data(); n != 0; --n, ++p) {
816  out << *p;
817  }
818 
819  return out;
820  }
const int n
Definition: JPolint.hh:697
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
const double * data() const
Get pointer to data.
Definition: JMatrixND.hh:210
std::ostream& operator<< ( std::ostream &  out,
const JMatrixND A 
)
friend

Print ASCII formatted output.

Parameters
outoutput stream
Amatrix
Returns
output stream

Definition at line 830 of file JMatrixND.hh.

831  {
832  using namespace std;
833 
834  const JFormat format(out, getFormat<JMatrixND>(JFormat_t(10, 3, std::ios::fixed | std::ios::showpos)));
835 
836  for (size_t row = 0; row != A.size(); ++row) {
837 
838  for (size_t col = 0; col != A.size(); ++col) {
839  out << format << A(row,col) << ' ';
840  }
841 
842  out << endl;
843  }
844 
845  return out;
846  }
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:632
size_t size() const
Get dimension of matrix.
Definition: JMatrixND.hh:177
source $JPP_DIR setenv csh $JPP_DIR &dev null eval JShellParser o a A
Data structure for format specifications.
Definition: JManip.hh:522

Member Data Documentation

JMatrixND_t JMATH::JMatrixND::ws
protected

Definition at line 329 of file JMatrixND.hh.

double* JMATH::JMatrixND_t::__p
protectedinherited

pointer to data

Definition at line 314 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__n
protectedinherited

dimension of matrix

Definition at line 315 of file JMatrixND.hh.

size_t JMATH::JMatrixND_t::__m
protectedinherited

capacity of matrix

Definition at line 316 of file JMatrixND.hh.


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