template_lapack_lasrt.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef TEMPLATE_LAPACK_LASRT_HEADER
00036 #define TEMPLATE_LAPACK_LASRT_HEADER
00037
00038
00039 template<class Treal>
00040 int template_lapack_lasrt(const char *id, const integer *n, Treal *d__, integer *
00041 info)
00042 {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 integer i__1, i__2;
00086
00087 integer endd, i__, j;
00088 integer stack[64] ;
00089 Treal dmnmx, d1, d2, d3;
00090 integer start;
00091 integer stkpnt, dir;
00092 Treal tmp;
00093 #define stack_ref(a_1,a_2) stack[(a_2)*2 + a_1 - 3]
00094
00095 --d__;
00096
00097
00098 *info = 0;
00099 dir = -1;
00100 if (template_blas_lsame(id, "D")) {
00101 dir = 0;
00102 } else if (template_blas_lsame(id, "I")) {
00103 dir = 1;
00104 }
00105 if (dir == -1) {
00106 *info = -1;
00107 } else if (*n < 0) {
00108 *info = -2;
00109 }
00110 if (*info != 0) {
00111 i__1 = -(*info);
00112 template_blas_erbla("LASRT ", &i__1);
00113 return 0;
00114 }
00115
00116
00117
00118 if (*n <= 1) {
00119 return 0;
00120 }
00121
00122 stkpnt = 1;
00123 stack_ref(1, 1) = 1;
00124 stack_ref(2, 1) = *n;
00125 L10:
00126 start = stack_ref(1, stkpnt);
00127 endd = stack_ref(2, stkpnt);
00128 --stkpnt;
00129 if (endd - start <= 20 && endd - start > 0) {
00130
00131
00132
00133 if (dir == 0) {
00134
00135
00136
00137 i__1 = endd;
00138 for (i__ = start + 1; i__ <= i__1; ++i__) {
00139 i__2 = start + 1;
00140 for (j = i__; j >= i__2; --j) {
00141 if (d__[j] > d__[j - 1]) {
00142 dmnmx = d__[j];
00143 d__[j] = d__[j - 1];
00144 d__[j - 1] = dmnmx;
00145 } else {
00146 goto L30;
00147 }
00148
00149 }
00150 L30:
00151 ;
00152 }
00153
00154 } else {
00155
00156
00157
00158 i__1 = endd;
00159 for (i__ = start + 1; i__ <= i__1; ++i__) {
00160 i__2 = start + 1;
00161 for (j = i__; j >= i__2; --j) {
00162 if (d__[j] < d__[j - 1]) {
00163 dmnmx = d__[j];
00164 d__[j] = d__[j - 1];
00165 d__[j - 1] = dmnmx;
00166 } else {
00167 goto L50;
00168 }
00169
00170 }
00171 L50:
00172 ;
00173 }
00174
00175 }
00176
00177 } else if (endd - start > 20) {
00178
00179
00180
00181
00182
00183 d1 = d__[start];
00184 d2 = d__[endd];
00185 i__ = (start + endd) / 2;
00186 d3 = d__[i__];
00187 if (d1 < d2) {
00188 if (d3 < d1) {
00189 dmnmx = d1;
00190 } else if (d3 < d2) {
00191 dmnmx = d3;
00192 } else {
00193 dmnmx = d2;
00194 }
00195 } else {
00196 if (d3 < d2) {
00197 dmnmx = d2;
00198 } else if (d3 < d1) {
00199 dmnmx = d3;
00200 } else {
00201 dmnmx = d1;
00202 }
00203 }
00204
00205 if (dir == 0) {
00206
00207
00208
00209 i__ = start - 1;
00210 j = endd + 1;
00211 L60:
00212 L70:
00213 --j;
00214 if (d__[j] < dmnmx) {
00215 goto L70;
00216 }
00217 L80:
00218 ++i__;
00219 if (d__[i__] > dmnmx) {
00220 goto L80;
00221 }
00222 if (i__ < j) {
00223 tmp = d__[i__];
00224 d__[i__] = d__[j];
00225 d__[j] = tmp;
00226 goto L60;
00227 }
00228 if (j - start > endd - j - 1) {
00229 ++stkpnt;
00230 stack_ref(1, stkpnt) = start;
00231 stack_ref(2, stkpnt) = j;
00232 ++stkpnt;
00233 stack_ref(1, stkpnt) = j + 1;
00234 stack_ref(2, stkpnt) = endd;
00235 } else {
00236 ++stkpnt;
00237 stack_ref(1, stkpnt) = j + 1;
00238 stack_ref(2, stkpnt) = endd;
00239 ++stkpnt;
00240 stack_ref(1, stkpnt) = start;
00241 stack_ref(2, stkpnt) = j;
00242 }
00243 } else {
00244
00245
00246
00247 i__ = start - 1;
00248 j = endd + 1;
00249 L90:
00250 L100:
00251 --j;
00252 if (d__[j] > dmnmx) {
00253 goto L100;
00254 }
00255 L110:
00256 ++i__;
00257 if (d__[i__] < dmnmx) {
00258 goto L110;
00259 }
00260 if (i__ < j) {
00261 tmp = d__[i__];
00262 d__[i__] = d__[j];
00263 d__[j] = tmp;
00264 goto L90;
00265 }
00266 if (j - start > endd - j - 1) {
00267 ++stkpnt;
00268 stack_ref(1, stkpnt) = start;
00269 stack_ref(2, stkpnt) = j;
00270 ++stkpnt;
00271 stack_ref(1, stkpnt) = j + 1;
00272 stack_ref(2, stkpnt) = endd;
00273 } else {
00274 ++stkpnt;
00275 stack_ref(1, stkpnt) = j + 1;
00276 stack_ref(2, stkpnt) = endd;
00277 ++stkpnt;
00278 stack_ref(1, stkpnt) = start;
00279 stack_ref(2, stkpnt) = j;
00280 }
00281 }
00282 }
00283 if (stkpnt > 0) {
00284 goto L10;
00285 }
00286 return 0;
00287
00288
00289
00290 }
00291
00292 #undef stack_ref
00293
00294
00295 #endif