OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Classes | Macros | Functions
newmatap.h File Reference
#include <ossim/matrix/newmat.h>

Go to the source code of this file.

Classes

class  SymmetricEigenAnalysis
 
class  FFT_Controller
 
class  MultiRadixCounter
 

Macros

#define NEWMATAP_LIB   0
 

Functions

void QRZT (Matrix &, LowerTriangularMatrix &)
 
void QRZT (const Matrix &, Matrix &, Matrix &)
 
void QRZ (Matrix &, UpperTriangularMatrix &)
 
void QRZ (const Matrix &, Matrix &, Matrix &)
 
void HHDecompose (Matrix &X, LowerTriangularMatrix &L)
 
void HHDecompose (const Matrix &X, Matrix &Y, Matrix &M)
 
void UpdateQRZT (Matrix &X, LowerTriangularMatrix &L)
 
void UpdateQRZ (Matrix &X, UpperTriangularMatrix &U)
 
ReturnMatrix Cholesky (const SymmetricMatrix &)
 
ReturnMatrix Cholesky (const SymmetricBandMatrix &)
 
void UpdateCholesky (UpperTriangularMatrix &chol, RowVector r1Modification)
 
void DowndateCholesky (UpperTriangularMatrix &chol, RowVector x)
 
void RightCircularUpdateCholesky (UpperTriangularMatrix &chol, int k, int l)
 
void LeftCircularUpdateCholesky (UpperTriangularMatrix &chol, int k, int l)
 
void SVD (const Matrix &, DiagonalMatrix &, Matrix &, Matrix &, bool=true, bool=true)
 
void SVD (const Matrix &, DiagonalMatrix &)
 
void SVD (const Matrix &A, DiagonalMatrix &D, Matrix &U, bool withU=true)
 
void SortSV (DiagonalMatrix &D, Matrix &U, bool ascending=false)
 
void SortSV (DiagonalMatrix &D, Matrix &U, Matrix &V, bool ascending=false)
 
void Jacobi (const SymmetricMatrix &, DiagonalMatrix &)
 
void Jacobi (const SymmetricMatrix &, DiagonalMatrix &, SymmetricMatrix &)
 
void Jacobi (const SymmetricMatrix &, DiagonalMatrix &, Matrix &)
 
void Jacobi (const SymmetricMatrix &, DiagonalMatrix &, SymmetricMatrix &, Matrix &, bool=true)
 
void EigenValues (const SymmetricMatrix &, DiagonalMatrix &)
 
void EigenValues (const SymmetricMatrix &, DiagonalMatrix &, SymmetricMatrix &)
 
void EigenValues (const SymmetricMatrix &, DiagonalMatrix &, Matrix &)
 
void SortAscending (GeneralMatrix &)
 
void SortDescending (GeneralMatrix &)
 
void FFT (const ColumnVector &, const ColumnVector &, ColumnVector &, ColumnVector &)
 
void FFTI (const ColumnVector &, const ColumnVector &, ColumnVector &, ColumnVector &)
 
void RealFFT (const ColumnVector &, ColumnVector &, ColumnVector &)
 
void RealFFTI (const ColumnVector &, const ColumnVector &, ColumnVector &)
 
void DCT_II (const ColumnVector &, ColumnVector &)
 
void DCT_II_inverse (const ColumnVector &, ColumnVector &)
 
void DST_II (const ColumnVector &, ColumnVector &)
 
void DST_II_inverse (const ColumnVector &, ColumnVector &)
 
void DCT (const ColumnVector &, ColumnVector &)
 
void DCT_inverse (const ColumnVector &, ColumnVector &)
 
void DST (const ColumnVector &, ColumnVector &)
 
void DST_inverse (const ColumnVector &, ColumnVector &)
 
void FFT2 (const Matrix &U, const Matrix &V, Matrix &X, Matrix &Y)
 
void FFT2I (const Matrix &U, const Matrix &V, Matrix &X, Matrix &Y)
 

Macro Definition Documentation

◆ NEWMATAP_LIB

#define NEWMATAP_LIB   0

Definition at line 6 of file newmatap.h.

Function Documentation

◆ Cholesky() [1/2]

ReturnMatrix Cholesky ( const SymmetricMatrix )

Definition at line 30 of file cholesky.cpp.

References GeneralMatrix::ForReturn(), GeneralMatrix::Nrows(), GeneralMatrix::Release(), REPORT, ossim::square(), and GeneralMatrix::Store().

Referenced by MLE_D_FI::NextPoint().

31 {
32  REPORT
33  Tracer trace("Cholesky");
34  int nr = S.Nrows();
36  Real* s = S.Store(); Real* t = T.Store(); Real* ti = t;
37  for (int i=0; i<nr; i++)
38  {
39  Real* tj = t; Real sum; int k;
40  for (int j=0; j<i; j++)
41  {
42  Real* tk = ti; sum = 0.0; k = j;
43  while (k--) { sum += *tj++ * *tk++; }
44  *tk = (*s++ - sum) / *tj++;
45  }
46  sum = 0.0; k = i;
47  while (k--) { sum += square(*ti++); }
48  Real d = *s++ - sum;
49  if (d<=0.0) Throw(NPDException(S));
50  *ti++ = std::sqrt(d);
51  }
52  T.Release(); return T.ForReturn();
53 }
double Real
Definition: include.h:57
T square(T x)
Definition: ossimCommon.h:334
#define REPORT
Definition: cholesky.cpp:21

◆ Cholesky() [2/2]

ReturnMatrix Cholesky ( const SymmetricBandMatrix )

Definition at line 55 of file cholesky.cpp.

References GeneralMatrix::ForReturn(), SymmetricBandMatrix::lower, GeneralMatrix::Nrows(), GeneralMatrix::Release(), REPORT, ossim::square(), and GeneralMatrix::Store().

56 {
57  REPORT
58  Tracer trace("Band-Cholesky");
59  int nr = S.Nrows(); int m = S.lower;
60  LowerBandMatrix T(nr,m);
61  Real* s = S.Store(); Real* t = T.Store(); Real* ti = t;
62 
63  for (int i=0; i<nr; i++)
64  {
65  Real* tj = t; Real sum; int l;
66  if (i<m) { REPORT l = m-i; s += l; ti += l; l = i; }
67  else { REPORT t += (m+1); l = m; }
68 
69  for (int j=0; j<l; j++)
70  {
71  Real* tk = ti; sum = 0.0; int k = j; tj += (m-j);
72  while (k--) { sum += *tj++ * *tk++; }
73  *tk = (*s++ - sum) / *tj++;
74  }
75  sum = 0.0;
76  while (l--) { sum += square(*ti++); }
77  Real d = *s++ - sum;
78  if (d<=0.0) Throw(NPDException(S));
79  *ti++ = std::sqrt(d);
80  }
81 
82  T.Release(); return T.ForReturn();
83 }
double Real
Definition: include.h:57
T square(T x)
Definition: ossimCommon.h:334
#define REPORT
Definition: cholesky.cpp:21

◆ DCT()

void DCT ( const ColumnVector ,
ColumnVector  
)

Definition at line 393 of file fft.cpp.

References DCT_inverse(), GeneralMatrix::Nrows(), and REPORT.

394 {
395  // Discrete cosine transform, type I
396  Tracer trace("DCT");
397  REPORT
398  DCT_inverse(U, V);
399  V *= (V.Nrows()-1)/2;
400 }
#define REPORT
Definition: fft.cpp:23
void DCT_inverse(const ColumnVector &V, ColumnVector &U)
Definition: fft.cpp:359

◆ DCT_II()

void DCT_II ( const ColumnVector ,
ColumnVector  
)

Definition at line 249 of file fft.cpp.

References A, n, GeneralMatrix::Nrows(), RealFFT(), REPORT, ColumnVector::ReSize(), GeneralMatrix::Store(), x, and y.

250 {
251  // Discrete cosine transform, type II, of a real series
252  Tracer trace("DCT_II");
253  REPORT
254  const int n = U.Nrows(); // length of arrays
255  const int n2 = n / 2; const int n4 = n * 4;
256  if (n != 2 * n2)
257  Throw(ProgramException("Vector length not multiple of 2", U));
258  ColumnVector A(n);
259  Real* a = A.Store(); Real* b = a + n; Real* u = U.Store();
260  int i = n2;
261  while (i--) { *a++ = *u++; *(--b) = *u++; }
262  ColumnVector X, Y;
263  RealFFT(A, X, Y); A.CleanUp();
264  V.ReSize(n);
265  Real* x = X.Store(); Real* y = Y.Store();
266  Real* v = V.Store(); Real* w = v + n;
267  *v = *x;
268  int k = 0; i = n2;
269  while (i--)
270  {
271  Real c, s; cossin(++k, n4, c, s);
272  Real xi = *(++x); Real yi = *(++y);
273  *(++v) = xi * c + yi * s; *(--w) = xi * s - yi * c;
274  }
275 }
ossim_uint32 x
double Real
Definition: include.h:57
void RealFFT(const ColumnVector &U, ColumnVector &X, ColumnVector &Y)
Definition: fft.cpp:126
ossim_uint32 y
#define A(r, c)
os2<< "> n<< " > nendobj n
#define REPORT
Definition: fft.cpp:23
Real * Store() const
Definition: newmat.h:433

◆ DCT_II_inverse()

