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
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include <stdio.h>
00050 #include "lapacke.h"
00051 #include "lapacke_utils.h"
00052 #include "test_utils.h"
00053
00054 static void init_scalars_dsteqr( char *compz, lapack_int *n, lapack_int *ldz );
00055 static void init_d( lapack_int size, double *d );
00056 static void init_e( lapack_int size, double *e );
00057 static void init_z( lapack_int size, double *z );
00058 static void init_work( lapack_int size, double *work );
00059 static int compare_dsteqr( double *d, double *d_i, double *e, double *e_i,
00060 double *z, double *z_i, lapack_int info,
00061 lapack_int info_i, char compz, lapack_int ldz,
00062 lapack_int n );
00063
00064 int main(void)
00065 {
00066
00067 char compz, compz_i;
00068 lapack_int n, n_i;
00069 lapack_int ldz, ldz_i;
00070 lapack_int ldz_r;
00071 lapack_int info, info_i;
00072 lapack_int i;
00073 int failed;
00074
00075
00076 double *d = NULL, *d_i = NULL;
00077 double *e = NULL, *e_i = NULL;
00078 double *z = NULL, *z_i = NULL;
00079 double *work = NULL, *work_i = NULL;
00080 double *d_save = NULL;
00081 double *e_save = NULL;
00082 double *z_save = NULL;
00083 double *z_r = NULL;
00084
00085
00086 init_scalars_dsteqr( &compz, &n, &ldz );
00087 ldz_r = n+2;
00088 compz_i = compz;
00089 n_i = n;
00090 ldz_i = ldz;
00091
00092
00093 d = (double *)LAPACKE_malloc( n * sizeof(double) );
00094 e = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00095 z = (double *)LAPACKE_malloc( ldz*n * sizeof(double) );
00096 work = (double *)LAPACKE_malloc( ((MAX(1,2*n-2))) * sizeof(double) );
00097
00098
00099 d_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00100 e_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00101 z_i = (double *)LAPACKE_malloc( ldz*n * sizeof(double) );
00102 work_i = (double *)LAPACKE_malloc( ((MAX(1,2*n-2))) * sizeof(double) );
00103
00104
00105 d_save = (double *)LAPACKE_malloc( n * sizeof(double) );
00106 e_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00107 z_save = (double *)LAPACKE_malloc( ldz*n * sizeof(double) );
00108
00109
00110 z_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) );
00111
00112
00113 init_d( n, d );
00114 init_e( (n-1), e );
00115 init_z( ldz*n, z );
00116 init_work( (MAX(1,2*n-2)), work );
00117
00118
00119 for( i = 0; i < n; i++ ) {
00120 d_save[i] = d[i];
00121 }
00122 for( i = 0; i < (n-1); i++ ) {
00123 e_save[i] = e[i];
00124 }
00125 for( i = 0; i < ldz*n; i++ ) {
00126 z_save[i] = z[i];
00127 }
00128
00129
00130 dsteqr_( &compz, &n, d, e, z, &ldz, work, &info );
00131
00132
00133
00134 for( i = 0; i < n; i++ ) {
00135 d_i[i] = d_save[i];
00136 }
00137 for( i = 0; i < (n-1); i++ ) {
00138 e_i[i] = e_save[i];
00139 }
00140 for( i = 0; i < ldz*n; i++ ) {
00141 z_i[i] = z_save[i];
00142 }
00143 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00144 work_i[i] = work[i];
00145 }
00146 info_i = LAPACKE_dsteqr_work( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00147 ldz_i, work_i );
00148
00149 failed = compare_dsteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00150 n );
00151 if( failed == 0 ) {
00152 printf( "PASSED: column-major middle-level interface to dsteqr\n" );
00153 } else {
00154 printf( "FAILED: column-major middle-level interface to dsteqr\n" );
00155 }
00156
00157
00158
00159 for( i = 0; i < n; i++ ) {
00160 d_i[i] = d_save[i];
00161 }
00162 for( i = 0; i < (n-1); i++ ) {
00163 e_i[i] = e_save[i];
00164 }
00165 for( i = 0; i < ldz*n; i++ ) {
00166 z_i[i] = z_save[i];
00167 }
00168 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00169 work_i[i] = work[i];
00170 }
00171 info_i = LAPACKE_dsteqr( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00172 ldz_i );
00173
00174 failed = compare_dsteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00175 n );
00176 if( failed == 0 ) {
00177 printf( "PASSED: column-major high-level interface to dsteqr\n" );
00178 } else {
00179 printf( "FAILED: column-major high-level interface to dsteqr\n" );
00180 }
00181
00182
00183
00184 for( i = 0; i < n; i++ ) {
00185 d_i[i] = d_save[i];
00186 }
00187 for( i = 0; i < (n-1); i++ ) {
00188 e_i[i] = e_save[i];
00189 }
00190 for( i = 0; i < ldz*n; i++ ) {
00191 z_i[i] = z_save[i];
00192 }
00193 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00194 work_i[i] = work[i];
00195 }
00196
00197 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00198 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00199 }
00200 info_i = LAPACKE_dsteqr_work( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00201 ldz_r, work_i );
00202
00203 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00204 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00205 }
00206
00207 failed = compare_dsteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00208 n );
00209 if( failed == 0 ) {
00210 printf( "PASSED: row-major middle-level interface to dsteqr\n" );
00211 } else {
00212 printf( "FAILED: row-major middle-level interface to dsteqr\n" );
00213 }
00214
00215
00216
00217 for( i = 0; i < n; i++ ) {
00218 d_i[i] = d_save[i];
00219 }
00220 for( i = 0; i < (n-1); i++ ) {
00221 e_i[i] = e_save[i];
00222 }
00223 for( i = 0; i < ldz*n; i++ ) {
00224 z_i[i] = z_save[i];
00225 }
00226 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00227 work_i[i] = work[i];
00228 }
00229
00230
00231 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00232 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00233 }
00234 info_i = LAPACKE_dsteqr( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00235 ldz_r );
00236
00237 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00238 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00239 }
00240
00241 failed = compare_dsteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00242 n );
00243 if( failed == 0 ) {
00244 printf( "PASSED: row-major high-level interface to dsteqr\n" );
00245 } else {
00246 printf( "FAILED: row-major high-level interface to dsteqr\n" );
00247 }
00248
00249
00250 if( d != NULL ) {
00251 LAPACKE_free( d );
00252 }
00253 if( d_i != NULL ) {
00254 LAPACKE_free( d_i );
00255 }
00256 if( d_save != NULL ) {
00257 LAPACKE_free( d_save );
00258 }
00259 if( e != NULL ) {
00260 LAPACKE_free( e );
00261 }
00262 if( e_i != NULL ) {
00263 LAPACKE_free( e_i );
00264 }
00265 if( e_save != NULL ) {
00266 LAPACKE_free( e_save );
00267 }
00268 if( z != NULL ) {
00269 LAPACKE_free( z );
00270 }
00271 if( z_i != NULL ) {
00272 LAPACKE_free( z_i );
00273 }
00274 if( z_r != NULL ) {
00275 LAPACKE_free( z_r );
00276 }
00277 if( z_save != NULL ) {
00278 LAPACKE_free( z_save );
00279 }
00280 if( work != NULL ) {
00281 LAPACKE_free( work );
00282 }
00283 if( work_i != NULL ) {
00284 LAPACKE_free( work_i );
00285 }
00286
00287 return 0;
00288 }
00289
00290
00291 static void init_scalars_dsteqr( char *compz, lapack_int *n, lapack_int *ldz )
00292 {
00293 *compz = 'V';
00294 *n = 4;
00295 *ldz = 8;
00296
00297 return;
00298 }
00299
00300
00301 static void init_d( lapack_int size, double *d ) {
00302 lapack_int i;
00303 for( i = 0; i < size; i++ ) {
00304 d[i] = 0;
00305 }
00306 d[0] = 4.99000000000000020e+000;
00307 d[1] = -2.48056000000000050e+000;
00308 d[2] = -6.61138379556598650e-002;
00309 d[3] = 8.56673837955660430e-001;
00310 }
00311 static void init_e( lapack_int size, double *e ) {
00312 lapack_int i;
00313 for( i = 0; i < size; i++ ) {
00314 e[i] = 0;
00315 }
00316 e[0] = 2.23606797749978960e-001;
00317 e[1] = 1.10297546953683430e+000;
00318 e[2] = 1.43009636203178530e+000;
00319 }
00320 static void init_z( lapack_int size, double *z ) {
00321 lapack_int i;
00322 for( i = 0; i < size; i++ ) {
00323 z[i] = 0;
00324 }
00325 z[0] = 1.00000000000000000e+000;
00326 z[8] = 0.00000000000000000e+000;
00327 z[16] = 0.00000000000000000e+000;
00328 z[24] = 0.00000000000000000e+000;
00329 z[1] = 0.00000000000000000e+000;
00330 z[9] = 1.78885438199983180e-001;
00331 z[17] = -1.32089480057769240e-001;
00332 z[25] = -9.74962752754210740e-001;
00333 z[2] = 0.00000000000000000e+000;
00334 z[10] = 9.83869910099907540e-001;
00335 z[18] = 2.40162691014125900e-002;
00336 z[26] = 1.77265955046220110e-001;
00337 z[3] = 0.00000000000000000e+000;
00338 z[11] = 0.00000000000000000e+000;
00339 z[19] = -9.90946813949425190e-001;
00340 z[27] = 1.34255025691715850e-001;
00341 }
00342 static void init_work( lapack_int size, double *work ) {
00343 lapack_int i;
00344 for( i = 0; i < size; i++ ) {
00345 work[i] = 0;
00346 }
00347 }
00348
00349
00350
00351 static int compare_dsteqr( double *d, double *d_i, double *e, double *e_i,
00352 double *z, double *z_i, lapack_int info,
00353 lapack_int info_i, char compz, lapack_int ldz,
00354 lapack_int n )
00355 {
00356 lapack_int i;
00357 int failed = 0;
00358 for( i = 0; i < n; i++ ) {
00359 failed += compare_doubles(d[i],d_i[i]);
00360 }
00361 for( i = 0; i < (n-1); i++ ) {
00362 failed += compare_doubles(e[i],e_i[i]);
00363 }
00364 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00365 for( i = 0; i < ldz*n; i++ ) {
00366 failed += compare_doubles(z[i],z_i[i]);
00367 }
00368 }
00369 failed += (info == info_i) ? 0 : 1;
00370 if( info != 0 || info_i != 0 ) {
00371 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00372 }
00373
00374 return failed;
00375 }