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_zsteqr( 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, lapack_complex_double *z );
00058 static void init_work( lapack_int size, double *work );
00059 static int compare_zsteqr( double *d, double *d_i, double *e, double *e_i,
00060 lapack_complex_double *z, lapack_complex_double *z_i,
00061 lapack_int info, lapack_int info_i, char compz,
00062 lapack_int ldz, 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 lapack_complex_double *z = NULL, *z_i = NULL;
00079 double *work = NULL, *work_i = NULL;
00080 double *d_save = NULL;
00081 double *e_save = NULL;
00082 lapack_complex_double *z_save = NULL;
00083 lapack_complex_double *z_r = NULL;
00084
00085
00086 init_scalars_zsteqr( &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 = (lapack_complex_double *)
00096 LAPACKE_malloc( ldz*n * sizeof(lapack_complex_double) );
00097 work = (double *)LAPACKE_malloc( ((MAX(1,2*n-2))) * sizeof(double) );
00098
00099
00100 d_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00101 e_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00102 z_i = (lapack_complex_double *)
00103 LAPACKE_malloc( ldz*n * sizeof(lapack_complex_double) );
00104 work_i = (double *)LAPACKE_malloc( ((MAX(1,2*n-2))) * sizeof(double) );
00105
00106
00107 d_save = (double *)LAPACKE_malloc( n * sizeof(double) );
00108 e_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00109 z_save = (lapack_complex_double *)
00110 LAPACKE_malloc( ldz*n * sizeof(lapack_complex_double) );
00111
00112
00113 z_r = (lapack_complex_double *)
00114 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00115
00116
00117 init_d( n, d );
00118 init_e( (n-1), e );
00119 init_z( ldz*n, z );
00120 init_work( (MAX(1,2*n-2)), work );
00121
00122
00123 for( i = 0; i < n; i++ ) {
00124 d_save[i] = d[i];
00125 }
00126 for( i = 0; i < (n-1); i++ ) {
00127 e_save[i] = e[i];
00128 }
00129 for( i = 0; i < ldz*n; i++ ) {
00130 z_save[i] = z[i];
00131 }
00132
00133
00134 zsteqr_( &compz, &n, d, e, z, &ldz, work, &info );
00135
00136
00137
00138 for( i = 0; i < n; i++ ) {
00139 d_i[i] = d_save[i];
00140 }
00141 for( i = 0; i < (n-1); i++ ) {
00142 e_i[i] = e_save[i];
00143 }
00144 for( i = 0; i < ldz*n; i++ ) {
00145 z_i[i] = z_save[i];
00146 }
00147 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00148 work_i[i] = work[i];
00149 }
00150 info_i = LAPACKE_zsteqr_work( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00151 ldz_i, work_i );
00152
00153 failed = compare_zsteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00154 n );
00155 if( failed == 0 ) {
00156 printf( "PASSED: column-major middle-level interface to zsteqr\n" );
00157 } else {
00158 printf( "FAILED: column-major middle-level interface to zsteqr\n" );
00159 }
00160
00161
00162
00163 for( i = 0; i < n; i++ ) {
00164 d_i[i] = d_save[i];
00165 }
00166 for( i = 0; i < (n-1); i++ ) {
00167 e_i[i] = e_save[i];
00168 }
00169 for( i = 0; i < ldz*n; i++ ) {
00170 z_i[i] = z_save[i];
00171 }
00172 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00173 work_i[i] = work[i];
00174 }
00175 info_i = LAPACKE_zsteqr( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00176 ldz_i );
00177
00178 failed = compare_zsteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00179 n );
00180 if( failed == 0 ) {
00181 printf( "PASSED: column-major high-level interface to zsteqr\n" );
00182 } else {
00183 printf( "FAILED: column-major high-level interface to zsteqr\n" );
00184 }
00185
00186
00187
00188 for( i = 0; i < n; i++ ) {
00189 d_i[i] = d_save[i];
00190 }
00191 for( i = 0; i < (n-1); i++ ) {
00192 e_i[i] = e_save[i];
00193 }
00194 for( i = 0; i < ldz*n; i++ ) {
00195 z_i[i] = z_save[i];
00196 }
00197 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00198 work_i[i] = work[i];
00199 }
00200
00201 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00202 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00203 }
00204 info_i = LAPACKE_zsteqr_work( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00205 ldz_r, work_i );
00206
00207 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00208 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00209 }
00210
00211 failed = compare_zsteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00212 n );
00213 if( failed == 0 ) {
00214 printf( "PASSED: row-major middle-level interface to zsteqr\n" );
00215 } else {
00216 printf( "FAILED: row-major middle-level interface to zsteqr\n" );
00217 }
00218
00219
00220
00221 for( i = 0; i < n; i++ ) {
00222 d_i[i] = d_save[i];
00223 }
00224 for( i = 0; i < (n-1); i++ ) {
00225 e_i[i] = e_save[i];
00226 }
00227 for( i = 0; i < ldz*n; i++ ) {
00228 z_i[i] = z_save[i];
00229 }
00230 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00231 work_i[i] = work[i];
00232 }
00233
00234
00235 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00236 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00237 }
00238 info_i = LAPACKE_zsteqr( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00239 ldz_r );
00240
00241 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00242 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00243 }
00244
00245 failed = compare_zsteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00246 n );
00247 if( failed == 0 ) {
00248 printf( "PASSED: row-major high-level interface to zsteqr\n" );
00249 } else {
00250 printf( "FAILED: row-major high-level interface to zsteqr\n" );
00251 }
00252
00253
00254 if( d != NULL ) {
00255 LAPACKE_free( d );
00256 }
00257 if( d_i != NULL ) {
00258 LAPACKE_free( d_i );
00259 }
00260 if( d_save != NULL ) {
00261 LAPACKE_free( d_save );
00262 }
00263 if( e != NULL ) {
00264 LAPACKE_free( e );
00265 }
00266 if( e_i != NULL ) {
00267 LAPACKE_free( e_i );
00268 }
00269 if( e_save != NULL ) {
00270 LAPACKE_free( e_save );
00271 }
00272 if( z != NULL ) {
00273 LAPACKE_free( z );
00274 }
00275 if( z_i != NULL ) {
00276 LAPACKE_free( z_i );
00277 }
00278 if( z_r != NULL ) {
00279 LAPACKE_free( z_r );
00280 }
00281 if( z_save != NULL ) {
00282 LAPACKE_free( z_save );
00283 }
00284 if( work != NULL ) {
00285 LAPACKE_free( work );
00286 }
00287 if( work_i != NULL ) {
00288 LAPACKE_free( work_i );
00289 }
00290
00291 return 0;
00292 }
00293
00294
00295 static void init_scalars_zsteqr( char *compz, lapack_int *n, lapack_int *ldz )
00296 {
00297 *compz = 'V';
00298 *n = 4;
00299 *ldz = 8;
00300
00301 return;
00302 }
00303
00304
00305 static void init_d( lapack_int size, double *d ) {
00306 lapack_int i;
00307 for( i = 0; i < size; i++ ) {
00308 d[i] = 0;
00309 }
00310 d[0] = -2.27999999999999980e+000;
00311 d[1] = -1.28456981649329280e-001;
00312 d[2] = -1.66593253752407190e-001;
00313 d[3] = -1.92494976459826360e+000;
00314 }
00315 static void init_e( lapack_int size, double *e ) {
00316 lapack_int i;
00317 for( i = 0; i < size; i++ ) {
00318 e[i] = 0;
00319 }
00320 e[0] = -4.33845594653212970e+000;
00321 e[1] = -2.02259457862261720e+000;
00322 e[2] = -1.80232297833873440e+000;
00323 }
00324 static void init_z( lapack_int size, lapack_complex_double *z ) {
00325 lapack_int i;
00326 for( i = 0; i < size; i++ ) {
00327 z[i] = lapack_make_complex_double( 0.0, 0.0 );
00328 }
00329 z[0] = lapack_make_complex_double( 1.00000000000000000e+000,
00330 0.00000000000000000e+000 );
00331 z[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00332 0.00000000000000000e+000 );
00333 z[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00334 0.00000000000000000e+000 );
00335 z[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00336 0.00000000000000000e+000 );
00337 z[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00338 0.00000000000000000e+000 );
00339 z[9] = lapack_make_complex_double( -4.10284216766753750e-001,
00340 -4.67908404514893240e-001 );
00341 z[17] = lapack_make_complex_double( 6.89296566406100150e-002,
00342 1.77991886191011440e-001 );
00343 z[25] = lapack_make_complex_double( 6.58292153470164230e-001,
00344 3.78084141457435350e-001 );
00345 z[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00346 0.00000000000000000e+000 );
00347 z[10] = lapack_make_complex_double( -5.20922657243181650e-001,
00348 2.30496750992558170e-002 );
00349 z[18] = lapack_make_complex_double( -2.57550236384426260e-001,
00350 -7.35600192599404460e-001 );
00351 z[26] = lapack_make_complex_double( -2.31282326855171080e-001,
00352 2.59185291478942760e-001 );
00353 z[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00354 0.00000000000000000e+000 );
00355 z[11] = lapack_make_complex_double( 2.76596101191070030e-002,
00356 5.83156780011172330e-001 );
00357 z[19] = lapack_make_complex_double( 5.95558108062965720e-001,
00358 -3.79257589519287130e-002 );
00359 z[27] = lapack_make_complex_double( 6.57306482539318500e-002,
00360 5.46548053242859160e-001 );
00361 }
00362 static void init_work( lapack_int size, double *work ) {
00363 lapack_int i;
00364 for( i = 0; i < size; i++ ) {
00365 work[i] = 0;
00366 }
00367 }
00368
00369
00370
00371 static int compare_zsteqr( double *d, double *d_i, double *e, double *e_i,
00372 lapack_complex_double *z, lapack_complex_double *z_i,
00373 lapack_int info, lapack_int info_i, char compz,
00374 lapack_int ldz, lapack_int n )
00375 {
00376 lapack_int i;
00377 int failed = 0;
00378 for( i = 0; i < n; i++ ) {
00379 failed += compare_doubles(d[i],d_i[i]);
00380 }
00381 for( i = 0; i < (n-1); i++ ) {
00382 failed += compare_doubles(e[i],e_i[i]);
00383 }
00384 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00385 for( i = 0; i < ldz*n; i++ ) {
00386 failed += compare_complex_doubles(z[i],z_i[i]);
00387 }
00388 }
00389 failed += (info == info_i) ? 0 : 1;
00390 if( info != 0 || info_i != 0 ) {
00391 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00392 }
00393
00394 return failed;
00395 }