void DCT_II_inverse ( const ColumnVector ,
ColumnVector  
)

Definition at line 277 of file fft.cpp.

References n, GeneralMatrix::Nrows(), REPORT, GeneralMatrix::Store(), x, and y.

278 {
279  // Inverse of discrete cosine transform, type II
280  Tracer trace("DCT_II_inverse");
281  REPORT
282  const int n = V.Nrows(); // length of array
283  const int n2 = n / 2; const int n4 = n * 4; const int n21 = n2 + 1;
284  if (n != 2 * n2)
285  Throw(ProgramException("Vector length not multiple of 2", V));
286  ColumnVector X(n21), Y(n21);
287  Real* x = X.Store(); Real* y = Y.Store();
288  Real* v = V.Store(); Real* w = v + n;
289  *x = *v; *y = 0.0;
290  int i = n2; int k = 0;
291  while (i--)
292  {
293  Real c, s; cossin(++k, n4, c, s);
294  Real vi = *(++v); Real wi = *(--w);
295  *(++x) = vi * c + wi * s; *(++y) = vi * s - wi * c;
296  }
297  ColumnVector A; RealFFTI(X, Y, A);
298  X.CleanUp(); Y.CleanUp(); U.ReSize(n);
299  Real* a = A.Store(); Real* b = a + n; Real* u = U.Store();
300  i = n2;
301  while (i--) { *u++ = *a++; *u++ = *(--b); }
302 }
ossim_uint32 x
double Real
Definition: include.h:57
ossim_uint32 y
#define A(r, c)
os2<< "> n<< " > nendobj n
void RealFFTI(const ColumnVector &A, const ColumnVector &B, ColumnVector &U)
Definition: fft.cpp:162
#define REPORT
Definition: fft.cpp:23

◆ DCT_inverse()

void DCT_inverse ( const ColumnVector ,
ColumnVector  
)

Definition at line 359 of file fft.cpp.

References A, ColumnVector::CleanUp(), n, GeneralMatrix::Nrows(), RealFFTI(), REPORT, ColumnVector::ReSize(), GeneralMatrix::Store(), x, and y.

Referenced by DCT().

360 {
361  // Inverse of discrete cosine transform, type I
362  Tracer trace("DCT_inverse");
363  REPORT
364  const int n = V.Nrows()-1; // length of transform
365  const int n2 = n / 2; const int n21 = n2 + 1;
366  if (n != 2 * n2)
367  Throw(ProgramException("Vector length not multiple of 2", V));
368  ColumnVector X(n21), Y(n21);
369  Real* x = X.Store(); Real* y = Y.Store(); Real* v = V.Store();
370  Real vi = *v++; *x++ = vi; *y++ = 0.0;
371  Real sum1 = vi / 2.0; Real sum2 = sum1; vi = *v++;
372  int i = n2-1;
373  while (i--)
374  {
375  Real vi2 = *v++; sum1 += vi2 + vi; sum2 += vi2 - vi;
376  *x++ = vi2; vi2 = *v++; *y++ = vi - vi2; vi = vi2;
377  }
378  sum1 += vi; sum2 -= vi;
379  vi = *v; *x = vi; *y = 0.0; vi /= 2.0; sum1 += vi; sum2 += vi;
380  ColumnVector A; RealFFTI(X, Y, A);
381  X.CleanUp(); Y.CleanUp(); U.ReSize(n+1);
382  Real* a = A.Store(); Real* b = a + n; Real* u = U.Store(); v = u + n;
383  i = n2; int k = 0; *u++ = sum1 / n2; *v-- = sum2 / n2;
384  while (i--)
385  {
386  Real s = sin(1.5707963267948966192 * (++k) / n2);
387  Real ai = *(++a); Real bi = *(--b);
388  Real bz = (ai - bi) / 4 / s; Real az = (ai + bi) / 2;
389  *u++ = az - bz; *v-- = az + bz;
390  }
391 }
ossim_uint32 x
double Real
Definition: include.h:57
ossim_uint32 y
#define A(r, c)
os2<< "> n<< " > nendobj n
void RealFFTI(const ColumnVector &A, const ColumnVector &B, ColumnVector &U)
Definition: fft.cpp:162
#define REPORT
Definition: fft.cpp:23

◆ DowndateCholesky()

void DowndateCholesky ( UpperTriangularMatrix chol,
RowVector  x 
)

Definition at line 123 of file cholesky.cpp.

References GivensRotation(), GeneralMatrix::Nrows(), pythag(), GeneralMatrix::SumSquare(), BaseMatrix::t(), and x.

124 {
125  int nRC = chol.Nrows();
126 
127  // solve R^T a = x
128  LowerTriangularMatrix L = chol.t();
129  ColumnVector a(nRC); a = 0.0;
130  int i, j;
131 
132  for (i = 1; i <= nRC; ++i)
133  {
134  // accumulate subtr sum
135  Real subtrsum = 0.0;
136  for(int k = 1; k < i; ++k) subtrsum += a(k) * L(i,k);
137 
138  a(i) = (x(i) - subtrsum) / L(i,i);
139  }
140 
141  // test that l2 norm of a is < 1
142  Real squareNormA = a.SumSquare();
143  if (squareNormA >= 1.0)
144  Throw(ProgramException("DowndateCholesky() fails", chol));
145 
146  Real alpha = std::sqrt(1.0 - squareNormA);
147 
148  // compute and apply Givens rotations to the vector a
149  ColumnVector cGivens(nRC); cGivens = 0.0;
150  ColumnVector sGivens(nRC); sGivens = 0.0;
151  for(i = nRC; i >= 1; i--)
152  alpha = pythag(alpha, a(i), cGivens(i), sGivens(i));
153 
154  // apply Givens rotations to the jth column of chol
155  ColumnVector xtilde(nRC); xtilde = 0.0;
156  for(j = nRC; j >= 1; j--)
157  {
158  // only the first j rotations have an affect on chol,0
159  for(int k = j; k >= 1; k--)
160  GivensRotation(cGivens(k), -sGivens(k), chol(k,j), xtilde(j));
161  }
162 }
ossim_uint32 x
void GivensRotation(Real cGivens, Real sGivens, Real &x, Real &y)
Definition: newmatrm.h:116
double Real
Definition: include.h:57
Real pythag(Real f, Real g, Real &c, Real &s)
Definition: newmatrm.cpp:186
int Nrows() const
Definition: newmat.h:430
TransposedMatrix t() const
Definition: newmat6.cpp:316

◆ DST()

void DST ( const ColumnVector ,
ColumnVector  
)

Definition at line 430 of file fft.cpp.

References DST_inverse(), GeneralMatrix::Nrows(), and REPORT.

431 {
432  // Discrete sine transform, type I
433  Tracer trace("DST");
434  REPORT
435  DST_inverse(U, V);
436  V *= (V.Nrows()-1)/2;
437 }
void DST_inverse(const ColumnVector &V, ColumnVector &U)
Definition: fft.cpp:402
#define REPORT
Definition: fft.cpp:23

◆ DST_II()

void DST_II ( const ColumnVector ,
ColumnVector  
)

Definition at line 304 of file fft.cpp.

References A, n, GeneralMatrix::Nrows(), RealFFT(), REPORT, ColumnVector::ReSize(), GeneralMatrix::Store(), x, and y.

305 {
306  // Discrete sine transform, type II, of a real series
307  Tracer trace("DST_II");
308  REPORT
309  const int n = U.Nrows(); // length of arrays
310  const int n2 = n / 2; const int n4 = n * 4;
311  if (n != 2 * n2)
312  Throw(ProgramException("Vector length not multiple of 2", U));
313  ColumnVector A(n);
314  Real* a = A.Store(); Real* b = a + n; Real* u = U.Store();
315  int i = n2;
316  while (i--) { *a++ = *u++; *(--b) = -(*u++); }
317  ColumnVector X, Y;
318  RealFFT(A, X, Y); A.CleanUp();
319  V.ReSize(n);
320  Real* x = X.Store(); Real* y = Y.Store();
321  Real* v = V.Store(); Real* w = v + n;
322  *(--w) = *x;
323  int k = 0; i = n2;
324  while (i--)
325  {
326  Real c, s; cossin(++k, n4, c, s);
327  Real xi = *(++x); Real yi = *(++y);
328  *v++ = xi * s - yi * c; *(--w) = xi * c + yi * s;
329  }
330 }
ossim_uint32 x
double Real
Definition: include.h:57
void RealFFT(const ColumnVector &U, ColumnVector &X, ColumnVector &Y)
Definition: fft.cpp:126
ossim_uint32 y
#define A(r, c)
os2<< "> n<< " > nendobj n
#define REPORT
Definition: fft.cpp:23
Real * Store() const
Definition: newmat.h:433

◆ DST_II_inverse()

void DST_II_inverse ( const ColumnVector ,
ColumnVector  
)

Definition at line 332 of file fft.cpp.

References n, GeneralMatrix::Nrows(), REPORT, GeneralMatrix::Store(), x, and y.

