OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CroutMatrix Class Reference

#include <newmat.h>

Inheritance diagram for CroutMatrix:
GeneralMatrix BaseMatrix

Public Member Functions

 CroutMatrix (const BaseMatrix &)
 
MatrixType Type () const
 
void lubksb (Real *, int=0)
 
 ~CroutMatrix ()
 
GeneralMatrixMakeSolver ()
 
LogAndSign LogDeterminant () const
 
void Solver (MatrixColX &, const MatrixColX &)
 
void GetRow (MatrixRowCol &)
 
void GetCol (MatrixRowCol &)
 
void GetCol (MatrixColX &c)
 
void CleanUp ()
 
void MiniCleanUp ()
 
bool IsEqual (const GeneralMatrix &) const
 
bool IsSingular () const
 
- Public Member Functions inherited from GeneralMatrix
GeneralMatrixEvaluate (MatrixType mt=MatrixTypeUnSp)
 
int Nrows () const
 
int Ncols () const
 
int Storage () const
 
RealStore () const
 
virtual ~GeneralMatrix ()
 
void tDelete ()
 
bool reuse ()
 
void Protect ()
 
int Tag () const
 
bool IsZero () const
 
void Release ()
 
void Release (int t)
 
void ReleaseAndDelete ()
 
void operator<< (const Real *)
 
void operator<< (const int *)
 
void operator<< (const BaseMatrix &X)
 
void Inject (const GeneralMatrix &)
 
void operator+= (const BaseMatrix &)
 
void operator-= (const BaseMatrix &)
 
void operator*= (const BaseMatrix &)
 
void operator|= (const BaseMatrix &)
 
void operator &= (const BaseMatrix &)
 
void operator+= (Real)
 
void operator-= (Real r)
 
void operator*= (Real)
 
void operator/= (Real r)
 
virtual void RestoreRow (MatrixRowCol &)
 
virtual void NextRow (MatrixRowCol &)
 
virtual void RestoreCol (MatrixRowCol &)
 
virtual void RestoreCol (MatrixColX &)
 
virtual void NextCol (MatrixRowCol &)
 
virtual void NextCol (MatrixColX &)
 
Real SumSquare () const
 
Real SumAbsoluteValue () const
 
Real Sum () const
 
Real MaximumAbsoluteValue1 (int &i) const
 
Real MinimumAbsoluteValue1 (int &i) const
 
Real Maximum1 (int &i) const
 
Real Minimum1 (int &i) const
 
Real MaximumAbsoluteValue () const
 
Real MaximumAbsoluteValue2 (int &i, int &j) const
 
Real MinimumAbsoluteValue () const
 
Real MinimumAbsoluteValue2 (int &i, int &j) const
 
Real Maximum () const
 
Real Maximum2 (int &i, int &j) const
 
Real Minimum () const
 
Real Minimum2 (int &i, int &j) const
 
void CheckStore () const
 
virtual void SetParameters (const GeneralMatrix *)
 
 operator ReturnMatrix () const
 
ReturnMatrix ForReturn () const
 
virtual bool SameStorageType (const GeneralMatrix &A) const
 
virtual void ReSizeForAdd (const GeneralMatrix &A, const GeneralMatrix &B)
 
virtual void ReSizeForSP (const GeneralMatrix &A, const GeneralMatrix &B)
 
virtual void ReSize (const GeneralMatrix &A)
 
MatrixInput operator<< (Real)
 
MatrixInput operator<< (int f)
 
- Public Member Functions inherited from BaseMatrix
AddedMatrix operator+ (const BaseMatrix &) const
 
MultipliedMatrix operator* (const BaseMatrix &) const
 
SubtractedMatrix operator- (const BaseMatrix &) const
 
ConcatenatedMatrix operator| (const BaseMatrix &) const
 
StackedMatrix operator & (const BaseMatrix &) const
 
ShiftedMatrix operator+ (Real) const
 
ScaledMatrix operator* (Real) const
 
ScaledMatrix operator/ (Real) const
 
ShiftedMatrix operator- (Real) const
 
