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_cgebrd( lapack_int *m, lapack_int *n, lapack_int *lda,
00055 lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_float *a );
00057 static void init_d( lapack_int size, float *d );
00058 static void init_e( lapack_int size, float *e );
00059 static void init_tauq( lapack_int size, lapack_complex_float *tauq );
00060 static void init_taup( lapack_int size, lapack_complex_float *taup );
00061 static void init_work( lapack_int size, lapack_complex_float *work );
00062 static int compare_cgebrd( lapack_complex_float *a, lapack_complex_float *a_i,
00063 float *d, float *d_i, float *e, float *e_i,
00064 lapack_complex_float *tauq,
00065 lapack_complex_float *tauq_i,
00066 lapack_complex_float *taup,
00067 lapack_complex_float *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_float *a = NULL, *a_i = NULL;
00085 float *d = NULL, *d_i = NULL;
00086 float *e = NULL, *e_i = NULL;
00087 lapack_complex_float *tauq = NULL, *tauq_i = NULL;
00088 lapack_complex_float *taup = NULL, *taup_i = NULL;
00089 lapack_complex_float *work = NULL, *work_i = NULL;
00090 lapack_complex_float *a_save = NULL;
00091 float *d_save = NULL;
00092 float *e_save = NULL;
00093 lapack_complex_float *tauq_save = NULL;
00094 lapack_complex_float *taup_save = NULL;
00095 lapack_complex_float *a_r = NULL;
00096
00097
00098 init_scalars_cgebrd( &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_float *)
00107 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00108 d = (float *)LAPACKE_malloc( MIN(m,n) * sizeof(float) );
00109 e = (float *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(float) );
00110 tauq = (lapack_complex_float *)
00111 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00112 taup = (lapack_complex_float *)
00113 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00114 work = (lapack_complex_float *)
00115 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00116
00117
00118 a_i = (lapack_complex_float *)
00119 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00120 d_i = (float *)LAPACKE_malloc( MIN(m,n) * sizeof(float) );
00121 e_i = (float *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(float) );
00122 tauq_i = (lapack_complex_float *)
00123 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00124 taup_i = (lapack_complex_float *)
00125 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00126 work_i = (lapack_complex_float *)
00127 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00128
00129
00130 a_save = (lapack_complex_float *)
00131 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00132 d_save = (float *)LAPACKE_malloc( MIN(m,n) * sizeof(float) );
00133 e_save = (float *)LAPACKE_malloc( ((MIN(m,n)-1)) * sizeof(float) );
00134 tauq_save = (lapack_complex_float *)
00135 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00136 taup_save = (lapack_complex_float *)
00137 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00138
00139
00140 a_r = (lapack_complex_float *)
00141 LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) );
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 cgebrd_( &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_cgebrd_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_cgebrd( 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 cgebrd\n" );
00198 } else {
00199 printf( "FAILED: column-major middle-level interface to cgebrd\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_cgebrd( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, d_i, e_i,
00223 tauq_i, taup_i );
00224
00225 failed = compare_cgebrd( 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 cgebrd\n" );
00229 } else {
00230 printf( "FAILED: column-major high-level interface to cgebrd\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_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00255 info_i = LAPACKE_cgebrd_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_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00259
00260 failed = compare_cgebrd( 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 cgebrd\n" );
00264 } else {
00265 printf( "FAILED: row-major middle-level interface to cgebrd\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_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00291 info_i = LAPACKE_cgebrd( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, d_i, e_i,
00292 tauq_i, taup_i );
00293
00294 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00295
00296 failed = compare_cgebrd( 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 cgebrd\n" );
00300 } else {
00301 printf( "FAILED: row-major high-level interface to cgebrd\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_cgebrd( lapack_int *m, lapack_int *n, lapack_int *lda,
00365 lapack_int *lwork )
00366 {
00367 *m = 3;
00368 *n = 3;
00369 *lda = 8;
00370 *lwork = 1024;
00371
00372 return;
00373 }
00374
00375
00376 static void init_a( lapack_int size, lapack_complex_float *a ) {
00377 lapack_int i;
00378 for( i = 0; i < size; i++ ) {
00379 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00380 }
00381 a[0] = lapack_make_complex_float( -2.225511312e+000, 0.000000000e+000 );
00382 a[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00383 a[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00384 a[1] = lapack_make_complex_float( 8.207554817e-001, 1.238457084e+000 );
00385 a[9] = lapack_make_complex_float( 1.688100934e+000, 0.000000000e+000 );
00386 a[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00387 a[2] = lapack_make_complex_float( 1.033455133e-003, -6.822252274e-001 );
00388 a[10] = lapack_make_complex_float( 7.747511864e-001, -6.154725552e-001 );
00389 a[18] = lapack_make_complex_float( -1.590258121e+000, 0.000000000e+000 );
00390 }
00391 static void init_d( lapack_int size, float *d ) {
00392 lapack_int i;
00393 for( i = 0; i < size; i++ ) {
00394 d[i] = 0;
00395 }
00396 }
00397 static void init_e( lapack_int size, float *e ) {
00398 lapack_int i;
00399 for( i = 0; i < size; i++ ) {
00400 e[i] = 0;
00401 }
00402 }
00403 static void init_tauq( lapack_int size, lapack_complex_float *tauq ) {
00404 lapack_int i;
00405 for( i = 0; i < size; i++ ) {
00406 tauq[i] = lapack_make_complex_float( 0.0f, 0.0f );
00407 }
00408 }
00409 static void init_taup( lapack_int size, lapack_complex_float *taup ) {
00410 lapack_int i;
00411 for( i = 0; i < size; i++ ) {
00412 taup[i] = lapack_make_complex_float( 0.0f, 0.0f );
00413 }
00414 }
00415 static void init_work( lapack_int size, lapack_complex_float *work ) {
00416 lapack_int i;
00417 for( i = 0; i < size; i++ ) {
00418 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00419 }
00420 }
00421
00422
00423
00424 static int compare_cgebrd( lapack_complex_float *a, lapack_complex_float *a_i,
00425 float *d, float *d_i, float *e, float *e_i,
00426 lapack_complex_float *tauq,
00427 lapack_complex_float *tauq_i,
00428 lapack_complex_float *taup,
00429 lapack_complex_float *taup_i, lapack_int info,
00430 lapack_int info_i, lapack_int lda, lapack_int m,
00431 lapack_int n )
00432 {
00433 lapack_int i;
00434 int failed = 0;
00435 for( i = 0; i < lda*n; i++ ) {
00436 failed += compare_complex_floats(a[i],a_i[i]);
00437 }
00438 for( i = 0; i < (MIN(m,n)); i++ ) {
00439 failed += compare_floats(d[i],d_i[i]);
00440 }
00441 for( i = 0; i < (MIN(m,n)-1); i++ ) {
00442 failed += compare_floats(e[i],e_i[i]);
00443 }
00444 for( i = 0; i < (MIN(m,n)); i++ ) {
00445 failed += compare_complex_floats(tauq[i],tauq_i[i]);
00446 }
00447 for( i = 0; i < (MIN(m,n)); i++ ) {
00448 failed += compare_complex_floats(taup[i],taup_i[i]);
00449 }
00450 failed += (info == info_i) ? 0 : 1;
00451 if( info != 0 || info_i != 0 ) {
00452 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00453 }
00454
00455 return failed;
00456 }