333 {
334  // Inverse of discrete sine transform, type II
335  Tracer trace("DST_II_inverse");
336  REPORT
337  const int n = V.Nrows(); // length of array
338  const int n2 = n / 2; const int n4 = n * 4; const int n21 = n2 + 1;
339  if (n != 2 * n2)
340  Throw(ProgramException("Vector length not multiple of 2", V));
341  ColumnVector X(n21), Y(n21);
342  Real* x = X.Store(); Real* y = Y.Store();
343  Real* v = V.Store(); Real* w = v + n;
344  *x = *(--w); *y = 0.0;
345  int i = n2; int k = 0;
346  while (i--)
347  {
348  Real c, s; cossin(++k, n4, c, s);
349  Real vi = *v++; Real wi = *(--w);
350  *(++x) = vi * s + wi * c; *(++y) = - vi * c + wi * s;
351  }
352  ColumnVector A; RealFFTI(X, Y, A);
353  X.CleanUp(); Y.CleanUp(); U.ReSize(n);
354  Real* a = A.Store(); Real* b = a + n; Real* u = U.Store();
355  i = n2;
356  while (i--) { *u++ = *a++; *u++ = -(*(--b)); }
357 }
ossim_uint32 x
double Real
Definition: include.h:57
ossim_uint32 y
#define A(r, c)
os2<< "> n<< " > nendobj n
void RealFFTI(const ColumnVector &A, const ColumnVector &B, ColumnVector &U)
Definition: fft.cpp:162
#define REPORT
Definition: fft.cpp:23

◆ DST_inverse()

void DST_inverse ( const ColumnVector ,
ColumnVector  
)

Definition at line 402 of file fft.cpp.

References A, ColumnVector::CleanUp(), n, GeneralMatrix::Nrows(), RealFFTI(), REPORT, ColumnVector::ReSize(), GeneralMatrix::Store(), x, and y.

Referenced by DST().

403 {
404  // Inverse of discrete sine transform, type I
405  Tracer trace("DST_inverse");
406  REPORT
407  const int n = V.Nrows()-1; // length of transform
408  const int n2 = n / 2; const int n21 = n2 + 1;
409  if (n != 2 * n2)
410  Throw(ProgramException("Vector length not multiple of 2", V));
411  ColumnVector X(n21), Y(n21);
412  Real* x = X.Store(); Real* y = Y.Store(); Real* v = V.Store();
413  Real vi = *(++v); *x++ = 2 * vi; *y++ = 0.0;
414  int i = n2-1;
415  while (i--) { *y++ = *(++v); Real vi2 = *(++v); *x++ = vi2 - vi; vi = vi2; }
416  *x = -2 * vi; *y = 0.0;
417  ColumnVector A; RealFFTI(X, Y, A);
418  X.CleanUp(); Y.CleanUp(); U.ReSize(n+1);
419  Real* a = A.Store(); Real* b = a + n; Real* u = U.Store(); v = u + n;
420  i = n2; int k = 0; *u++ = 0.0; *v-- = 0.0;
421  while (i--)
422  {
423  Real s = sin(1.5707963267948966192 * (++k) / n2);
424  Real ai = *(++a); Real bi = *(--b);
425  Real az = (ai + bi) / 4 / s; Real bz = (ai - bi) / 2;
426  *u++ = az - bz; *v-- = az + bz;
427  }
428 }
ossim_uint32 x
double Real
Definition: include.h:57
ossim_uint32 y
#define A(r, c)
os2<< "> n<< " > nendobj n
void RealFFTI(const ColumnVector &A, const ColumnVector &B, ColumnVector &U)
Definition: fft.cpp:162
#define REPORT
Definition: fft.cpp:23

◆ EigenValues() [1/3]

void EigenValues ( const SymmetricMatrix ,
DiagonalMatrix  
)

Definition at line 286 of file evalue.cpp.

Referenced by ossimMatrix3x3::getEigenValues(), and ossimMatrix4x4::getEigenValues().

287 { REPORT DiagonalMatrix E; SymmetricMatrix A; tred3(X,D,E,A); tql1(D,E); }
#define A(r, c)
#define REPORT
Definition: evalue.cpp:19

◆ EigenValues() [2/3]

void EigenValues ( const SymmetricMatrix ,
DiagonalMatrix ,
SymmetricMatrix  
)

Definition at line 289 of file evalue.cpp.

291 { REPORT DiagonalMatrix E; tred3(X,D,E,A); tql1(D,E); }
#define A(r, c)
#define REPORT
Definition: evalue.cpp:19

◆ EigenValues() [3/3]

void EigenValues ( const SymmetricMatrix ,
DiagonalMatrix ,
Matrix  
)

Definition at line 283 of file evalue.cpp.

284 { REPORT DiagonalMatrix E; tred2(A, D, E, Z); tql2(D, E, Z); SortSV(D,Z,true); }
#define A(r, c)
#define REPORT
Definition: evalue.cpp:19
void SortSV(DiagonalMatrix &D, Matrix &U, bool ascending=false)
Definition: sort.cpp:190

◆ FFT()

void FFT ( const ColumnVector ,
const ColumnVector ,
ColumnVector ,
ColumnVector  
)

Definition at line 197 of file fft.cpp.

References FFT_Controller::ar_1d_ft(), FFT_Controller::CanFactor(), n, GeneralMatrix::Nrows(), FFT_Controller::OnlyOldFFT, REPORT, and GeneralMatrix::Store().

Referenced by FFT2(), and FFTI().

199 {
200  // from Carl de Boor (1980), Siam J Sci Stat Comput, 1 173-8
201  // but first try Sande and Gentleman
202  Tracer trace("FFT");
203  REPORT
204  const int n = U.Nrows(); // length of arrays
205  if (n != V.Nrows() || n == 0)
206  Throw(ProgramException("Vector lengths unequal or zero", U, V));
207  if (n == 1) { REPORT X = U; Y = V; return; }
208 
209  // see if we can use the newfft routine
211  {
212  REPORT
213  X = U; Y = V;
214  if ( FFT_Controller::ar_1d_ft(n,X.Store(),Y.Store()) ) return;
215  }
216 
217  ColumnVector B = V;
218  ColumnVector A = U;
219  X.ReSize(n); Y.ReSize(n);
220  const int nextmx = 8;
221  int prime[8] = { 2,3,5,7,11,13,17,19 };
222  int after = 1; int before = n; int next = 0; bool inzee = true;
223  int now = 0; int b1; // initialised to keep gnu happy
224 
225  do
226  {
227  for (;;)
228  {
229  if (next < nextmx) { REPORT now = prime[next]; }
230  b1 = before / now; if (b1 * now == before) { REPORT break; }
231  next++; now += 2;
232  }
233  before = b1;
234 
235  if (inzee) { REPORT fftstep(A, B, X, Y, after, now, before); }
236  else { REPORT fftstep(X, Y, A, B, after, now, before); }
237 
238  inzee = !inzee; after *= now;
239  }
240  while (before != 1);
241 
242  if (inzee) { REPORT A.Release(); X = A; B.Release(); Y = B; }
243 }
void Release()
Definition: newmat.h:440
#define A(r, c)
os2<< "> n<< " > nendobj n
static bool ar_1d_ft(int PTS, Real *X, Real *Y)
Definition: newfft.cpp:146
static bool OnlyOldFFT
Definition: newmatap.h:109
#define REPORT
Definition: fft.cpp:23
static bool CanFactor(int PTS)
Definition: newfft.cpp:988

◆ FFT2()

void FFT2 ( const Matrix U,
const Matrix V,
Matrix X,
Matrix Y 
)

Definition at line 440 of file fft.cpp.

References BaseMatrix::Column(), FFT(), n, GeneralMatrix::Ncols(), GeneralMatrix::Nrows(), REPORT, BaseMatrix::Row(), and BaseMatrix::t().

Referenced by FFT2I(), and ossimFftFilter::runFft().

441 {
442  Tracer trace("FFT2");
443  REPORT
444  int m = U.Nrows(); int n = U.Ncols();
445  if (m != V.Nrows() || n != V.Ncols() || m == 0 || n == 0)
446  Throw(ProgramException("Matrix dimensions unequal or zero", U, V));
447  X = U; Y = V;
448  int i; ColumnVector CVR; ColumnVector CVI;
449  for (i = 1; i <= m; ++i)
450  {
451  FFT(X.Row(i).t(), Y.Row(i).t(), CVR, CVI);
452  X.Row(i) = CVR.t(); Y.Row(i) = CVI.t();
453  }
454  for (i = 1; i <= n; ++i)
455  {
456  FFT(X.Column(i), Y.Column(i), CVR, CVI);
457  X.Column(i) = CVR; Y.Column(i) = CVI;
458  }
459 }
GetSubMatrix Column(int) const
Definition: submat.cpp:64
int Ncols() const
Definition: newmat.h:431
void FFT(const ColumnVector &U, const ColumnVector &V, ColumnVector &X, ColumnVector &Y)
Definition: fft.cpp:197
os2<< "> n<< " > nendobj n
GetSubMatrix Row(int) const
Definition: submat.cpp:45
#define REPORT
Definition: fft.cpp:23
int Nrows() const
Definition: newmat.h:430
TransposedMatrix t() const
Definition: newmat6.cpp:316

◆ FFT2I()

void FFT2I ( const Matrix U,
const Matrix V,
Matrix X,
Matrix Y 
)

Definition at line 461 of file fft.cpp.

References FFT2(), n, GeneralMatrix::Ncols(), GeneralMatrix::Nrows(), and REPORT.

Referenced by ossimFftFilter::runFft().