TransposedMatrix t () const
 
NegatedMatrix operator- () const
 
ReversedMatrix Reverse () const
 
InvertedMatrix i () const
 
RowedMatrix AsRow () const
 
ColedMatrix AsColumn () const
 
DiagedMatrix AsDiagonal () const
 
MatedMatrix AsMatrix (int, int) const
 
GetSubMatrix SubMatrix (int, int, int, int) const
 
GetSubMatrix SymSubMatrix (int, int) const
 
GetSubMatrix Row (int) const
 
GetSubMatrix Rows (int, int) const
 
GetSubMatrix Column (int) const
 
GetSubMatrix Columns (int, int) const
 
Real AsScalar () const
 
Real Determinant () const
 
Real NormFrobenius () const
 
virtual Real Trace () const
 
Real Norm1 () const
 
Real NormInfinity () const
 
virtual MatrixBandWidth BandWidth () const
 
void IEQND () const
 

Private Member Functions

void ludcmp ()
 
void operator= (const CroutMatrix &)
 

Private Attributes

int * indx
 
bool d
 
bool sing
 

Additional Inherited Members

- Protected Member Functions inherited from GeneralMatrix
 GeneralMatrix ()
 
 GeneralMatrix (ArrayLengthSpecifier)
 
void Add (GeneralMatrix *, Real)
 
void Add (Real)
 
void NegAdd (GeneralMatrix *, Real)
 
void NegAdd (Real)
 
void Multiply (GeneralMatrix *, Real)
 
void Multiply (Real)
 
void Negate (GeneralMatrix *)
 
void Negate ()
 
void ReverseElements ()
 
void ReverseElements (GeneralMatrix *)
 
void operator= (Real)
 
Real * GetStore ()
 
GeneralMatrixBorrowStore (GeneralMatrix *, MatrixType)
 
void GetMatrix (const GeneralMatrix *)
 
void Eq (const BaseMatrix &, MatrixType)
 
void Eq (const GeneralMatrix &)
 
void Eq (const BaseMatrix &, MatrixType, bool)
 
void Eq2 (const BaseMatrix &, MatrixType)
 
int search (const BaseMatrix *) const
 
virtual GeneralMatrixTranspose (TransposedMatrix *, MatrixType)
 
void CheckConversion (const BaseMatrix &)
 
void ReSize (int, int, int)
 
virtual short SimpleAddOK (const GeneralMatrix *)
 
void PlusEqual (const GeneralMatrix &gm)
 
void MinusEqual (const GeneralMatrix &gm)
 
void PlusEqual (Real f)
 
void MinusEqual (Real f)
 
- Protected Attributes inherited from GeneralMatrix
int tag
 
int nrows
 
int ncols
 
int storage
 
Realstore
 

Detailed Description

Definition at line 902 of file newmat.h.

Constructor & Destructor Documentation

◆ CroutMatrix()

CroutMatrix::CroutMatrix ( const BaseMatrix m)

Definition at line 170 of file newmat4.cpp.

References CleanUp(), d, GeneralMatrix::Evaluate(), GeneralMatrix::GetMatrix(), indx, ludcmp(), MatrixErrorNoSpace(), MONITOR_INT_NEW, GeneralMatrix::ncols, GeneralMatrix::nrows, REPORT, MatrixType::Rt, and sing.

171 {
172  REPORT
173  Tracer tr("CroutMatrix");
174  indx = 0; // in case of exception at next line
176  GetMatrix(gm);
177  if (nrows!=ncols) { CleanUp(); Throw(NotSquareException(*gm)); }
178  d=true; sing=false;
179  indx=new int [nrows]; MatrixErrorNoSpace(indx);
180  MONITOR_INT_NEW("Index (CroutMat)",nrows,indx)
181  ludcmp();
182 }
void ludcmp()
Definition: newmat8.cpp:27
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
Definition: newmat5.cpp:79
bool sing
Definition: newmat.h:906
#define MONITOR_INT_NEW(Operation, Size, Pointer)
Definition: myexcept.h:318
void MatrixErrorNoSpace(const void *)
Definition: newmatex.cpp:292
#define REPORT
Definition: newmat4.cpp:19
bool d
Definition: newmat.h:905
void CleanUp()
Definition: newmat4.cpp:898
int * indx
Definition: newmat.h:904
void GetMatrix(const GeneralMatrix *)
Definition: newmat4.cpp:610

