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_zhseqr( char *job, char *compz, lapack_int *n,
00055 lapack_int *ilo, lapack_int *ihi,
00056 lapack_int *ldh, lapack_int *ldz,
00057 lapack_int *lwork );
00058 static void init_h( lapack_int size, lapack_complex_double *h );
00059 static void init_w( lapack_int size, lapack_complex_double *w );
00060 static void init_z( lapack_int size, lapack_complex_double *z );
00061 static void init_work( lapack_int size, lapack_complex_double *work );
00062 static int compare_zhseqr( lapack_complex_double *h, lapack_complex_double *h_i,
00063 lapack_complex_double *w, lapack_complex_double *w_i,
00064 lapack_complex_double *z, lapack_complex_double *z_i,
00065 lapack_int info, lapack_int info_i, char compz,
00066 lapack_int ldh, lapack_int ldz, lapack_int n );
00067
00068 int main(void)
00069 {
00070
00071 char job, job_i;
00072 char compz, compz_i;
00073 lapack_int n, n_i;
00074 lapack_int ilo, ilo_i;
00075 lapack_int ihi, ihi_i;
00076 lapack_int ldh, ldh_i;
00077 lapack_int ldh_r;
00078 lapack_int ldz, ldz_i;
00079 lapack_int ldz_r;
00080 lapack_int lwork, lwork_i;
00081 lapack_int info, info_i;
00082 lapack_int i;
00083 int failed;
00084
00085
00086 lapack_complex_double *h = NULL, *h_i = NULL;
00087 lapack_complex_double *w = NULL, *w_i = NULL;
00088 lapack_complex_double *z = NULL, *z_i = NULL;
00089 lapack_complex_double *work = NULL, *work_i = NULL;
00090 lapack_complex_double *h_save = NULL;
00091 lapack_complex_double *w_save = NULL;
00092 lapack_complex_double *z_save = NULL;
00093 lapack_complex_double *h_r = NULL;
00094 lapack_complex_double *z_r = NULL;
00095
00096
00097 init_scalars_zhseqr( &job, &compz, &n, &ilo, &ihi, &ldh, &ldz, &lwork );
00098 ldh_r = n+2;
00099 ldz_r = n+2;
00100 job_i = job;
00101 compz_i = compz;
00102 n_i = n;
00103 ilo_i = ilo;
00104 ihi_i = ihi;
00105 ldh_i = ldh;
00106 ldz_i = ldz;
00107 lwork_i = lwork;
00108
00109
00110 h = (lapack_complex_double *)
00111 LAPACKE_malloc( ldh*n * sizeof(lapack_complex_double) );
00112 w = (lapack_complex_double *)
00113 LAPACKE_malloc( n * sizeof(lapack_complex_double) );
00114 z = (lapack_complex_double *)
00115 LAPACKE_malloc( ldz*n * sizeof(lapack_complex_double) );
00116 work = (lapack_complex_double *)
00117 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00118
00119
00120 h_i = (lapack_complex_double *)
00121 LAPACKE_malloc( ldh*n * sizeof(lapack_complex_double) );
00122 w_i = (lapack_complex_double *)
00123 LAPACKE_malloc( n * sizeof(lapack_complex_double) );
00124 z_i = (lapack_complex_double *)
00125 LAPACKE_malloc( ldz*n * sizeof(lapack_complex_double) );
00126 work_i = (lapack_complex_double *)
00127 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00128
00129
00130 h_save = (lapack_complex_double *)
00131 LAPACKE_malloc( ldh*n * sizeof(lapack_complex_double) );
00132 w_save = (lapack_complex_double *)
00133 LAPACKE_malloc( n * sizeof(lapack_complex_double) );
00134 z_save = (lapack_complex_double *)
00135 LAPACKE_malloc( ldz*n * sizeof(lapack_complex_double) );
00136
00137
00138 h_r = (lapack_complex_double *)
00139 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00140 z_r = (lapack_complex_double *)
00141 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00142
00143
00144 init_h( ldh*n, h );
00145 init_w( n, w );
00146 init_z( ldz*n, z );
00147 init_work( lwork, work );
00148
00149
00150 for( i = 0; i < ldh*n; i++ ) {
00151 h_save[i] = h[i];
00152 }
00153 for( i = 0; i < n; i++ ) {
00154 w_save[i] = w[i];
00155 }
00156 for( i = 0; i < ldz*n; i++ ) {
00157 z_save[i] = z[i];
00158 }
00159
00160
00161 zhseqr_( &job, &compz, &n, &ilo, &ihi, h, &ldh, w, z, &ldz, work, &lwork,
00162 &info );
00163
00164
00165
00166 for( i = 0; i < ldh*n; i++ ) {
00167 h_i[i] = h_save[i];
00168 }
00169 for( i = 0; i < n; i++ ) {
00170 w_i[i] = w_save[i];
00171 }
00172 for( i = 0; i < ldz*n; i++ ) {
00173 z_i[i] = z_save[i];
00174 }
00175 for( i = 0; i < lwork; i++ ) {
00176 work_i[i] = work[i];
00177 }
00178 info_i = LAPACKE_zhseqr_work( LAPACK_COL_MAJOR, job_i, compz_i, n_i, ilo_i,
00179 ihi_i, h_i, ldh_i, w_i, z_i, ldz_i, work_i,
00180 lwork_i );
00181
00182 failed = compare_zhseqr( h, h_i, w, w_i, z, z_i, info, info_i, compz, ldh,
00183 ldz, n );
00184 if( failed == 0 ) {
00185 printf( "PASSED: column-major middle-level interface to zhseqr\n" );
00186 } else {
00187 printf( "FAILED: column-major middle-level interface to zhseqr\n" );
00188 }
00189
00190
00191
00192 for( i = 0; i < ldh*n; i++ ) {
00193 h_i[i] = h_save[i];
00194 }
00195 for( i = 0; i < n; i++ ) {
00196 w_i[i] = w_save[i];
00197 }
00198 for( i = 0; i < ldz*n; i++ ) {
00199 z_i[i] = z_save[i];
00200 }
00201 for( i = 0; i < lwork; i++ ) {
00202 work_i[i] = work[i];
00203 }
00204 info_i = LAPACKE_zhseqr( LAPACK_COL_MAJOR, job_i, compz_i, n_i, ilo_i,
00205 ihi_i, h_i, ldh_i, w_i, z_i, ldz_i );
00206
00207 failed = compare_zhseqr( h, h_i, w, w_i, z, z_i, info, info_i, compz, ldh,
00208 ldz, n );
00209 if( failed == 0 ) {
00210 printf( "PASSED: column-major high-level interface to zhseqr\n" );
00211 } else {
00212 printf( "FAILED: column-major high-level interface to zhseqr\n" );
00213 }
00214
00215
00216
00217 for( i = 0; i < ldh*n; i++ ) {
00218 h_i[i] = h_save[i];
00219 }
00220 for( i = 0; i < n; i++ ) {
00221 w_i[i] = w_save[i];
00222 }
00223 for( i = 0; i < ldz*n; i++ ) {
00224 z_i[i] = z_save[i];
00225 }
00226 for( i = 0; i < lwork; i++ ) {
00227 work_i[i] = work[i];
00228 }
00229
00230 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, h_i, ldh, h_r, n+2 );
00231 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00232 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00233 }
00234 info_i = LAPACKE_zhseqr_work( LAPACK_ROW_MAJOR, job_i, compz_i, n_i, ilo_i,
00235 ihi_i, h_r, ldh_r, w_i, z_r, ldz_r, work_i,
00236 lwork_i );
00237
00238 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, h_r, n+2, h_i, ldh );
00239 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00240 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00241 }
00242
00243 failed = compare_zhseqr( h, h_i, w, w_i, z, z_i, info, info_i, compz, ldh,
00244 ldz, n );
00245 if( failed == 0 ) {
00246 printf( "PASSED: row-major middle-level interface to zhseqr\n" );
00247 } else {
00248 printf( "FAILED: row-major middle-level interface to zhseqr\n" );
00249 }
00250
00251
00252
00253 for( i = 0; i < ldh*n; i++ ) {
00254 h_i[i] = h_save[i];
00255 }
00256 for( i = 0; i < n; i++ ) {
00257 w_i[i] = w_save[i];
00258 }
00259 for( i = 0; i < ldz*n; i++ ) {
00260 z_i[i] = z_save[i];
00261 }
00262 for( i = 0; i < lwork; i++ ) {
00263 work_i[i] = work[i];
00264 }
00265
00266
00267 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, h_i, ldh, h_r, n+2 );
00268 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00269 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00270 }
00271 info_i = LAPACKE_zhseqr( LAPACK_ROW_MAJOR, job_i, compz_i, n_i, ilo_i,
00272 ihi_i, h_r, ldh_r, w_i, z_r, ldz_r );
00273
00274 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, h_r, n+2, h_i, ldh );
00275 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00276 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00277 }
00278
00279 failed = compare_zhseqr( h, h_i, w, w_i, z, z_i, info, info_i, compz, ldh,
00280 ldz, n );
00281 if( failed == 0 ) {
00282 printf( "PASSED: row-major high-level interface to zhseqr\n" );
00283 } else {
00284 printf( "FAILED: row-major high-level interface to zhseqr\n" );
00285 }
00286
00287
00288 if( h != NULL ) {
00289 LAPACKE_free( h );
00290 }
00291 if( h_i != NULL ) {
00292 LAPACKE_free( h_i );
00293 }
00294 if( h_r != NULL ) {
00295 LAPACKE_free( h_r );
00296 }
00297 if( h_save != NULL ) {
00298 LAPACKE_free( h_save );
00299 }
00300 if( w != NULL ) {
00301 LAPACKE_free( w );
00302 }
00303 if( w_i != NULL ) {
00304 LAPACKE_free( w_i );
00305 }
00306 if( w_save != NULL ) {
00307 LAPACKE_free( w_save );
00308 }
00309 if( z != NULL ) {
00310 LAPACKE_free( z );
00311 }
00312 if( z_i != NULL ) {
00313 LAPACKE_free( z_i );
00314 }
00315 if( z_r != NULL ) {
00316 LAPACKE_free( z_r );
00317 }
00318 if( z_save != NULL ) {
00319 LAPACKE_free( z_save );
00320 }
00321 if( work != NULL ) {
00322 LAPACKE_free( work );
00323 }
00324 if( work_i != NULL ) {
00325 LAPACKE_free( work_i );
00326 }
00327
00328 return 0;
00329 }
00330
00331
00332 static void init_scalars_zhseqr( char *job, char *compz, lapack_int *n,
00333 lapack_int *ilo, lapack_int *ihi,
00334 lapack_int *ldh, lapack_int *ldz,
00335 lapack_int *lwork )
00336 {
00337 *job = 'S';
00338 *compz = 'V';
00339 *n = 4;
00340 *ilo = 2;
00341 *ihi = 3;
00342 *ldh = 8;
00343 *ldz = 8;
00344 *lwork = 512;
00345
00346 return;
00347 }
00348
00349
00350 static void init_h( lapack_int size, lapack_complex_double *h ) {
00351 lapack_int i;
00352 for( i = 0; i < size; i++ ) {
00353 h[i] = lapack_make_complex_double( 0.0, 0.0 );
00354 }
00355 h[0] = lapack_make_complex_double( -1.25000000000000000e+000,
00356 7.50000000000000000e-001 );
00357 h[8] = lapack_make_complex_double( 1.38999999999999990e+000,
00358 3.97000000000000020e+000 );
00359 h[16] = lapack_make_complex_double( 8.28365051039430260e-001,
00360 7.39561433163036420e+000 );
00361 h[24] = lapack_make_complex_double( -2.08999999999999990e+000,
00362 7.55999999999999960e+000 );
00363 h[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00364 0.00000000000000000e+000 );
00365 h[9] = lapack_make_complex_double( -2.50000000000000000e+000,
00366 -5.00000000000000000e-001 );
00367 h[17] = lapack_make_complex_double( 9.01376551729519800e-001,
00368 4.50688275864752350e-003 );
00369 h[25] = lapack_make_complex_double( -8.06000000000000050e+000,
00370 -1.24000000000000000e+000 );
00371 h[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00372 0.00000000000000000e+000 );
00373 h[10] = lapack_make_complex_double( 1.10941425986869310e+000,
00374 0.00000000000000000e+000 );
00375 h[18] = lapack_make_complex_double( -2.50000000000000000e+000,
00376 -5.00000000000000000e-001 );
00377 h[26] = lapack_make_complex_double( -1.05960419162011950e+001,
00378 -4.66480393051061170e+000 );
00379 h[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00380 0.00000000000000000e+000 );
00381 h[11] = lapack_make_complex_double( 0.00000000000000000e+000,
00382 0.00000000000000000e+000 );
00383 h[19] = lapack_make_complex_double( 0.00000000000000000e+000,
00384 0.00000000000000000e+000 );
00385 h[27] = lapack_make_complex_double( 1.50000000000000000e+000,
00386 -2.75000000000000000e+000 );
00387 }
00388 static void init_w( lapack_int size, lapack_complex_double *w ) {
00389 lapack_int i;
00390 for( i = 0; i < size; i++ ) {
00391 w[i] = lapack_make_complex_double( 0.0, 0.0 );
00392 }
00393 }
00394 static void init_z( lapack_int size, lapack_complex_double *z ) {
00395 lapack_int i;
00396 for( i = 0; i < size; i++ ) {
00397 z[i] = lapack_make_complex_double( 0.0, 0.0 );
00398 }
00399 z[0] = lapack_make_complex_double( 1.00000000000000000e+000,
00400 0.00000000000000000e+000 );
00401 z[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00402 0.00000000000000000e+000 );
00403 z[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00404 0.00000000000000000e+000 );
00405 z[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00406 0.00000000000000000e+000 );
00407 z[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00408 0.00000000000000000e+000 );
00409 z[9] = lapack_make_complex_double( 1.00000000000000000e+000,
00410 0.00000000000000000e+000 );
00411 z[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00412 0.00000000000000000e+000 );
00413 z[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00414 0.00000000000000000e+000 );
00415 z[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00416 0.00000000000000000e+000 );
00417 z[10] = lapack_make_complex_double( 0.00000000000000000e+000,
00418 0.00000000000000000e+000 );
00419 z[18] = lapack_make_complex_double( -8.29266427591158320e-001,
00420 -5.58853462072302240e-001 );
00421 z[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00422 0.00000000000000000e+000 );
00423 z[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00424 0.00000000000000000e+000 );
00425 z[11] = lapack_make_complex_double( 0.00000000000000000e+000,
00426 0.00000000000000000e+000 );
00427 z[19] = lapack_make_complex_double( 0.00000000000000000e+000,
00428 0.00000000000000000e+000 );
00429 z[27] = lapack_make_complex_double( 1.00000000000000000e+000,
00430 0.00000000000000000e+000 );
00431 }
00432 static void init_work( lapack_int size, lapack_complex_double *work ) {
00433 lapack_int i;
00434 for( i = 0; i < size; i++ ) {
00435 work[i] = lapack_make_complex_double( 0.0, 0.0 );
00436 }
00437 }
00438
00439
00440
00441 static int compare_zhseqr( lapack_complex_double *h, lapack_complex_double *h_i,
00442 lapack_complex_double *w, lapack_complex_double *w_i,
00443 lapack_complex_double *z, lapack_complex_double *z_i,
00444 lapack_int info, lapack_int info_i, char compz,
00445 lapack_int ldh, lapack_int ldz, lapack_int n )
00446 {
00447 lapack_int i;
00448 int failed = 0;
00449 for( i = 0; i < ldh*n; i++ ) {
00450 failed += compare_complex_doubles(h[i],h_i[i]);
00451 }
00452 for( i = 0; i < n; i++ ) {
00453 failed += compare_complex_doubles(w[i],w_i[i]);
00454 }
00455 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00456 for( i = 0; i < ldz*n; i++ ) {
00457 failed += compare_complex_doubles(z[i],z_i[i]);
00458 }
00459 }
00460 failed += (info == info_i) ? 0 : 1;
00461 if( info != 0 || info_i != 0 ) {
00462 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00463 }
00464
00465 return failed;
00466 }