462 {
463  // Inverse transform
464  Tracer trace("FFT2I");
465  REPORT
466  FFT2(U,-V,X,Y);
467  const Real n = X.Nrows() * X.Ncols(); X /= n; Y /= (-n);
468 }
double Real
Definition: include.h:57
int Ncols() const
Definition: newmat.h:431
void FFT2(const Matrix &U, const Matrix &V, Matrix &X, Matrix &Y)
Definition: fft.cpp:440
os2<< "> n<< " > nendobj n
#define REPORT
Definition: fft.cpp:23
int Nrows() const
Definition: newmat.h:430

◆ FFTI()

void FFTI ( const ColumnVector ,
const ColumnVector ,
ColumnVector ,
ColumnVector  
)

Definition at line 116 of file fft.cpp.

References FFT(), n, GeneralMatrix::Nrows(), and REPORT.

118 {
119  // Inverse transform
120  Tracer trace("FFTI");
121  REPORT
122  FFT(U,-V,X,Y);
123  const Real n = X.Nrows(); X /= n; Y /= (-n);
124 }
double Real
Definition: include.h:57
void FFT(const ColumnVector &U, const ColumnVector &V, ColumnVector &X, ColumnVector &Y)
Definition: fft.cpp:197
os2<< "> n<< " > nendobj n
#define REPORT
Definition: fft.cpp:23

◆ HHDecompose() [1/2]

void HHDecompose ( Matrix X,
LowerTriangularMatrix L 
)
inline

Definition at line 26 of file newmatap.h.

References QRZT().

27 { QRZT(X,L); }
void QRZT(Matrix &, LowerTriangularMatrix &)
Definition: hholder.cpp:28

◆ HHDecompose() [2/2]

void HHDecompose ( const Matrix X,
Matrix Y,
Matrix M 
)
inline

Definition at line 29 of file newmatap.h.

References QRZT().

30 { QRZT(X, Y, M); }
void QRZT(Matrix &, LowerTriangularMatrix &)
Definition: hholder.cpp:28

◆ Jacobi() [1/4]

void Jacobi ( const SymmetricMatrix ,
DiagonalMatrix  
)

Definition at line 110 of file jacobi.cpp.

111 { REPORT SymmetricMatrix A; Matrix V; Jacobi(X,D,A,V,false); }
void Jacobi(const SymmetricMatrix &X, DiagonalMatrix &D, SymmetricMatrix &A, Matrix &V, bool eivec)
Definition: jacobi.cpp:27
#define REPORT
Definition: jacobi.cpp:23
#define A(r, c)
Definition: newmat.h:543

◆ Jacobi() [2/4]

void Jacobi ( const SymmetricMatrix ,
DiagonalMatrix ,
SymmetricMatrix  
)

Definition at line 113 of file jacobi.cpp.

114 { REPORT Matrix V; Jacobi(X,D,A,V,false); }
void Jacobi(const SymmetricMatrix &X, DiagonalMatrix &D, SymmetricMatrix &A, Matrix &V, bool eivec)
Definition: jacobi.cpp:27
#define REPORT
Definition: jacobi.cpp:23
#define A(r, c)
Definition: newmat.h:543

◆ Jacobi() [3/4]

void Jacobi ( const SymmetricMatrix ,
DiagonalMatrix ,
Matrix  
)

Definition at line 116 of file jacobi.cpp.

117 { REPORT SymmetricMatrix A; Jacobi(X,D,A,V,true); }
void Jacobi(const SymmetricMatrix &X, DiagonalMatrix &D, SymmetricMatrix &A, Matrix &V, bool eivec)
Definition: jacobi.cpp:27
#define REPORT
Definition: jacobi.cpp:23
#define A(r, c)

◆ Jacobi() [4/4]

void Jacobi ( const SymmetricMatrix ,
DiagonalMatrix ,
SymmetricMatrix ,
Matrix ,
bool  = true 
)

Definition at line 27 of file jacobi.cpp.

29 {
30  Real epsilon = FloatingPointPrecision::Epsilon();
31  Tracer et("Jacobi");
32  REPORT
33  int n = X.Nrows(); DiagonalMatrix B(n), Z(n); D.ReSize(n); A = X;
34  if (eivec) { REPORT V.ReSize(n,n); D = 1.0; V = D; }
35  B << A; D = B; Z = 0.0; A.Inject(Z);
36  bool converged = false;
37  for (int i=1; i<=50; i++)
38  {
39  Real sm=0.0; Real* a = A.Store(); int p = A.Storage();
40  while (p--) sm += fabs(*a++); // have previously zeroed diags
41  if (sm==0.0) { REPORT converged = true; break; }
42  Real tresh = (i<4) ? 0.2 * sm / square(n) : 0.0; a = A.Store();
43  for (p = 0; p < n; p++)
44  {
45  Real* ap1 = a + (p*(p+1))/2;
46  Real& zp = Z.element(p); Real& dp = D.element(p);
47  for (int q = p+1; q < n; q++)
48  {
49  Real* ap = ap1; Real* aq = a + (q*(q+1))/2;
50  Real& zq = Z.element(q); Real& dq = D.element(q);
51  Real& apq = A.element(q,p);
52  Real g = 100 * fabs(apq); Real adp = fabs(dp); Real adq = fabs(dq);
53 
54  if (i>4 && g < epsilon*adp && g < epsilon*adq) { REPORT apq = 0.0; }
55  else if (fabs(apq) > tresh)
56  {
57  REPORT
58  Real t; Real h = dq - dp; Real ah = fabs(h);
59  if (g < epsilon*ah) { REPORT t = apq / h; }
60  else
61  {
62  REPORT
63  Real theta = 0.5 * h / apq;
64  t = 1.0 / ( fabs(theta) + sqrt(1.0 + square(theta)) );
65  if (theta<0.0) { REPORT t = -t; }
66  }
67  Real c = 1.0 / sqrt(1.0 + square(t)); Real s = t * c;
68  Real tau = s / (1.0 + c); h = t * apq;
69  zp -= h; zq += h; dp -= h; dq += h; apq = 0.0;
70  int j = p;
71  while (j--)
72  {
73  g = *ap; h = *aq;
74  *ap++ = g-s*(h+g*tau); *aq++ = h+s*(g-h*tau);
75  }
76  int ip = p+1; j = q-ip; ap += ip++; aq++;
77  while (j--)
78  {
79  g = *ap; h = *aq;
80  *ap = g-s*(h+g*tau); *aq++ = h+s*(g-h*tau);
81  ap += ip++;
82  }
83  if (q < n-1) // last loop is non-empty
84  {
85  int iq = q+1; j = n-iq; ap += ip++; aq += iq++;
86  for (;;)
87  {
88  g = *ap; h = *aq;
89  *ap = g-s*(h+g*tau); *aq = h+s*(g-h*tau);
90  if (!(--j)) break;
91  ap += ip++; aq += iq++;
92  }
93  }
94  if (eivec)
95  {
96  REPORT
97  RectMatrixCol VP(V,p); RectMatrixCol VQ(V,q);
98  Rotate(VP, VQ, tau, s);
99  }
100  }
101  }
102  }
103  B = B + Z; D = B; Z = 0.0;
104  }
105  if (!converged) Throw(ConvergenceException(X));
106  if (eivec) SortSV(D, V, true);
107  else SortAscending(D);
108 }
double Real
Definition: include.h:57
void SortAscending(GeneralMatrix &)
Definition: sort.cpp:121
void Rotate(RectMatrixCol &U, RectMatrixCol &V, Real tau, Real s)
Definition: newmatrm.cpp:156
T square(T x)
Definition: ossimCommon.h:334
#define REPORT
Definition: jacobi.cpp:23
#define A(r, c)
os2<< "> n<< " > nendobj n
void SortSV(DiagonalMatrix &D, Matrix &U, bool ascending=false)
Definition: sort.cpp:190

◆ LeftCircularUpdateCholesky()

void LeftCircularUpdateCholesky ( UpperTriangularMatrix chol,
int  k,
int  l 
)

Definition at line 225 of file cholesky.cpp.

References BaseMatrix::Column(), GivensRotationR(), GeneralMatrix::Nrows(), and pythag().

226 {
227  int nRC = chol.Nrows();
228  int i, j;
229 
230  // I. compute shift of column k to the lth position
231  Matrix cholCopy = chol;
232  // a. grab column k
233  ColumnVector columnK = cholCopy.Column(k);
234  // b. shift columns k+1,...l to the LEFT
235  for(j = k+1; j <= l; ++j)
236  cholCopy.Column(j-1) = cholCopy.Column(j);
237  // c. copy the elements of columnK into the lth column of cholCopy
238  cholCopy.Column(l) = 0.0;
239  for(i = 1; i <= k; ++i)
240  cholCopy(i,l) = columnK(i);
241 
242  // II. apply and compute Given's rotations
243  int nGivens = l-k;
244  ColumnVector cGivens(nGivens); cGivens = 0.0;
245  ColumnVector sGivens(nGivens); sGivens = 0.0;
246  for(j = k; j <= nRC; ++j)
247  {
248  ColumnVector columnJ = cholCopy.Column(j);
249 
250  // apply the previous Givens rotations to columnJ
251  int imax = j - k; if (imax > nGivens) imax = nGivens;
252  for(int i = 1; i <= imax; ++i)
253  {
254  int gIndex = i;
255  int topRowIndex = k + i - 1;
256  GivensRotationR(cGivens(gIndex), sGivens(gIndex),
257  columnJ(topRowIndex), columnJ(topRowIndex+1));
258  }
259 
260  // compute a new Given's rotation when j < l
261  if(j < l)
262  {
263  int gIndex = j-k+1;
264  columnJ(j) = pythag(columnJ(j), columnJ(j+1), cGivens(gIndex), sGivens(gIndex));
265  columnJ(j+1) = 0.0;
266  }
267 
268  cholCopy.Column(j) = columnJ;
269  }
270 
271  chol << cholCopy;
272 
273 }
GetSubMatrix Column(int) const
Definition: submat.cpp:64
void GivensRotationR(Real cGivens, Real sGivens, Real &x, Real &y)
Definition: newmatrm.h:124
Real pythag(Real f, Real g, Real &c, Real &s)
Definition: newmatrm.cpp:186
Definition: newmat.h:543
int Nrows() const
Definition: newmat.h:430

