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_chbtrd( char *vect, char *uplo, lapack_int *n,
00055 lapack_int *kd, lapack_int *ldab,
00056 lapack_int *ldq );
00057 static void init_ab( lapack_int size, lapack_complex_float *ab );
00058 static void init_d( lapack_int size, float *d );
00059 static void init_e( lapack_int size, float *e );
00060 static void init_q( lapack_int size, lapack_complex_float *q );
00061 static void init_work( lapack_int size, lapack_complex_float *work );
00062 static int compare_chbtrd( lapack_complex_float *ab, lapack_complex_float *ab_i,
00063 float *d, float *d_i, float *e, float *e_i,
00064 lapack_complex_float *q, lapack_complex_float *q_i,
00065 lapack_int info, lapack_int info_i, lapack_int ldab,
00066 lapack_int ldq, lapack_int n, char vect );
00067
00068 int main(void)
00069 {
00070
00071 char vect, vect_i;
00072 char uplo, uplo_i;
00073 lapack_int n, n_i;
00074 lapack_int kd, kd_i;
00075 lapack_int ldab, ldab_i;
00076 lapack_int ldab_r;
00077 lapack_int ldq, ldq_i;
00078 lapack_int ldq_r;
00079 lapack_int info, info_i;
00080 lapack_int i;
00081 int failed;
00082
00083
00084 lapack_complex_float *ab = NULL, *ab_i = NULL;
00085 float *d = NULL, *d_i = NULL;
00086 float *e = NULL, *e_i = NULL;
00087 lapack_complex_float *q = NULL, *q_i = NULL;
00088 lapack_complex_float *work = NULL, *work_i = NULL;
00089 lapack_complex_float *ab_save = NULL;
00090 float *d_save = NULL;
00091 float *e_save = NULL;
00092 lapack_complex_float *q_save = NULL;
00093 lapack_complex_float *ab_r = NULL;
00094 lapack_complex_float *q_r = NULL;
00095
00096
00097 init_scalars_chbtrd( &vect, &uplo, &n, &kd, &ldab, &ldq );
00098 ldab_r = n+2;
00099 ldq_r = n+2;
00100 vect_i = vect;
00101 uplo_i = uplo;
00102 n_i = n;
00103 kd_i = kd;
00104 ldab_i = ldab;
00105 ldq_i = ldq;
00106
00107
00108 ab = (lapack_complex_float *)
00109 LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00110 d = (float *)LAPACKE_malloc( n * sizeof(float) );
00111 e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00112 q = (lapack_complex_float *)
00113 LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00114 work = (lapack_complex_float *)
00115 LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00116
00117
00118 ab_i = (lapack_complex_float *)
00119 LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00120 d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00121 e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00122 q_i = (lapack_complex_float *)
00123 LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00124 work_i = (lapack_complex_float *)
00125 LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00126
00127
00128 ab_save = (lapack_complex_float *)
00129 LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00130 d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00131 e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00132 q_save = (lapack_complex_float *)
00133 LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00134
00135
00136 ab_r = (lapack_complex_float *)
00137 LAPACKE_malloc( (kd+1)*(n+2) * sizeof(lapack_complex_float) );
00138 q_r = (lapack_complex_float *)
00139 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00140
00141
00142 init_ab( ldab*n, ab );
00143 init_d( n, d );
00144 init_e( (n-1), e );
00145 init_q( ldq*n, q );
00146 init_work( n, work );
00147
00148
00149 for( i = 0; i < ldab*n; i++ ) {
00150 ab_save[i] = ab[i];
00151 }
00152 for( i = 0; i < n; i++ ) {
00153 d_save[i] = d[i];
00154 }
00155 for( i = 0; i < (n-1); i++ ) {
00156 e_save[i] = e[i];
00157 }
00158 for( i = 0; i < ldq*n; i++ ) {
00159 q_save[i] = q[i];
00160 }
00161
00162
00163 chbtrd_( &vect, &uplo, &n, &kd, ab, &ldab, d, e, q, &ldq, work, &info );
00164
00165
00166
00167 for( i = 0; i < ldab*n; i++ ) {
00168 ab_i[i] = ab_save[i];
00169 }
00170 for( i = 0; i < n; i++ ) {
00171 d_i[i] = d_save[i];
00172 }
00173 for( i = 0; i < (n-1); i++ ) {
00174 e_i[i] = e_save[i];
00175 }
00176 for( i = 0; i < ldq*n; i++ ) {
00177 q_i[i] = q_save[i];
00178 }
00179 for( i = 0; i < n; i++ ) {
00180 work_i[i] = work[i];
00181 }
00182 info_i = LAPACKE_chbtrd_work( LAPACK_COL_MAJOR, vect_i, uplo_i, n_i, kd_i,
00183 ab_i, ldab_i, d_i, e_i, q_i, ldq_i, work_i );
00184
00185 failed = compare_chbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
00186 ldab, ldq, n, vect );
00187 if( failed == 0 ) {
00188 printf( "PASSED: column-major middle-level interface to chbtrd\n" );
00189 } else {
00190 printf( "FAILED: column-major middle-level interface to chbtrd\n" );
00191 }
00192
00193
00194
00195 for( i = 0; i < ldab*n; i++ ) {
00196 ab_i[i] = ab_save[i];
00197 }
00198 for( i = 0; i < n; i++ ) {
00199 d_i[i] = d_save[i];
00200 }
00201 for( i = 0; i < (n-1); i++ ) {
00202 e_i[i] = e_save[i];
00203 }
00204 for( i = 0; i < ldq*n; i++ ) {
00205 q_i[i] = q_save[i];
00206 }
00207 for( i = 0; i < n; i++ ) {
00208 work_i[i] = work[i];
00209 }
00210 info_i = LAPACKE_chbtrd( LAPACK_COL_MAJOR, vect_i, uplo_i, n_i, kd_i, ab_i,
00211 ldab_i, d_i, e_i, q_i, ldq_i );
00212
00213 failed = compare_chbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
00214 ldab, ldq, n, vect );
00215 if( failed == 0 ) {
00216 printf( "PASSED: column-major high-level interface to chbtrd\n" );
00217 } else {
00218 printf( "FAILED: column-major high-level interface to chbtrd\n" );
00219 }
00220
00221
00222
00223 for( i = 0; i < ldab*n; i++ ) {
00224 ab_i[i] = ab_save[i];
00225 }
00226 for( i = 0; i < n; i++ ) {
00227 d_i[i] = d_save[i];
00228 }
00229 for( i = 0; i < (n-1); i++ ) {
00230 e_i[i] = e_save[i];
00231 }
00232 for( i = 0; i < ldq*n; i++ ) {
00233 q_i[i] = q_save[i];
00234 }
00235 for( i = 0; i < n; i++ ) {
00236 work_i[i] = work[i];
00237 }
00238
00239 LAPACKE_cge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00240 if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00241 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00242 }
00243 info_i = LAPACKE_chbtrd_work( LAPACK_ROW_MAJOR, vect_i, uplo_i, n_i, kd_i,
00244 ab_r, ldab_r, d_i, e_i, q_r, ldq_r, work_i );
00245
00246 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, kd+1, n, ab_r, n+2, ab_i, ldab );
00247 if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00248 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00249 }
00250
00251 failed = compare_chbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
00252 ldab, ldq, n, vect );
00253 if( failed == 0 ) {
00254 printf( "PASSED: row-major middle-level interface to chbtrd\n" );
00255 } else {
00256 printf( "FAILED: row-major middle-level interface to chbtrd\n" );
00257 }
00258
00259
00260
00261 for( i = 0; i < ldab*n; i++ ) {
00262 ab_i[i] = ab_save[i];
00263 }
00264 for( i = 0; i < n; i++ ) {
00265 d_i[i] = d_save[i];
00266 }
00267 for( i = 0; i < (n-1); i++ ) {
00268 e_i[i] = e_save[i];
00269 }
00270 for( i = 0; i < ldq*n; i++ ) {
00271 q_i[i] = q_save[i];
00272 }
00273 for( i = 0; i < n; i++ ) {
00274 work_i[i] = work[i];
00275 }
00276
00277
00278 LAPACKE_cge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00279 if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00280 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00281 }
00282 info_i = LAPACKE_chbtrd( LAPACK_ROW_MAJOR, vect_i, uplo_i, n_i, kd_i, ab_r,
00283 ldab_r, d_i, e_i, q_r, ldq_r );
00284
00285 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, kd+1, n, ab_r, n+2, ab_i, ldab );
00286 if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00287 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00288 }
00289
00290 failed = compare_chbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
00291 ldab, ldq, n, vect );
00292 if( failed == 0 ) {
00293 printf( "PASSED: row-major high-level interface to chbtrd\n" );
00294 } else {
00295 printf( "FAILED: row-major high-level interface to chbtrd\n" );
00296 }
00297
00298
00299 if( ab != NULL ) {
00300 LAPACKE_free( ab );
00301 }
00302 if( ab_i != NULL ) {
00303 LAPACKE_free( ab_i );
00304 }
00305 if( ab_r != NULL ) {
00306 LAPACKE_free( ab_r );
00307 }
00308 if( ab_save != NULL ) {
00309 LAPACKE_free( ab_save );
00310 }
00311 if( d != NULL ) {
00312 LAPACKE_free( d );
00313 }
00314 if( d_i != NULL ) {
00315 LAPACKE_free( d_i );
00316 }
00317 if( d_save != NULL ) {
00318 LAPACKE_free( d_save );
00319 }
00320 if( e != NULL ) {
00321 LAPACKE_free( e );
00322 }
00323 if( e_i != NULL ) {
00324 LAPACKE_free( e_i );
00325 }
00326 if( e_save != NULL ) {
00327 LAPACKE_free( e_save );
00328 }
00329 if( q != NULL ) {
00330 LAPACKE_free( q );
00331 }
00332 if( q_i != NULL ) {
00333 LAPACKE_free( q_i );
00334 }
00335 if( q_r != NULL ) {
00336 LAPACKE_free( q_r );
00337 }
00338 if( q_save != NULL ) {
00339 LAPACKE_free( q_save );
00340 }
00341 if( work != NULL ) {
00342 LAPACKE_free( work );
00343 }
00344 if( work_i != NULL ) {
00345 LAPACKE_free( work_i );
00346 }
00347
00348 return 0;
00349 }
00350
00351
00352 static void init_scalars_chbtrd( char *vect, char *uplo, lapack_int *n,
00353 lapack_int *kd, lapack_int *ldab,
00354 lapack_int *ldq )
00355 {
00356 *vect = 'V';
00357 *uplo = 'L';
00358 *n = 4;
00359 *kd = 2;
00360 *ldab = 9;
00361 *ldq = 8;
00362
00363 return;
00364 }
00365
00366
00367 static void init_ab( lapack_int size, lapack_complex_float *ab ) {
00368 lapack_int i;
00369 for( i = 0; i < size; i++ ) {
00370 ab[i] = lapack_make_complex_float( 0.0f, 0.0f );
00371 }
00372 ab[0] = lapack_make_complex_float( -3.130000114e+000, 0.000000000e+000 );
00373 ab[9] = lapack_make_complex_float( -1.909999967e+000, 0.000000000e+000 );
00374 ab[18] = lapack_make_complex_float( -2.869999886e+000, 0.000000000e+000 );
00375 ab[27] = lapack_make_complex_float( 5.000000000e-001, 0.000000000e+000 );
00376 ab[1] = lapack_make_complex_float( 1.940000057e+000, 2.099999905e+000 );
00377 ab[10] = lapack_make_complex_float( -8.199999928e-001, 8.899999857e-001 );
00378 ab[19] = lapack_make_complex_float( -2.099999905e+000, 1.599999964e-001 );
00379 ab[28] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00380 ab[2] = lapack_make_complex_float( -3.400000095e+000, -2.500000000e-001 );
00381 ab[11] = lapack_make_complex_float( -6.700000167e-001, -3.400000036e-001 );
00382 ab[20] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00383 ab[29] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00384 }
00385 static void init_d( lapack_int size, float *d ) {
00386 lapack_int i;
00387 for( i = 0; i < size; i++ ) {
00388 d[i] = 0;
00389 }
00390 }
00391 static void init_e( lapack_int size, float *e ) {
00392 lapack_int i;
00393 for( i = 0; i < size; i++ ) {
00394 e[i] = 0;
00395 }
00396 }
00397 static void init_q( lapack_int size, lapack_complex_float *q ) {
00398 lapack_int i;
00399 for( i = 0; i < size; i++ ) {
00400 q[i] = lapack_make_complex_float( 0.0f, 0.0f );
00401 }
00402 q[0] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00403 q[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00404 q[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00405 q[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00406 q[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00407 q[9] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00408 q[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00409 q[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00410 q[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00411 q[10] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00412 q[18] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00413 q[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00414 q[3] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00415 q[11] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00416 q[19] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00417 q[27] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00418 }
00419 static void init_work( lapack_int size, lapack_complex_float *work ) {
00420 lapack_int i;
00421 for( i = 0; i < size; i++ ) {
00422 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00423 }
00424 }
00425
00426
00427
00428 static int compare_chbtrd( lapack_complex_float *ab, lapack_complex_float *ab_i,
00429 float *d, float *d_i, float *e, float *e_i,
00430 lapack_complex_float *q, lapack_complex_float *q_i,
00431 lapack_int info, lapack_int info_i, lapack_int ldab,
00432 lapack_int ldq, lapack_int n, char vect )
00433 {
00434 lapack_int i;
00435 int failed = 0;
00436 for( i = 0; i < ldab*n; i++ ) {
00437 failed += compare_complex_floats(ab[i],ab_i[i]);
00438 }
00439 for( i = 0; i < n; i++ ) {
00440 failed += compare_floats(d[i],d_i[i]);
00441 }
00442 for( i = 0; i < (n-1); i++ ) {
00443 failed += compare_floats(e[i],e_i[i]);
00444 }
00445 if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
00446 for( i = 0; i < ldq*n; i++ ) {
00447 failed += compare_complex_floats(q[i],q_i[i]);
00448 }
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 }