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

Go to the source code of this file.

Macros

#define WANT_MATH
 
#define REPORT   {}
 
#define DoSimpleSort   17
 
#define MaxDepth   50
 

Functions

void SortDescending (GeneralMatrix &GM)
 
void SortAscending (GeneralMatrix &GM)
 
void SortSV (DiagonalMatrix &D, Matrix &U, bool ascending)
 
void SortSV (DiagonalMatrix &D, Matrix &U, Matrix &V, bool ascending)
 

Macro Definition Documentation

◆ DoSimpleSort

#define DoSimpleSort   17

Definition at line 32 of file sort.cpp.

Referenced by SortAscending(), and SortDescending().

◆ MaxDepth

#define MaxDepth   50

Definition at line 33 of file sort.cpp.

◆ REPORT

#define REPORT   {}

Definition at line 18 of file sort.cpp.

Referenced by SortAscending(), and SortDescending().

◆ WANT_MATH

#define WANT_MATH

Definition at line 5 of file sort.cpp.

Function Documentation

◆ SortAscending()

void SortAscending ( GeneralMatrix GM)

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
int Storage() const
Definition: newmat.h:432
Real * Store() const
Definition: newmat.h:433

◆ SortDescending()

void SortDescending ( GeneralMatrix GM)

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
int Storage() const
Definition: newmat.h:432
Real * Store() const
Definition: newmat.h:433

◆ SortSV() [1/2]

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

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 
)

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