◆ QRZ() [1/2]

void QRZ ( Matrix ,
UpperTriangularMatrix  
)

Definition at line 111 of file hholder.cpp.

References n, GeneralMatrix::Ncols(), GeneralMatrix::Nrows(), REPORT, UpperTriangularMatrix::ReSize(), and GeneralMatrix::Store().

Referenced by NonLinearLeastSquares::NextPoint().

112 {
113  REPORT
114  Tracer et("QRZ(1)");
115  int n = X.Nrows(); int s = X.Ncols(); U.ReSize(s); U = 0.0;
116  Real* xi0 = X.Store(); Real* u0 = U.Store(); Real* u;
117  int j, k; int J = s; int i = s;
118  while (i--)
119  {
120  Real* xj0 = xi0; Real* xi = xi0; k = n;
121  if (k) for (;;)
122  {
123  u = u0; Real Xi = *xi; Real* xj = xj0;
124  j = J; while(j--) *u++ += Xi * *xj++;
125  if (!(--k)) break;
126  xi += s; xj0 += s;
127  }
128 
129  Real sum = std::sqrt(*u0); *u0 = sum; u = u0+1;
130  if (sum == 0.0)
131  {
132  REPORT
133  j = J - 1; while(j--) *u++ = 0.0;
134 
135  xj0 = xi0++; k = n;
136  if (k) for (;;)
137  {
138  *xj0 = 0.0;
139  if (!(--k)) break;
140  xj0 += s;
141  }
142  u0 += J--;
143  }
144  else
145  {
146  int J1 = J-1; j = J1; while(j--) *u++ /= sum;
147 
148  xj0 = xi0; xi = xi0++; k = n;
149  if (k) for (;;)
150  {
151  u = u0+1; Real Xi = *xi; Real* xj = xj0;
152  Xi /= sum; *xj++ = Xi;
153  j = J1; while(j--) *xj++ -= *u++ * Xi;
154  if (!(--k)) break;
155  xi += s; xj0 += s;
156  }
157  u0 += J--;
158  }
159  }
160 }
double Real
Definition: include.h:57
os2<< "> n<< " > nendobj n
#define REPORT
Definition: hholder.cpp:20

◆ QRZ() [2/2]

void QRZ ( const Matrix ,
Matrix ,
Matrix  
)

Definition at line 162 of file hholder.cpp.

References n, GeneralMatrix::Ncols(), GeneralMatrix::Nrows(), REPORT, Matrix::ReSize(), and GeneralMatrix::Store().

163 {
164  REPORT
165  Tracer et("QRZ(2)");
166  int n = X.Nrows(); int s = X.Ncols(); int t = Y.Ncols();
167  if (Y.Nrows() != n)
168  { Throw(ProgramException("Unequal column lengths",X,Y)); }
169  M.ReSize(s,t); M = 0;Real* m0 = M.Store(); Real* m;
170  Real* xi0 = X.Store();
171  int j, k; int i = s;
172  while (i--)
173  {
174  Real* xj0 = Y.Store(); Real* xi = xi0; k = n;
175  if (k) for (;;)
176  {
177  m = m0; Real Xi = *xi; Real* xj = xj0;
178  j = t; while(j--) *m++ += Xi * *xj++;
179  if (!(--k)) break;
180  xi += s; xj0 += t;
181  }
182 
183  xj0 = Y.Store(); xi = xi0++; k = n;
184  if (k) for (;;)
185  {
186  m = m0; Real Xi = *xi; Real* xj = xj0;
187  j = t; while(j--) *xj++ -= *m++ * Xi;
188  if (!(--k)) break;
189  xi += s; xj0 += t;
190  }
191  m0 += t;
192  }
193 }
double Real
Definition: include.h:57
os2<< "> n<< " > nendobj n
#define REPORT
Definition: hholder.cpp:20

◆ QRZT() [1/2]

void QRZT ( Matrix ,
LowerTriangularMatrix  
)

Definition at line 28 of file hholder.cpp.

References LowerTriangularMatrix::element(), n, GeneralMatrix::Ncols(), GeneralMatrix::Nrows(), REPORT, LowerTriangularMatrix::ReSize(), square(), and GeneralMatrix::Store().

Referenced by HHDecompose().

29 {
30  REPORT
31  Tracer et("QRZT(1)");
32  int n = X.Ncols(); int s = X.Nrows(); L.ReSize(s);
33  Real* xi = X.Store(); int k;
34  for (int i=0; i<s; i++)
35  {
36  Real sum = 0.0;
37  Real* xi0=xi; k=n; while(k--) { sum += square(*xi++); }
38  sum = std::sqrt(sum);
39  if (sum == 0.0)
40  {
41  REPORT
42  k=n; while(k--) { *xi0++ = 0.0; }
43  for (int j=i; j<s; j++) L.element(j,i) = 0.0;
44  }
45  else
46  {
47  L.element(i,i) = sum;
48  Real* xj0=xi0; k=n; while(k--) { *xj0++ /= sum; }
49  for (int j=i+1; j<s; j++)
50  {
51  sum=0.0;
52  xi=xi0; Real* xj=xj0; k=n; while(k--) { sum += *xi++ * *xj++; }
53  xi=xi0; k=n; while(k--) { *xj0++ -= sum * *xi++; }
54  L.element(j,i) = sum;
55  }
56  }
57  }
58 }
double Real
Definition: include.h:57
os2<< "> n<< " > nendobj n
Real square(Real x)
Definition: hholder.cpp:26
#define REPORT
Definition: hholder.cpp:20

◆ QRZT() [2/2]

void QRZT ( const Matrix ,
Matrix ,
Matrix  
)

Definition at line 60 of file hholder.cpp.

References Matrix::element(), n, GeneralMatrix::Ncols(), GeneralMatrix::Nrows(), REPORT, Matrix::ReSize(), and GeneralMatrix::Store().

61 {
62  REPORT
63  Tracer et("QRZT(2)");
64  int n = X.Ncols(); int s = X.Nrows(); int t = Y.Nrows();
65  if (Y.Ncols() != n)
66  { Throw(ProgramException("Unequal row lengths",X,Y)); }
67  M.ReSize(t,s);
68  Real* xi = X.Store(); int k;
69  for (int i=0; i<s; i++)
70  {
71  Real* xj0 = Y.Store(); Real* xi0 = xi;
72  for (int j=0; j<t; j++)
73  {
74  Real sum=0.0;
75  xi=xi0; Real* xj=xj0; k=n; while(k--) { sum += *xi++ * *xj++; }
76  xi=xi0; k=n; while(k--) { *xj0++ -= sum * *xi++; }
77  M.element(j,i) = sum;
78  }
79  }
80 }
double Real
Definition: include.h:57
os2<< "> n<< " > nendobj n
#define REPORT
Definition: hholder.cpp:20

◆ RealFFT()

void RealFFT ( const ColumnVector ,
ColumnVector ,
ColumnVector  
)

Definition at line 126 of file fft.cpp.

References A, n, GeneralMatrix::Nrows(), and REPORT.

Referenced by DCT_II(), and DST_II().

127 {
128  // Fourier transform of a real series
129  Tracer trace("RealFFT");
130  REPORT
131  const int n = U.Nrows(); // length of arrays
132  const int n2 = n / 2;
133  if (n != 2 * n2)
134  Throw(ProgramException("Vector length not multiple of 2", U));
135  ColumnVector A(n2), B(n2);
136  Real* a = A.Store(); Real* b = B.Store(); Real* u = U.Store(); int i = n2;
137  while (i--) { *a++ = *u++; *b++ = *u++; }
138  FFT(A,B,A,B);
139  int n21 = n2 + 1;
140  X.ReSize(n21); Y.ReSize(n21);
141  i = n2 - 1;
142  a = A.Store(); b = B.Store(); // first els of A and B
143  Real* an = a + i; Real* bn = b + i; // last els of A and B
144  Real* x = X.Store(); Real* y = Y.Store(); // first els of X and Y
145  Real* xn = x + n2; Real* yn = y + n2; // last els of X and Y
146 
147  *x++ = *a + *b; *y++ = 0.0; // first complex element
148  *xn-- = *a++ - *b++; *yn-- = 0.0; // last complex element
149 
150  int j = -1; i = n2/2;
151  while (i--)
152  {
153  Real c,s; cossin(j--,n,c,s);
154  Real am = *a - *an; Real ap = *a++ + *an--;
155  Real bm = *b - *bn; Real bp = *b++ + *bn--;
156  Real samcbp = s * am + c * bp; Real sbpcam = s * bp - c * am;
157  *x++ = 0.5 * ( ap + samcbp); *y++ = 0.5 * ( bm + sbpcam);
158  *xn-- = 0.5 * ( ap - samcbp); *yn-- = 0.5 * (-bm + sbpcam);
159  }
160 }
ossim_uint32 x
double Real
Definition: include.h:57
ossim_uint32 y
#define A(r, c)
void FFT(const ColumnVector &U, const ColumnVector &V, ColumnVector &X, ColumnVector &Y)
Definition: fft.cpp:197
os2<< "> n<< " > nendobj n
#define REPORT
Definition: fft.cpp:23