◆ ~CroutMatrix()

CroutMatrix::~CroutMatrix ( )

Definition at line 184 of file newmat4.cpp.

References indx, MONITOR_INT_DELETE, and GeneralMatrix::nrows.

185 {
186  MONITOR_INT_DELETE("Index (CroutMat)",nrows,indx)
187  delete [] indx;
188 }
#define MONITOR_INT_DELETE(Operation, Size, Pointer)
Definition: myexcept.h:320
int * indx
Definition: newmat.h:904

Member Function Documentation

◆ CleanUp()

void CroutMatrix::CleanUp ( )
virtual

Reimplemented from GeneralMatrix.

Definition at line 898 of file newmat4.cpp.

References GeneralMatrix::CleanUp(), indx, GeneralMatrix::nrows, and REPORT.

Referenced by CroutMatrix().

899 {
900  REPORT
901  if (nrows) delete [] indx;
903 }
void CleanUp()
Definition: newmat4.cpp:874
#define REPORT
Definition: newmat4.cpp:19
int * indx
Definition: newmat.h:904

◆ GetCol() [1/2]

void CroutMatrix::GetCol ( MatrixRowCol )
virtual

Implements GeneralMatrix.

Definition at line 303 of file newmatex.cpp.

304  { Throw(NotDefinedException("GetCol","Crout")); }

◆ GetCol() [2/2]

void CroutMatrix::GetCol ( MatrixColX c)
inlinevirtual

Implements GeneralMatrix.

Definition at line 919 of file newmat.h.

References GetCol().

Referenced by GetCol().

919 { GetCol((MatrixRowCol&)c); }
void GetCol(MatrixRowCol &)
Definition: newmatex.cpp:303

◆ GetRow()

void CroutMatrix::GetRow ( MatrixRowCol )
virtual

Implements GeneralMatrix.

Definition at line 301 of file newmatex.cpp.

302  { Throw(NotDefinedException("GetRow","Crout")); }

◆ IsEqual()

bool CroutMatrix::IsEqual ( const GeneralMatrix A) const
virtual

Reimplemented from GeneralMatrix.

Definition at line 918 of file newmat7.cpp.

References A, and REPORT.

919 {
920  Tracer tr("CroutMatrix IsEqual");
921  if (A.Type() != Type()) // not same types
922  { REPORT return false; }
923  if (&A == this) // same matrix
924  { REPORT return true; }
925  if (A.nrows != nrows || A.ncols != ncols)
926  // different dimensions
927  { REPORT return false; }
928  // is matrix storage the same - compare store
929  REPORT
930  return RealEqual(A.store,store,storage)
931  && intEqual(((CroutMatrix&)A).indx, indx, nrows);
932 }
MatrixType Type() const
Definition: newmat4.cpp:421
#define A(r, c)
#define REPORT
Definition: newmat7.cpp:18
Real * store
Definition: newmat.h:393
int storage
Definition: newmat.h:392
int * indx
Definition: newmat.h:904

◆ IsSingular()

bool CroutMatrix::IsSingular ( ) const
inline

Definition at line 923 of file newmat.h.

923 { return sing; }
bool sing
Definition: newmat.h:906

◆ LogDeterminant()

LogAndSign CroutMatrix::LogDeterminant ( ) const
virtual

Reimplemented from GeneralMatrix.

Definition at line 696 of file newmat8.cpp.

References LogAndSign::ChangeSign(), and REPORT.

