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_zgebrd( lapack_int *m, lapack_int *n, lapack_int *lda,
00055 lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_double *a );
00057 static void init_d( lapack_int size, double *d );
00058 static void init_e( lapack_int size, double *e );
00059 static void init_tauq( lapack_int size, lapack_complex_double *tauq );
00060 static void init_taup( lapack_int size, lapack_complex_double *taup );
00061 static void init_work( lapack_int size, lapack_complex_double *work );
00062 static int compare_zgebrd( lapack_complex_double *a, lapack_complex_double *a_i,
00063 double *d, double *d_i, double *e, double *e_i,
00064 lapack_complex_double *tauq,
00065 lapack_complex_double *tauq_i,
00066 lapack_complex_double *taup,
00067 lapack_complex_double *taup_i, lapack_int info,
00068 lapack_int info_i, lapack_int lda, lapack_int m,
00069 lapack_int n );
00070
00071 int main(void)
00072 {
00073
00074 lapack_int m, m_i;
00075 lapack_int n, n_i;
00076 lapack_int lda, lda_i;
00077 lapack_int lda_r;
00078 lapack_int lwork, lwork_i;
00079 lapack_int info, info_i;
00080 lapack_int i;
00081 int failed;
00082
00083
00084 lapack_complex_double *a = NULL, *a_i = NULL;
00085 double *d = NULL, *d_i = NULL;
00086 double *e = NULL, *e_i = NULL;
00087 lapack_complex_double *tauq = NULL, *tauq_i = NULL;
00088 lapack_complex_double *taup = NULL, *taup_i = NULL;
00089 lapack_complex_double *work = NULL, *work_i = NULL;
00090 lapack_complex_double *a_save = NULL;
00091 double *d_save = NULL;
00092 double *e_save = NULL;
00093 lapack_complex_double *tauq_save = NULL;
00094 lapack_complex_double *taup_save = NULL;
00095 lapack_complex_double *a_r = NULL;
00096
00097
00098 init_scalars_zgebrd( &m, &n, &lda, &lwork );
00099 lda_r = n+2;
00100 m_i = m;
00101 n_i = n;
00102 lda_i = lda;
00103 lwork_i = lwork;
00104
00105
00106 a = (lapack_complex_double *)
00107 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00108 d = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00109 e = (double *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(double) );
00110 tauq = (lapack_complex_double *)
00111 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00112 taup = (lapack_complex_double *)
00113 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00114 work = (lapack_complex_double *)
00115 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00116
00117
00118 a_i = (lapack_complex_double *)
00119 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00120 d_i = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00121 e_i = (double *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(double) );
00122 tauq_i = (lapack_complex_double *)
00123 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00124 taup_i = (lapack_complex_double *)
00125 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00126 work_i = (lapack_complex_double *)
00127 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00128
00129
00130 a_save = (lapack_complex_double *)
00131 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00132 d_save = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00133 e_save = (double *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(double) );
00134 tauq_save = (lapack_complex_double *)
00135 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00136 taup_save = (lapack_complex_double *)
00137 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_double) );
00138
00139
00140 a_r = (lapack_complex_double *)
00141 LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_double) );
00142
00143
00144 init_a( lda*n, a );
00145 init_d( (MIN(m,n)), d );
00146 init_e( (MIN(m,n)-1), e );
00147 init_tauq( (MIN(m,n)), tauq );
00148 init_taup( (MIN(m,n)), taup );
00149 init_work( lwork, work );
00150
00151
00152 for( i = 0; i < lda*n; i++ ) {
00153 a_save[i] = a[i];
00154 }
00155 for( i = 0; i < (MIN(m,n)); i++ ) {
00156 d_save[i] = d[i];
00157 }
00158 for( i = 0; i < (MIN(m,n)-1); i++ ) {
00159 e_save[i] = e[i];
00160 }
00161 for( i = 0; i < (MIN(m,n)); i++ ) {
00162 tauq_save[i] = tauq[i];
00163 }
00164 for( i = 0; i < (MIN(m,n)); i++ ) {
00165 taup_save[i] = taup[i];
00166 }
00167
00168
00169 zgebrd_( &m, &n, a, &lda, d, e, tauq, taup, work, &lwork, &info );
00170
00171
00172
00173 for( i = 0; i < lda*n; i++ ) {
00174 a_i[i] = a_save[i];
00175 }
00176 for( i = 0; i < (MIN(m,n)); i++ ) {
00177 d_i[i] = d_save[i];
00178 }
00179 for( i = 0; i < (MIN(m,n)-1); i++ ) {
00180 e_i[i] = e_save[i];
00181 }
00182 for( i = 0; i < (MIN(m,n)); i++ ) {
00183 tauq_i[i] = tauq_save[i];
00184 }
00185 for( i = 0; i < (MIN(m,n)); i++ ) {
00186 taup_i[i] = taup_save[i];
00187 }
00188 for( i = 0; i < lwork; i++ ) {
00189 work_i[i] = work[i];
00190 }
00191 info_i = LAPACKE_zgebrd_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, d_i,
00192 e_i, tauq_i, taup_i, work_i, lwork_i );
00193
00194 failed = compare_zgebrd( a, a_i, d, d_i, e, e_i, tauq, tauq_i, taup, taup_i,
00195 info, info_i, lda, m, n );
00196 if( failed == 0 ) {
00197 printf( "PASSED: column-major middle-level interface to zgebrd\n" );
00198 } else {
00199 printf( "FAILED: column-major middle-level interface to zgebrd\n" );
00200 }
00201
00202
00203
00204 for( i = 0; i < lda*n; i++ ) {
00205 a_i[i] = a_save[i];
00206 }
00207 for( i = 0; i < (MIN(m,n)); i++ ) {
00208 d_i[i] = d_save[i];
00209 }
00210 for( i = 0; i < (MIN(m,n)-1); i++ ) {
00211 e_i[i] = e_save[i];
00212 }
00213 for( i = 0; i < (MIN(m,n)); i++ ) {
00214 tauq_i[i] = tauq_save[i];
00215 }
00216 for( i = 0; i < (MIN(m,n)); i++ ) {
00217 taup_i[i] = taup_save[i];
00218 }
00219 for( i = 0; i < lwork; i++ ) {
00220 work_i[i] = work[i];
00221 }
00222 info_i = LAPACKE_zgebrd( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, d_i, e_i,
00223 tauq_i, taup_i );
00224
00225 failed = compare_zgebrd( a, a_i, d, d_i, e, e_i, tauq, tauq_i, taup, taup_i,
00226 info, info_i, lda, m, n );
00227 if( failed == 0 ) {
00228 printf( "PASSED: column-major high-level interface to zgebrd\n" );
00229 } else {
00230 printf( "FAILED: column-major high-level interface to zgebrd\n" );
00231 }
00232
00233
00234
00235 for( i = 0; i < lda*n; i++ ) {
00236 a_i[i] = a_save[i];
00237 }
00238 for( i = 0; i < (MIN(m,n)); i++ ) {
00239 d_i[i] = d_save[i];
00240 }
00241 for( i = 0; i < (MIN(m,n)-1); i++ ) {
00242 e_i[i] = e_save[i];
00243 }
00244 for( i = 0; i < (MIN(m,n)); i++ ) {
00245 tauq_i[i] = tauq_save[i];
00246 }
00247 for( i = 0; i < (MIN(m,n)); i++ ) {
00248 taup_i[i] = taup_save[i];
00249 }
00250 for( i = 0; i < lwork; i++ ) {
00251 work_i[i] = work[i];
00252 }
00253
00254 LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00255 info_i = LAPACKE_zgebrd_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, d_i,
00256 e_i, tauq_i, taup_i, work_i, lwork_i );
00257
00258 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00259
00260 failed = compare_zgebrd( a, a_i, d, d_i, e, e_i, tauq, tauq_i, taup, taup_i,
00261 info, info_i, lda, m, n );
00262 if( failed == 0 ) {
00263 printf( "PASSED: row-major middle-level interface to zgebrd\n" );
00264 } else {
00265 printf( "FAILED: row-major middle-level interface to zgebrd\n" );
00266 }
00267
00268
00269
00270 for( i = 0; i < lda*n; i++ ) {
00271 a_i[i] = a_save[i];
00272 }
00273 for( i = 0; i < (MIN(m,n)); i++ ) {
00274 d_i[i] = d_save[i];
00275 }
00276 for( i = 0; i < (MIN(m,n)-1); i++ ) {
00277 e_i[i] = e_save[i];
00278 }
00279 for( i = 0; i < (MIN(m,n)); i++ ) {
00280 tauq_i[i] = tauq_save[i];
00281 }
00282 for( i = 0; i < (MIN(m,n)); i++ ) {
00283 taup_i[i] = taup_save[i];
00284 }
00285 for( i = 0; i < lwork; i++ ) {
00286 work_i[i] = work[i];
00287 }
00288
00289
00290 LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00291 info_i = LAPACKE_zgebrd( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, d_i, e_i,
00292 tauq_i, taup_i );
00293
00294 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00295
00296 failed = compare_zgebrd( a, a_i, d, d_i, e, e_i, tauq, tauq_i, taup, taup_i,
00297 info, info_i, lda, m, n );
00298 if( failed == 0 ) {
00299 printf( "PASSED: row-major high-level interface to zgebrd\n" );
00300 } else {
00301 printf( "FAILED: row-major high-level interface to zgebrd\n" );
00302 }
00303
00304
00305 if( a != NULL ) {
00306 LAPACKE_free( a );
00307 }
00308 if( a_i != NULL ) {
00309 LAPACKE_free( a_i );
00310 }
00311 if( a_r != NULL ) {
00312 LAPACKE_free( a_r );
00313 }
00314 if( a_save != NULL ) {
00315 LAPACKE_free( a_save );
00316 }
00317 if( d != NULL ) {
00318 LAPACKE_free( d );
00319 }
00320 if( d_i != NULL ) {
00321 LAPACKE_free( d_i );
00322 }
00323 if( d_save != NULL ) {
00324 LAPACKE_free( d_save );
00325 }
00326 if( e != NULL ) {
00327 LAPACKE_free( e );
00328 }
00329 if( e_i != NULL ) {
00330 LAPACKE_free( e_i );
00331 }
00332 if( e_save != NULL ) {
00333 LAPACKE_free( e_save );
00334 }
00335 if( tauq != NULL ) {
00336 LAPACKE_free( tauq );
00337 }
00338 if( tauq_i != NULL ) {
00339 LAPACKE_free( tauq_i );
00340 }
00341 if( tauq_save != NULL ) {
00342 LAPACKE_free( tauq_save );
00343 }
00344 if( taup != NULL ) {
00345 LAPACKE_free( taup );
00346 }
00347 if( taup_i != NULL ) {
00348 LAPACKE_free( taup_i );
00349 }
00350 if( taup_save != NULL ) {
00351 LAPACKE_free( taup_save );
00352 }
00353 if( work != NULL ) {
00354 LAPACKE_free( work );
00355 }
00356 if( work_i != NULL ) {
00357 LAPACKE_free( work_i );
00358 }
00359
00360 return 0;
00361 }
00362
00363
00364 static void init_scalars_zgebrd( lapack_int *m, lapack_int *n, lapack_int *lda,
00365 lapack_int *lwork )
00366 {
00367 *m = 6;
00368 *n = 4;
00369 *lda = 8;
00370 *lwork = 1024;
00371
00372 return;
00373 }
00374
00375
00376 static void init_a( lapack_int size, lapack_complex_double *a ) {
00377 lapack_int i;
00378 for( i = 0; i < size; i++ ) {
00379 a[i] = lapack_make_complex_double( 0.0, 0.0 );
00380 }
00381 a[0] = lapack_make_complex_double( 9.59999999999999960e-001,
00382 -8.10000000000000050e-001 );
00383 a[8] = lapack_make_complex_double( -2.99999999999999990e-002,
00384 9.59999999999999960e-001 );
00385 a[16] = lapack_make_complex_double( -9.10000000000000030e-001,
00386 2.06000000000000010e+000 );
00387 a[24] = lapack_make_complex_double( -5.00000000000000030e-002,
00388 4.09999999999999980e-001 );
00389 a[1] = lapack_make_complex_double( -9.79999999999999980e-001,
00390 1.98000000000000000e+000 );
00391 a[9] = lapack_make_complex_double( -1.20000000000000000e+000,
00392 1.90000000000000000e-001 );
00393 a[17] = lapack_make_complex_double( -6.60000000000000030e-001,
00394 4.19999999999999980e-001 );
00395 a[25] = lapack_make_complex_double( -8.10000000000000050e-001,
00396 5.60000000000000050e-001 );
00397 a[2] = lapack_make_complex_double( 6.20000000000000000e-001,
00398 -4.60000000000000020e-001 );
00399 a[10] = lapack_make_complex_double( 1.01000000000000000e+000,
00400 2.00000000000000000e-002 );
00401 a[18] = lapack_make_complex_double( 6.30000000000000000e-001,
00402 -1.70000000000000010e-001 );
00403 a[26] = lapack_make_complex_double( -1.11000000000000010e+000,
00404 5.99999999999999980e-001 );
00405 a[3] = lapack_make_complex_double( -3.70000000000000000e-001,
00406 3.80000000000000000e-001 );
00407 a[11] = lapack_make_complex_double( 1.90000000000000000e-001,
00408 -5.40000000000000040e-001 );
00409 a[19] = lapack_make_complex_double( -9.79999999999999980e-001,
00410 -3.59999999999999990e-001 );
00411 a[27] = lapack_make_complex_double( 2.20000000000000000e-001,
00412 -2.00000000000000010e-001 );
00413 a[4] = lapack_make_complex_double( 8.29999999999999960e-001,
00414 5.10000000000000010e-001 );
00415 a[12] = lapack_make_complex_double( 2.00000000000000010e-001,
00416 1.00000000000000000e-002 );
00417 a[20] = lapack_make_complex_double( -1.70000000000000010e-001,
00418 -4.60000000000000020e-001 );
00419 a[28] = lapack_make_complex_double( 1.47000000000000000e+000,
00420 1.59000000000000010e+000 );
00421 a[5] = lapack_make_complex_double( 1.08000000000000010e+000,
00422 -2.80000000000000030e-001 );
00423 a[13] = lapack_make_complex_double( 2.00000000000000010e-001,
00424 -1.20000000000000000e-001 );
00425 a[21] = lapack_make_complex_double( -7.00000000000000070e-002,
00426 1.23000000000000000e+000 );
00427 a[29] = lapack_make_complex_double( 2.60000000000000010e-001,
00428 2.60000000000000010e-001 );
00429 }
00430 static void init_d( lapack_int size, double *d ) {
00431 lapack_int i;
00432 for( i = 0; i < size; i++ ) {
00433 d[i] = 0;
00434 }
00435 }
00436 static void init_e( lapack_int size, double *e ) {
00437 lapack_int i;
00438 for( i = 0; i < size; i++ ) {
00439 e[i] = 0;
00440 }
00441 }
00442 static void init_tauq( lapack_int size, lapack_complex_double *tauq ) {
00443 lapack_int i;
00444 for( i = 0; i < size; i++ ) {
00445 tauq[i] = lapack_make_complex_double( 0.0, 0.0 );
00446 }
00447 }
00448 static void init_taup( lapack_int size, lapack_complex_double *taup ) {
00449 lapack_int i;
00450 for( i = 0; i < size; i++ ) {
00451 taup[i] = lapack_make_complex_double( 0.0, 0.0 );
00452 }
00453 }
00454 static void init_work( lapack_int size, lapack_complex_double *work ) {
00455 lapack_int i;
00456 for( i = 0; i < size; i++ ) {
00457 work[i] = lapack_make_complex_double( 0.0, 0.0 );
00458 }
00459 }
00460
00461
00462
00463 static int compare_zgebrd( lapack_complex_double *a, lapack_complex_double *a_i,
00464 double *d, double *d_i, double *e, double *e_i,
00465 lapack_complex_double *tauq,
00466 lapack_complex_double *tauq_i,
00467 lapack_complex_double *taup,
00468 lapack_complex_double *taup_i, lapack_int info,
00469 lapack_int info_i, lapack_int lda, lapack_int m,
00470 lapack_int n )
00471 {
00472 lapack_int i;
00473 int failed = 0;
00474 for( i = 0; i < lda*n; i++ ) {
00475 failed += compare_complex_doubles(a[i],a_i[i]);
00476 }
00477 for( i = 0; i < (MIN(m,n)); i++ ) {
00478 failed += compare_doubles(d[i],d_i[i]);
00479 }
00480 for( i = 0; i < (MIN(m,n)-1); i++ ) {
00481 failed += compare_doubles(e[i],e_i[i]);
00482 }
00483 for( i = 0; i < (MIN(m,n)); i++ ) {
00484 failed += compare_complex_doubles(tauq[i],tauq_i[i]);
00485 }
00486 for( i = 0; i < (MIN(m,n)); i++ ) {
00487 failed += compare_complex_doubles(taup[i],taup_i[i]);
00488 }
00489 failed += (info == info_i) ? 0 : 1;
00490 if( info != 0 || info_i != 0 ) {
00491 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00492 }
00493
00494 return failed;
00495 }