◆ RealFFTI()

void RealFFTI ( const ColumnVector ,
const ColumnVector ,
ColumnVector  
)

Definition at line 162 of file fft.cpp.

Referenced by DCT_inverse(), and DST_inverse().

163 {
164  // inverse of a Fourier transform of a real series
165  Tracer trace("RealFFTI");
166  REPORT
167  const int n21 = A.Nrows(); // length of arrays
168  if (n21 != B.Nrows() || n21 == 0)
169  Throw(ProgramException("Vector lengths unequal or zero", A, B));
170  const int n2 = n21 - 1; const int n = 2 * n2; int i = n2 - 1;
171 
172  ColumnVector X(n2), Y(n2);
173  Real* a = A.Store(); Real* b = B.Store(); // first els of A and B
174  Real* an = a + n2; Real* bn = b + n2; // last els of A and B
175  Real* x = X.Store(); Real* y = Y.Store(); // first els of X and Y
176  Real* xn = x + i; Real* yn = y + i; // last els of X and Y
177 
178  Real hn = 0.5 / n2;
179  *x++ = hn * (*a + *an); *y++ = - hn * (*a - *an);
180  a++; an--; b++; bn--;
181  int j = -1; i = n2/2;
182  while (i--)
183  {
184  Real c,s; cossin(j--,n,c,s);
185  Real am = *a - *an; Real ap = *a++ + *an--;
186  Real bm = *b - *bn; Real bp = *b++ + *bn--;
187  Real samcbp = s * am - c * bp; Real sbpcam = s * bp + c * am;
188  *x++ = hn * ( ap + samcbp); *y++ = - hn * ( bm + sbpcam);
189  *xn-- = hn * ( ap - samcbp); *yn-- = - hn * (-bm + sbpcam);
190  }
191  FFT(X,Y,X,Y); // have done inverting elsewhere
192  U.ReSize(n); i = n2;
193  x = X.Store(); y = Y.Store(); Real* u = U.Store();
194  while (i--) { *u++ = *x++; *u++ = - *y++; }
195 }
ossim_uint32 x
double Real
Definition: include.h:57
ossim_uint32 y
#define A(r, c)
void FFT(const ColumnVector &U, const ColumnVector &V, ColumnVector &X, ColumnVector &Y)
Definition: fft.cpp:197
os2<< "> n<< " > nendobj n
#define REPORT
Definition: fft.cpp:23

◆ RightCircularUpdateCholesky()

void RightCircularUpdateCholesky ( UpperTriangularMatrix chol,
int  k,
int  l 
)

Definition at line 170 of file cholesky.cpp.

References BaseMatrix::Column(), GivensRotationR(), GeneralMatrix::Nrows(), and pythag().

171 {
172  int nRC = chol.Nrows();
173  int i, j;
174 
175  // I. compute shift of column l to the kth position
176  Matrix cholCopy = chol;
177  // a. grab column l
178  ColumnVector columnL = cholCopy.Column(l);
179  // b. shift columns k,...l-1 to the RIGHT
180  for(j = l-1; j >= k; --j)
181  cholCopy.Column(j+1) = cholCopy.Column(j);
182  // c. copy the top k-1 elements of columnL into the kth column of cholCopy
183  cholCopy.Column(k) = 0.0;
184  for(i = 1; i < k; ++i) cholCopy(i,k) = columnL(i);
185 
186  // II. determine the l-k Given's rotations
187  int nGivens = l-k;
188  ColumnVector cGivens(nGivens); cGivens = 0.0;
189  ColumnVector sGivens(nGivens); sGivens = 0.0;
190  for(i = l; i > k; i--)
191  {
192  int givensIndex = l-i+1;
193  columnL(i-1) = pythag(columnL(i-1), columnL(i),
194  cGivens(givensIndex), sGivens(givensIndex));
195  columnL(i) = 0.0;
196  }
197  // the kth entry of columnL is the new diagonal element in column k of cholCopy
198  cholCopy(k,k) = columnL(k);
199 
200  // III. apply these Given's rotations to subsequent columns
201  // for columns k+1,...,l-1 we only need to apply the last nGivens-(j-k) rotations
202  for(j = k+1; j <= nRC; ++j)
203  {
204  ColumnVector columnJ = cholCopy.Column(j);
205  int imin = nGivens - (j-k) + 1; if (imin < 1) imin = 1;
206  for(int gIndex = imin; gIndex <= nGivens; ++gIndex)
207  {
208  // apply gIndex Given's rotation
209  int topRowIndex = k + nGivens - gIndex;
210  GivensRotationR(cGivens(gIndex), sGivens(gIndex),
211  columnJ(topRowIndex), columnJ(topRowIndex+1));
212  }
213  cholCopy.Column(j) = columnJ;
214  }
215 
216  chol << cholCopy;
217 }
GetSubMatrix Column(int) const
Definition: submat.cpp:64
void GivensRotationR(Real cGivens, Real sGivens, Real &x, Real &y)
Definition: newmatrm.h:124
Real pythag(Real f, Real g, Real &c, Real &s)
Definition: newmatrm.cpp:186
Definition: newmat.h:543
int Nrows() const
Definition: newmat.h:430

◆ SortAscending()

void SortAscending ( GeneralMatrix )

Definition at line 121 of file sort.cpp.

References DoSimpleSort, max, REPORT, GeneralMatrix::Storage(), and GeneralMatrix::Store().

122 {
123  REPORT
124  Tracer et("QuickSortAscending");
125 
126  Real* data = GM.Store(); int max = GM.Storage();
127 
128  if (max > DoSimpleSort) MyQuickSortAscending(data, data + max - 1, 0);
129  InsertionSortAscending(data, max, DoSimpleSort);
130 
131 }
double Real
Definition: include.h:57
#define REPORT
Definition: sort.cpp:18
#define DoSimpleSort
Definition: sort.cpp:32
#define max(a, b)
Definition: auxiliary.h:76

◆ SortDescending()

void SortDescending ( GeneralMatrix )

Definition at line 45 of file sort.cpp.

References DoSimpleSort, max, REPORT, GeneralMatrix::Storage(), and GeneralMatrix::Store().

Referenced by SVD().

46 {
47  REPORT
48  Tracer et("QuickSortDescending");
49 
50  Real* data = GM.Store(); int max = GM.Storage();
51 
52  if (max > DoSimpleSort) MyQuickSortDescending(data, data + max - 1, 0);
53  InsertionSortDescending(data, max, DoSimpleSort);
54 
55 }
double Real
Definition: include.h:57
#define REPORT
Definition: sort.cpp:18
#define DoSimpleSort
Definition: sort.cpp:32
#define max(a, b)
Definition: auxiliary.h:76

◆ SortSV() [1/2]

void SortSV ( DiagonalMatrix D,
Matrix U,
bool  ascending = false 
)

Definition at line 190 of file sort.cpp.

Referenced by SVD().

191 {
192  REPORT
193  Tracer trace("SortSV_DU");
194  int m = U.Nrows(); int n = U.Ncols();
195  if (n != D.Nrows()) Throw(IncompatibleDimensionsException(D,U));
196  Real* u = U.Store();
197  for (int i=0; i<n; i++)
198  {
199  int k = i; Real p = D.element(i);
200  if (ascending)
201  {
202  for (int j=i+1; j<n; j++)
203  { if (D.element(j) < p) { k = j; p = D.element(j); } }
204  }
205  else
206  {
207  for (int j=i+1; j<n; j++)
208  { if (D.element(j) > p) { k = j; p = D.element(j); } }
209  }
210  if (k != i)
211  {
212  D.element(k) = D.element(i); D.element(i) = p; int j = m;
213  Real* uji = u + i; Real* ujk = u + k;
214  if (j) for(;;)
215  {
216  p = *uji; *uji = *ujk; *ujk = p;
217  if (!(--j)) break;
218  uji += n; ujk += n;
219  }
220  }
221  }
222 }
double Real
Definition: include.h:57
Real & element(int, int)
Definition: newmat6.cpp:725
int Ncols() const
Definition: newmat.h:431
#define REPORT
Definition: sort.cpp:18
os2<< "> n<< " > nendobj n
int Nrows() const
Definition: newmat.h:430
Real * Store() const
Definition: newmat.h:433

◆ SortSV() [2/2]

void SortSV ( DiagonalMatrix D,
Matrix U,
Matrix V,
bool  ascending = false 
)

Definition at line 224 of file sort.cpp.

225 {
226  REPORT
227  Tracer trace("SortSV_DUV");
228  int mu = U.Nrows(); int mv = V.Nrows(); int n = D.Nrows();
229  if (n != U.Ncols()) Throw(IncompatibleDimensionsException(D,U));
230  if (n != V.Ncols()) Throw(IncompatibleDimensionsException(D,V));
231  Real* u = U.Store(); Real* v = V.Store();
232  for (int i=0; i<n; i++)
233  {
234  int k = i; Real p = D.element(i);
235  if (ascending)
236  {
237  for (int j=i+1; j<n; j++)
238  { if (D.element(j) < p) { k = j; p = D.element(j); } }
239  }
240  else
241  {
242  for (int j=i+1; j<n; j++)
243  { if (D.element(j) > p) { k = j; p = D.element(j); } }
244  }
245  if (k != i)
246  {
247  D.element(k) = D.element(i); D.element(i) = p;
248  Real* uji = u + i; Real* ujk = u + k;
249  Real* vji = v + i; Real* vjk = v + k;
250  int j = mu;
251  if (j) for(;;)
252  {
253  p = *uji; *uji = *ujk; *ujk = p; if (!(--j)) break;
254  uji += n; ujk += n;
255  }
256  j = mv;
257  if (j) for(;;)
258  {
259  p = *vji; *vji = *vjk; *vjk = p; if (!(--j)) break;
260  vji += n; vjk += n;
261  }
262  }
263  }
264 }
double Real
Definition: include.h:57
Real & element(int, int)
Definition: newmat6.cpp:725
int Ncols() const
Definition: newmat.h:431
#define REPORT
Definition: sort.cpp:18
os2<< "> n<< " > nendobj n
int Nrows() const
Definition: newmat.h:430
Real * Store() const
Definition: newmat.h:433

◆ SVD() [1/3]

void SVD ( const Matrix ,
DiagonalMatrix ,
Matrix ,
Matrix ,
bool  = true,
bool  = true 
)

Definition at line 26 of file svd.cpp.

References A, RectMatrixRowCol::AddScaled(), ComplexScale(), RectMatrixRowCol::Divide(), RectMatrixRow::Down(), RectMatrixCol::Down(), RectMatrixRowCol::DownDiag(), DiagonalMatrix::element(), RowVector::element(), RectMatrixRowCol::First(), RectMatrixCol::Left(), Maximum(), Minimum(), n, RectMatrixRowCol::Negate(), pythag(), REPORT, RectMatrixRow::Reset(), Matrix::ReSize(), DiagonalMatrix::ReSize(), RectMatrixRow::Right(), RectMatrixCol::Right(), sign(), SortDescending(), SortSV(), ossim::square(), RectMatrixRowCol::SumSquare(), RectMatrixCol::Up(), RectMatrixRowCol::UpDiag(), x, y, and RectMatrixRowCol::Zero().

Referenced by ossimRpcSolver::invert(), ossimSensorModelTuple::invert(), ossimRpcProjection::invert(), ossimSensorModel::invert(), and ossimPolynom< ossim_float64, 3 >::invert().

29 {
30  REPORT
31  Tracer trace("SVD");
32  Real eps = FloatingPointPrecision::Epsilon();
34 
35  int m = A.Nrows(); int n = A.Ncols();
36  if (m<n)
37  Throw(ProgramException("Want no. Rows >= no. Cols", A));
38  if (withV && &U == &V)
39  Throw(ProgramException("Need different matrices for U and V", U, V));
40  U = A; Real g = 0.0; Real f,h; Real x = 0.0; int i;
41  RowVector E(n); RectMatrixRow EI(E,0); Q.ReSize(n);
42  RectMatrixCol UCI(U,0); RectMatrixRow URI(U,0,1,n-1);
43 
44  if (n) for (i=0;;)
45  {
46  EI.First() = g; Real ei = g; EI.Right(); Real s = UCI.SumSquare();
47  if (s<tol) { REPORT Q.element(i) = 0.0; }
48  else
49  {
50  REPORT
51  f = UCI.First(); g = -sign(sqrt(s), f); h = f*g-s; UCI.First() = f-g;
52  Q.element(i) = g; RectMatrixCol UCJ = UCI; int j=n-i;
53  while (--j) { UCJ.Right(); UCJ.AddScaled(UCI, (UCI*UCJ)/h); }
54  }
55 
56  s = URI.SumSquare();
57  if (s<tol) { REPORT g = 0.0; }
58  else
59  {
60  REPORT
61  f = URI.First(); g = -sign(sqrt(s), f); URI.First() = f-g;
62  EI.Divide(URI,f*g-s); RectMatrixRow URJ = URI; int j=m-i;
63  while (--j) { URJ.Down(); URJ.AddScaled(EI, URI*URJ); }
64  }
65 
66  Real y = fabs(Q.element(i)) + fabs(ei); if (x<y) { REPORT x = y; }
67  if (++i == n) { REPORT break; }
68  UCI.DownDiag(); URI.DownDiag();
69  }
70 
71  if (withV)
72  {
73  REPORT
74  V.ReSize(n,n); V = 0.0; RectMatrixCol VCI(V,n-1,n-1,1);
75  if (n) { VCI.First() = 1.0; g=E.element(n-1); if (n!=1) URI.UpDiag(); }
76  for (i=n-2; i>=0; i--)
77  {
78  VCI.Left();
79  if (g!=0.0)
80  {
81  VCI.Divide(URI, URI.First()*g); int j = n-i;
82  RectMatrixCol VCJ = VCI;
83  while (--j) { VCJ.Right(); VCJ.AddScaled( VCI, (URI*VCJ) ); }
84  }
85  VCI.Zero(); VCI.Up(); VCI.First() = 1.0; g=E.element(i);
86  if (i==0) break;
87  URI.UpDiag();
88  }
89  }
90 
91  if (withU)
92  {
93  REPORT
94  for (i=n-1; i>=0; i--)
95  {
96  g = Q.element(i); URI.Reset(U,i,i+1,n-i-1); URI.Zero();
97  if (g!=0.0)
98  {
99  h=UCI.First()*g; int j=n-i; RectMatrixCol UCJ = UCI;
100  while (--j)
101  {
102  UCJ.Right(); UCI.Down(); UCJ.Down(); Real s = UCI*UCJ;
103  UCI.Up(); UCJ.Up(); UCJ.AddScaled(UCI,s/h);
104  }
105  UCI.Divide(g);
106  }
107  else UCI.Zero();
108  UCI.First() += 1.0;
109  if (i==0) break;
110  UCI.UpDiag();
111  }
112  }
113 
114  eps *= x;
115  for (int k=n-1; k>=0; k--)
116  {
117  Real z = -FloatingPointPrecision::Maximum(); // to keep Gnu happy
118  Real y; int limit = 50; int l = 0;
119  while (limit--)
120  {
121  Real c, s; int i; int l1=k; bool tfc=false;
122  for (l=k; l>=0; l--)
123  {
124 // if (fabs(E.element(l))<=eps) goto test_f_convergence;
125  if (fabs(E.element(l))<=eps) { REPORT tfc=true; break; }
126  if (fabs(Q.element(l-1))<=eps) { REPORT l1=l; break; }
127  REPORT
128  }
129  if (!tfc)
130  {
131  REPORT
132  l=l1; l1=l-1; s = -1.0; c = 0.0;
133  for (i=l; i<=k; i++)
134  {
135  f = - s * E.element(i); E.element(i) *= c;
136 // if (fabs(f)<=eps) goto test_f_convergence;
137  if (fabs(f)<=eps) { REPORT break; }
138  g = Q.element(i); h = pythag(g,f,c,s); Q.element(i) = h;
139  if (withU)
140  {
141  REPORT
142  RectMatrixCol UCI(U,i); RectMatrixCol UCJ(U,l1);
143  ComplexScale(UCJ, UCI, c, s);
144  }
145  }
146  }
147 // test_f_convergence: z = Q.element(k); if (l==k) goto convergence;
148  z = Q.element(k); if (l==k) { REPORT break; }
149 
150  x = Q.element(l); y = Q.element(k-1);
151  g = E.element(k-1); h = E.element(k);
152  f = ((y-z)*(y+z) + (g-h)*(g+h)) / (2*h*y);
153  if (f>1) { REPORT g = f * sqrt(1 + square(1/f)); }
154  else if (f<-1) { REPORT g = -f * sqrt(1 + square(1/f)); }
155  else { REPORT g = sqrt(f*f + 1); }
156  { REPORT f = ((x-z)*(x+z) + h*(y / ((f<0.0) ? f-g : f+g)-h)) / x; }
157 
158  c = 1.0; s = 1.0;
159  for (i=l+1; i<=k; i++)
160  {
161  g = E.element(i); y = Q.element(i); h = s*g; g *= c;
162  z = pythag(f,h,c,s); E.element(i-1) = z;
163  f = x*c + g*s; g = -x*s + g*c; h = y*s; y *= c;
164  if (withV)
165  {
166  REPORT
167  RectMatrixCol VCI(V,i); RectMatrixCol VCJ(V,i-1);
168  ComplexScale(VCI, VCJ, c, s);
169  }
170  z = pythag(f,h,c,s); Q.element(i-1) = z;
171  f = c*g + s*y; x = -s*g + c*y;
172  if (withU)
173  {
174  REPORT
175  RectMatrixCol UCI(U,i); RectMatrixCol UCJ(U,i-1);
176  ComplexScale(UCI, UCJ, c, s);
177  }
178  }
179  E.element(l) = 0.0; E.element(k) = f; Q.element(k) = x;
180  }
181  if (l!=k) { Throw(ConvergenceException(A)); }
182 // convergence:
183  if (z < 0.0)
184  {
185  REPORT
186  Q.element(k) = -z;
187  if (withV) { RectMatrixCol VCI(V,k); VCI.Negate(); }
188  }
189  }
190  if (withU & withV) SortSV(Q, U, V);
191  else if (withU) SortSV(Q, U);
192  else if (withV) SortSV(Q, V);
193  else SortDescending(Q);
194 }
ossim_uint32 x
double Real
Definition: include.h:57
Real sign(Real x, Real y)
Definition: newmatrm.h:108
Real Maximum(const BaseMatrix &B)
Definition: newmat.h:1766
ossim_uint32 y
#define REPORT
Definition: svd.cpp:20
T square(T x)
Definition: ossimCommon.h:334
void Up()
Definition: newmatrm.h:72
#define A(r, c)
Real pythag(Real f, Real g, Real &c, Real &s)
Definition: newmatrm.cpp:186
void ComplexScale(RectMatrixCol &U, RectMatrixCol &V, Real x, Real y)
Definition: newmatrm.cpp:132
os2<< "> n<< " > nendobj n
void AddScaled(const RectMatrixRowCol &, Real)
Definition: newmatrm.cpp:79
void SortDescending(GeneralMatrix &)
Definition: sort.cpp:45
Real Minimum(const BaseMatrix &B)
Definition: newmat.h:1767
void Down()
Definition: newmatrm.h:56
void SortSV(DiagonalMatrix &D, Matrix &U, bool ascending=false)
Definition: sort.cpp:190
void Right()
Definition: newmatrm.h:71
void Down()
Definition: newmatrm.h:70