697 {
698  REPORT
699  if (sing) return 0.0;
700  int i = nrows; int dd = i+1; LogAndSign sum; Real* s = store;
701  if (i) for(;;)
702  {
703  sum *= *s;
704  if (!(--i)) break;
705  s += dd;
706  }
707  if (!d) sum.ChangeSign(); return sum;
708 
709 }
double Real
Definition: include.h:57
InvertedMatrix i() const
Definition: newmat6.cpp:325
#define REPORT
Definition: newmat8.cpp:21
bool sing
Definition: newmat.h:906
Real * store
Definition: newmat.h:393
bool d
Definition: newmat.h:905
void ChangeSign()
Definition: newmat.h:50

◆ lubksb()

void CroutMatrix::lubksb ( Real *  B,
int  mini = 0 
)

Definition at line 98 of file newmat8.cpp.

99 {
100  REPORT
101  // this has been adapted from Numerical Recipes in C. The code has been
102  // substantially streamlined, so I do not think much of the original
103  // copyright remains. However there is not much opportunity for
104  // variation in the code, so it is still similar to the NR code.
105  // I follow the NR code in skipping over initial zeros in the B vector.
106  Tracer trace("Crout(lubksb)");
107  sing = false;
108  // if ((this->LogDeterminant()).Value() != 0) sing = false;
109  if (sing) Throw(SingularException(*this));
110  int i, j, ii = nrows; // ii initialised : B might be all zeros
111 
112 
113  // scan for first non-zero in B
114  for (i = 0; i < nrows; i++)
115  {
116  int ip = indx[i]; Real temp = B[ip]; B[ip] = B[i]; B[i] = temp;
117  if (temp != 0.0) { ii = i; break; }
118  }
119 
120  Real* bi; Real* ai;
121  i = ii + 1;
122 
123  if (i < nrows)
124  {
125  bi = B + ii; ai = store + ii + i * nrows;
126  for (;;)
127  {
128  int ip = indx[i]; Real sum = B[ip]; B[ip] = B[i];
129  Real* aij = ai; Real* bj = bi; j = i - ii;
130  while (j--) sum -= *aij++ * *bj++;
131  B[i] = sum;
132  if (++i == nrows) break;
133  ai += nrows;
134  }
135  }
136 
137  ai = store + nrows * nrows;
138 
139  for (i = nrows - 1; i >= mini; i--)
140  {
141  Real* bj = B+i; ai -= nrows; Real* ajx = ai+i;
142  Real sum = *bj; Real diag = *ajx;
143  j = nrows - i; while(--j) sum -= *(++ajx) * *(++bj);
144  B[i] = sum / diag;
145  }
146 }
double Real
Definition: include.h:57
InvertedMatrix i() const
Definition: newmat6.cpp:325
#define REPORT
Definition: newmat8.cpp:21
bool sing
Definition: newmat.h:906
Real * store
Definition: newmat.h:393
int * indx
Definition: newmat.h:904

◆ ludcmp()

void CroutMatrix::ludcmp ( )
private

Definition at line 27 of file newmat8.cpp.

References REPORT.

Referenced by CroutMatrix().

