20 #define REPORT { static ExeCounter ExeCount(__LINE__,13); ++ExeCount; } 36 #define DoSimpleSort 17 // when to switch to insert sort 37 #define MaxDepth 50 // maximum recursion depth 52 Tracer et(
"sort_descending");
66 if (*b >= *c) {
REPORT return *b; }
67 else if (*a >= *c) {
REPORT Real x = *c; *c = *b; *b = x;
return x; }
68 else {
REPORT Real x = *
a; *a = *c; *c = *b; *b = x;
return x; }
70 else if (*c >= *b) {
REPORT Real x = *c; *c = *
a; *a = x;
return *b; }
71 else if (*a >= *c) {
REPORT Real x = *
a; *a = *b; *b = x;
return x; }
72 else {
REPORT Real x = *c; *c = *
a; *a = *b; *b = x;
return x; }
81 if (length <= 1)
return;
85 if (guard > length) {
REPORT guard = length; }
87 while (i--)
if (v < *(++f)) { v = *f; h = f; }
88 *h = *first; *first = v;
91 i = length - 1; f = first;
94 Real* g = f++; h = f; v = *h;
95 while (*g < v) *h-- = *g--;
105 const int length = last - first + 1;
109 Real* centre = first + length/2;
114 while (*(++f) > test) {}
115 while (*(--l) < test) {}
117 const Real temp = *f; *f = *l; *l = temp;
128 Tracer et(
"sort_ascending");
143 if (length <= 1)
return;
147 if (guard > length) {
REPORT guard = length; }
149 while (i--)
if (v > *(++f)) { v = *f; h = f; }
150 *h = *first; *first = v;
153 i = length - 1; f = first;
156 Real* g = f++; h = f; v = *h;
157 while (*g > v) *h-- = *g--;
166 const int length = last - first + 1;
170 Real* centre = first + length/2;
175 while (*(++f) < test) {}
176 while (*(--l) > test) {}
178 const Real temp = *f; *f = *l; *l = temp;
201 for (
int i=0; i<n; i++)
206 for (
int j=i+1; j<n; j++)
211 for (
int j=i+1; j<n; j++)
217 Real* uji = u + i;
Real* ujk = u + k;
220 p = *uji; *uji = *ujk; *ujk = p;
236 for (
int i=0; i<n; i++)
241 for (
int j=i+1; j<n; j++)
246 for (
int j=i+1; j<n; j++)
252 Real* uji = u + i;
Real* ujk = u + k;
253 Real* vji = v + i;
Real* vjk = v + k;
257 p = *uji; *uji = *ujk; *ujk = p;
if (!(--j))
break;
263 p = *vji; *vji = *vjk; *vjk = p;
if (!(--j))
break;
static void MyQuickSortDescending(Real *first, Real *last, int depth)
void sort_ascending(GeneralMatrix &GM)
static void InsertionSortAscending(Real *first, const int length, int guard)
The usual rectangular matrix.
Incompatible dimensions exception.
FloatVector FloatVector * a
Real trace(const BaseMatrix &B)
void SortSV(DiagonalMatrix &D, Matrix &U, bool ascending)
Covergence failure exception.
static void InsertionSortDescending(Real *first, const int length, int guard)
void sort_descending(GeneralMatrix &GM)
The classes for matrices that can contain data are derived from this.
static Real SortThreeDescending(Real *a, Real *b, Real *c)
static void MyQuickSortAscending(Real *first, Real *last, int depth)