◆ SVD() [2/3]

void SVD ( const Matrix ,
DiagonalMatrix  
)

Definition at line 196 of file svd.cpp.

197 { REPORT Matrix U; SVD(A, D, U, U, false, false); }
void SVD(const Matrix &A, DiagonalMatrix &Q, Matrix &U, Matrix &V, bool withU, bool withV)
Definition: svd.cpp:26
#define REPORT
Definition: svd.cpp:20
#define A(r, c)
Definition: newmat.h:543

◆ SVD() [3/3]

void SVD ( const Matrix A,
DiagonalMatrix D,
Matrix U,
bool  withU = true 
)
inline

Definition at line 66 of file newmatap.h.

67  { SVD(A, D, U, U, withU, false); }
#define A(r, c)
void SVD(const Matrix &, DiagonalMatrix &, Matrix &, Matrix &, bool=true, bool=true)
Definition: svd.cpp:26

◆ UpdateCholesky()

void UpdateCholesky ( UpperTriangularMatrix chol,
RowVector  r1Modification 
)

Definition at line 96 of file cholesky.cpp.

References GivensRotation(), GeneralMatrix::Nrows(), and pythag().

97 {
98  int ncols = chol.Nrows();
99  ColumnVector cGivens(ncols); cGivens = 0.0;
100  ColumnVector sGivens(ncols); sGivens = 0.0;
101 
102  for(int j = 1; j <= ncols; ++j) // process the jth column of chol
103  {
104  // apply the previous Givens rotations k = 1,...,j-1 to column j
105  for(int k = 1; k < j; ++k)
106  GivensRotation(cGivens(k), sGivens(k), chol(k,j), r1Modification(j));
107 
108  // determine the jth Given's rotation
109  pythag(chol(j,j), r1Modification(j), cGivens(j), sGivens(j));
110 
111  // apply the jth Given's rotation
112  {
113  Real tmp0 = cGivens(j) * chol(j,j) + sGivens(j) * r1Modification(j);
114  chol(j,j) = tmp0; r1Modification(j) = 0.0;
115  }
116 
117  }
118 
119 }
void GivensRotation(Real cGivens, Real sGivens, Real &x, Real &y)
Definition: newmatrm.h:116
double Real
Definition: include.h:57
Real pythag(Real f, Real g, Real &c, Real &s)
Definition: newmatrm.cpp:186
int Nrows() const
Definition: newmat.h:430

◆ UpdateQRZ()

void UpdateQRZ ( Matrix X,
UpperTriangularMatrix U 
)

Definition at line 261 of file hholder.cpp.

References n, GeneralMatrix::Ncols(), GeneralMatrix::Nrows(), REPORT, square(), and GeneralMatrix::Store().

262 {
263  REPORT
264  Tracer et("UpdateQRZ");
265  int n = X.Nrows(); int s = X.Ncols();
266  if (s != U.Ncols())
267  Throw(ProgramException("Incompatible dimensions",X,U));
268  Real* xi0 = X.Store(); Real* u0 = U.Store(); Real* u;
269  RowVector V(s); Real* v0 = V.Store(); Real* v; V = 0.0;
270  int j, k; int J = s; int i = s;
271  while (i--)
272  {
273  Real* xj0 = xi0; Real* xi = xi0; k = n;
274  if (k) for (;;)
275  {
276  v = v0; Real Xi = *xi; Real* xj = xj0;
277  j = J; while(j--) *v++ += Xi * *xj++;
278  if (!(--k)) break;
279  xi += s; xj0 += s;
280  }
281 
282  Real r = *u0;
283  Real sum = std::sqrt(*v0 + square(r));
284 
285  if (sum == 0.0)
286  {
287  REPORT
288  u = u0; v = v0;
289  j = J; while(j--) { *u++ = 0.0; *v++ = 0.0; }
290  xj0 = xi0++; k = n;
291  if (k) for (;;)
292  {
293  *xj0 = 0.0;
294  if (!(--k)) break;
295  xj0 += s;
296  }
297  u0 += J--;
298  }
299  else
300  {
301  Real frs = std::fabs(r) + sum;
302  Real a0 = std::sqrt(frs / sum); Real alpha = a0 / frs;
303  if (r <= 0) { REPORT alpha = -alpha; *u0 = sum; }
304  else { REPORT *u0 = -sum; }
305 
306  j = J - 1; v = v0 + 1; u = u0 + 1;
307  while (j--)
308  { *v = a0 * *u + alpha * *v; *u -= a0 * *v; ++v; ++u; }
309 
310  xj0 = xi0; xi = xi0++; k = n;
311  if (k) for (;;)
312  {
313  v = v0 + 1; Real Xi = *xi; Real* xj = xj0;
314  Xi *= alpha; *xj++ = Xi;
315  j = J - 1; while(j--) *xj++ -= *v++ * Xi;
316  if (!(--k)) break;
317  xi += s; xj0 += s;
318  }
319 
320  j = J; v = v0;
321  while (j--) *v++ = 0.0;
322 
323  u0 += J--;
324  }
325  }
326 }
double Real
Definition: include.h:57
int Ncols() const
Definition: newmat.h:431
os2<< "> n<< " > nendobj n
Real square(Real x)
Definition: hholder.cpp:26
#define REPORT
Definition: hholder.cpp:20
int Nrows() const
Definition: newmat.h:430
Real * Store() const
Definition: newmat.h:433

◆ UpdateQRZT()

void UpdateQRZT ( Matrix X,
LowerTriangularMatrix L 
)

Definition at line 222 of file hholder.cpp.

References LowerTriangularMatrix::element(), n, GeneralMatrix::Ncols(), GeneralMatrix::Nrows(), REPORT, square(), and GeneralMatrix::Store().

223 {
224  REPORT
225  Tracer et("UpdateQRZT");
226  int n = X.Ncols(); int s = X.Nrows();
227  if (s != L.Nrows())
228  Throw(ProgramException("Incompatible dimensions",X,L));
229  Real* xi = X.Store(); int k;
230  for (int i=0; i<s; i++)
231  {
232  Real r = L.element(i,i);
233  Real sum = 0.0;
234  Real* xi0=xi; k=n; while(k--) { sum += square(*xi++); }
235  sum = std::sqrt(sum + square(r));
236  if (sum == 0.0)
237  {
238  REPORT
239  k=n; while(k--) { *xi0++ = 0.0; }
240  for (int j=i; j<s; j++) L.element(j,i) = 0.0;
241  }
242  else
243  {
244  Real frs = std::fabs(r) + sum;
245  Real a0 = std::sqrt(frs / sum); Real alpha = a0 / frs;
246  if (r <= 0) { REPORT L.element(i,i) = sum; alpha = -alpha; }
247  else { REPORT L.element(i,i) = -sum; }
248  Real* xj0=xi0; k=n; while(k--) { *xj0++ *= alpha; }
249  for (int j=i+1; j<s; j++)
250  {
251  sum = 0.0;
252  xi=xi0; Real* xj=xj0; k=n; while(k--) { sum += *xi++ * *xj++; }
253  sum += a0 * L.element(j,i);
254  xi=xi0; k=n; while(k--) { *xj0++ -= sum * *xi++; }
255  L.element(j,i) -= sum * a0;
256  }
257  }
258  }
259 }
double Real
Definition: include.h:57
Real & element(int, int)
Definition: newmat6.cpp:709
int Ncols() const
Definition: newmat.h:431
os2<< "> n<< " > nendobj n
Real square(Real x)
Definition: hholder.cpp:26
#define REPORT
Definition: hholder.cpp:20
int Nrows() const
Definition: newmat.h:430
Real * Store() const
Definition: newmat.h:433