33 {
34  REPORT
35  Tracer trace( "Crout(ludcmp)" ); sing = false;
36  Real* akk = store; // runs down diagonal
37 
38  Real big = fabs(*akk); int mu = 0; Real* ai = akk; int k;
39 
40  for (k = 1; k < nrows; k++)
41  {
42  ai += nrows; const Real trybig = fabs(*ai);
43  if (big < trybig) { big = trybig; mu = k; }
44  }
45 
46 
47  if (nrows) for (k = 0;;)
48  {
49  /*
50  int mu1;
51  {
52  Real big = fabs(*akk); mu1 = k; Real* ai = akk; int i;
53 
54  for (i = k+1; i < nrows; i++)
55  {
56  ai += nrows; const Real trybig = fabs(*ai);
57  if (big < trybig) { big = trybig; mu1 = i; }
58  }
59  }
60  if (mu1 != mu) cout << k << " " << mu << " " << mu1 << endl;
61  */
62 
63  indx[k] = mu;
64 
65  if (mu != k) //row swap
66  {
67  Real* a1 = store + nrows * k; Real* a2 = store + nrows * mu; d = !d;
68  int j = nrows;
69  while (j--) { const Real temp = *a1; *a1++ = *a2; *a2++ = temp; }
70  }
71 
72  Real diag = *akk; big = 0; mu = k + 1;
73  if (diag != 0)
74  {
75  ai = akk; int i = nrows - k - 1;
76  while (i--)
77  {
78  ai += nrows; Real* al = ai; Real mult = *al / diag; *al = mult;
79  int l = nrows - k - 1; Real* aj = akk;
80  // work out the next pivot as part of this loop
81  // this saves a column operation
82  if (l-- != 0)
83  {
84  *(++al) -= (mult * *(++aj));
85  const Real trybig = fabs(*al);
86  if (big < trybig) { big = trybig; mu = nrows - i - 1; }
87  while (l--) *(++al) -= (mult * *(++aj));
88  }
89  }
90  }
91  else sing = true;
92  if (++k == nrows) break; // so next line won't overflow
93  akk += nrows + 1;
94  }
95 }
double Real
Definition: include.h:57
InvertedMatrix i() const
Definition: newmat6.cpp:325
#define REPORT
Definition: newmat8.cpp:21
bool sing
Definition: newmat.h:906
Real * store
Definition: newmat.h:393
bool d
Definition: newmat.h:905
int * indx
Definition: newmat.h:904

◆ MakeSolver()

GeneralMatrix* CroutMatrix::MakeSolver ( )
inlinevirtual

Reimplemented from GeneralMatrix.

Definition at line 914 of file newmat.h.

914 { return this; } // for solving

◆ MiniCleanUp()

void CroutMatrix::MiniCleanUp ( )
virtual

Reimplemented from GeneralMatrix.

Definition at line 905 of file newmat4.cpp.

References indx, GeneralMatrix::MiniCleanUp(), GeneralMatrix::nrows, and REPORT.

906 {
907  REPORT
908  if (nrows) delete [] indx;
910 }
virtual void MiniCleanUp()
Definition: newmat.h:421
#define REPORT
Definition: newmat4.cpp:19
int * indx
Definition: newmat.h:904

◆ operator=()

void CroutMatrix::operator= ( const CroutMatrix )
inlineprivate

Definition at line 908 of file newmat.h.

908 {} // not allowed

◆ Solver()

void CroutMatrix::Solver ( MatrixColX mcout,
const MatrixColX mcin 
)
virtual

Reimplemented from GeneralMatrix.

Definition at line 38 of file newmat7.cpp.

References MatrixRowCol::data, REPORT, MatrixRowCol::skip, and MatrixRowCol::storage.

39 {
40  REPORT
41  int i = mcin.skip; Real* el = mcin.data-i; Real* el1 = el;
42  while (i--) *el++ = 0.0;
43  el += mcin.storage; i = nrows - mcin.skip - mcin.storage;
44  while (i--) *el++ = 0.0;
45  lubksb(el1, mcout.skip);
46 }
double Real
Definition: include.h:57
InvertedMatrix i() const
Definition: newmat6.cpp:325
#define REPORT
Definition: newmat7.cpp:18
Real * data
Definition: newmatrc.h:43
int storage
Definition: newmatrc.h:40
void lubksb(Real *, int=0)
Definition: newmat8.cpp:98

◆ Type()

MatrixType CroutMatrix::Type ( ) const
virtual

Implements GeneralMatrix.

Definition at line 421 of file newmat4.cpp.

References MatrixType::Ct.

421 { return MatrixType::Ct; }

Member Data Documentation

◆ d

bool CroutMatrix::d
private

Definition at line 905 of file newmat.h.

Referenced by CroutMatrix().

◆ indx

int* CroutMatrix::indx
private

Definition at line 904 of file newmat.h.

Referenced by CleanUp(), CroutMatrix(), MiniCleanUp(), and ~CroutMatrix().

◆ sing

bool CroutMatrix::sing
private

Definition at line 906 of file newmat.h.

Referenced by CroutMatrix().


The documentation for this class was generated from the following files: