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_chetrd( char *uplo, 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_tau( lapack_int size, lapack_complex_float *tau );
00060 static void init_work( lapack_int size, lapack_complex_float *work );
00061 static int compare_chetrd( lapack_complex_float *a, lapack_complex_float *a_i,
00062 float *d, float *d_i, float *e, float *e_i,
00063 lapack_complex_float *tau,
00064 lapack_complex_float *tau_i, lapack_int info,
00065 lapack_int info_i, lapack_int lda, lapack_int n );
00066
00067 int main(void)
00068 {
00069
00070 char uplo, uplo_i;
00071 lapack_int n, n_i;
00072 lapack_int lda, lda_i;
00073 lapack_int lda_r;
00074 lapack_int lwork, lwork_i;
00075 lapack_int info, info_i;
00076 lapack_int i;
00077 int failed;
00078
00079
00080 lapack_complex_float *a = NULL, *a_i = NULL;
00081 float *d = NULL, *d_i = NULL;
00082 float *e = NULL, *e_i = NULL;
00083 lapack_complex_float *tau = NULL, *tau_i = NULL;
00084 lapack_complex_float *work = NULL, *work_i = NULL;
00085 lapack_complex_float *a_save = NULL;
00086 float *d_save = NULL;
00087 float *e_save = NULL;
00088 lapack_complex_float *tau_save = NULL;
00089 lapack_complex_float *a_r = NULL;
00090
00091
00092 init_scalars_chetrd( &uplo, &n, &lda, &lwork );
00093 lda_r = n+2;
00094 uplo_i = uplo;
00095 n_i = n;
00096 lda_i = lda;
00097 lwork_i = lwork;
00098
00099
00100 a = (lapack_complex_float *)
00101 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00102 d = (float *)LAPACKE_malloc( n * sizeof(float) );
00103 e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00104 tau = (lapack_complex_float *)
00105 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00106 work = (lapack_complex_float *)
00107 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00108
00109
00110 a_i = (lapack_complex_float *)
00111 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00112 d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00113 e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00114 tau_i = (lapack_complex_float *)
00115 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00116 work_i = (lapack_complex_float *)
00117 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00118
00119
00120 a_save = (lapack_complex_float *)
00121 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00122 d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00123 e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00124 tau_save = (lapack_complex_float *)
00125 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00126
00127
00128 a_r = (lapack_complex_float *)
00129 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00130
00131
00132 init_a( lda*n, a );
00133 init_d( n, d );
00134 init_e( (n-1), e );
00135 init_tau( (n-1), tau );
00136 init_work( lwork, work );
00137
00138
00139 for( i = 0; i < lda*n; i++ ) {
00140 a_save[i] = a[i];
00141 }
00142 for( i = 0; i < n; i++ ) {
00143 d_save[i] = d[i];
00144 }
00145 for( i = 0; i < (n-1); i++ ) {
00146 e_save[i] = e[i];
00147 }
00148 for( i = 0; i < (n-1); i++ ) {
00149 tau_save[i] = tau[i];
00150 }
00151
00152
00153 chetrd_( &uplo, &n, a, &lda, d, e, tau, work, &lwork, &info );
00154
00155
00156
00157 for( i = 0; i < lda*n; i++ ) {
00158 a_i[i] = a_save[i];
00159 }
00160 for( i = 0; i < n; i++ ) {
00161 d_i[i] = d_save[i];
00162 }
00163 for( i = 0; i < (n-1); i++ ) {
00164 e_i[i] = e_save[i];
00165 }
00166 for( i = 0; i < (n-1); i++ ) {
00167 tau_i[i] = tau_save[i];
00168 }
00169 for( i = 0; i < lwork; i++ ) {
00170 work_i[i] = work[i];
00171 }
00172 info_i = LAPACKE_chetrd_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00173 d_i, e_i, tau_i, work_i, lwork_i );
00174
00175 failed = compare_chetrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00176 lda, n );
00177 if( failed == 0 ) {
00178 printf( "PASSED: column-major middle-level interface to chetrd\n" );
00179 } else {
00180 printf( "FAILED: column-major middle-level interface to chetrd\n" );
00181 }
00182
00183
00184
00185 for( i = 0; i < lda*n; i++ ) {
00186 a_i[i] = a_save[i];
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 < (n-1); i++ ) {
00195 tau_i[i] = tau_save[i];
00196 }
00197 for( i = 0; i < lwork; i++ ) {
00198 work_i[i] = work[i];
00199 }
00200 info_i = LAPACKE_chetrd( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i, d_i,
00201 e_i, tau_i );
00202
00203 failed = compare_chetrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00204 lda, n );
00205 if( failed == 0 ) {
00206 printf( "PASSED: column-major high-level interface to chetrd\n" );
00207 } else {
00208 printf( "FAILED: column-major high-level interface to chetrd\n" );
00209 }
00210
00211
00212
00213 for( i = 0; i < lda*n; i++ ) {
00214 a_i[i] = a_save[i];
00215 }
00216 for( i = 0; i < n; i++ ) {
00217 d_i[i] = d_save[i];
00218 }
00219 for( i = 0; i < (n-1); i++ ) {
00220 e_i[i] = e_save[i];
00221 }
00222 for( i = 0; i < (n-1); i++ ) {
00223 tau_i[i] = tau_save[i];
00224 }
00225 for( i = 0; i < lwork; i++ ) {
00226 work_i[i] = work[i];
00227 }
00228
00229 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00230 info_i = LAPACKE_chetrd_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00231 d_i, e_i, tau_i, work_i, lwork_i );
00232
00233 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00234
00235 failed = compare_chetrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00236 lda, n );
00237 if( failed == 0 ) {
00238 printf( "PASSED: row-major middle-level interface to chetrd\n" );
00239 } else {
00240 printf( "FAILED: row-major middle-level interface to chetrd\n" );
00241 }
00242
00243
00244
00245 for( i = 0; i < lda*n; i++ ) {
00246 a_i[i] = a_save[i];
00247 }
00248 for( i = 0; i < n; i++ ) {
00249 d_i[i] = d_save[i];
00250 }
00251 for( i = 0; i < (n-1); i++ ) {
00252 e_i[i] = e_save[i];
00253 }
00254 for( i = 0; i < (n-1); i++ ) {
00255 tau_i[i] = tau_save[i];
00256 }
00257 for( i = 0; i < lwork; i++ ) {
00258 work_i[i] = work[i];
00259 }
00260
00261
00262 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00263 info_i = LAPACKE_chetrd( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r, d_i,
00264 e_i, tau_i );
00265
00266 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00267
00268 failed = compare_chetrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00269 lda, n );
00270 if( failed == 0 ) {
00271 printf( "PASSED: row-major high-level interface to chetrd\n" );
00272 } else {
00273 printf( "FAILED: row-major high-level interface to chetrd\n" );
00274 }
00275
00276
00277 if( a != NULL ) {
00278 LAPACKE_free( a );
00279 }
00280 if( a_i != NULL ) {
00281 LAPACKE_free( a_i );
00282 }
00283 if( a_r != NULL ) {
00284 LAPACKE_free( a_r );
00285 }
00286 if( a_save != NULL ) {
00287 LAPACKE_free( a_save );
00288 }
00289 if( d != NULL ) {
00290 LAPACKE_free( d );
00291 }
00292 if( d_i != NULL ) {
00293 LAPACKE_free( d_i );
00294 }
00295 if( d_save != NULL ) {
00296 LAPACKE_free( d_save );
00297 }
00298 if( e != NULL ) {
00299 LAPACKE_free( e );
00300 }
00301 if( e_i != NULL ) {
00302 LAPACKE_free( e_i );
00303 }
00304 if( e_save != NULL ) {
00305 LAPACKE_free( e_save );
00306 }
00307 if( tau != NULL ) {
00308 LAPACKE_free( tau );
00309 }
00310 if( tau_i != NULL ) {
00311 LAPACKE_free( tau_i );
00312 }
00313 if( tau_save != NULL ) {
00314 LAPACKE_free( tau_save );
00315 }
00316 if( work != NULL ) {
00317 LAPACKE_free( work );
00318 }
00319 if( work_i != NULL ) {
00320 LAPACKE_free( work_i );
00321 }
00322
00323 return 0;
00324 }
00325
00326
00327 static void init_scalars_chetrd( char *uplo, lapack_int *n, lapack_int *lda,
00328 lapack_int *lwork )
00329 {
00330 *uplo = 'L';
00331 *n = 4;
00332 *lda = 8;
00333 *lwork = 512;
00334
00335 return;
00336 }
00337
00338
00339 static void init_a( lapack_int size, lapack_complex_float *a ) {
00340 lapack_int i;
00341 for( i = 0; i < size; i++ ) {
00342 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00343 }
00344 a[0] = lapack_make_complex_float( 6.019999981e+000, 0.000000000e+000 );
00345 a[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00346 a[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00347 a[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00348 a[1] = lapack_make_complex_float( -4.499999881e-001, -2.500000000e-001 );
00349 a[9] = lapack_make_complex_float( 2.910000086e+000, 0.000000000e+000 );
00350 a[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00351 a[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00352 a[2] = lapack_make_complex_float( -1.299999952e+000, -1.740000010e+000 );
00353 a[10] = lapack_make_complex_float( 5.000000075e-002, -1.559999943e+000 );
00354 a[18] = lapack_make_complex_float( 3.289999962e+000, 0.000000000e+000 );
00355 a[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00356 a[3] = lapack_make_complex_float( 1.450000048e+000, 6.600000262e-001 );
00357 a[11] = lapack_make_complex_float( -1.039999962e+000, -1.269999981e+000 );
00358 a[19] = lapack_make_complex_float( 1.400000006e-001, -1.700000048e+000 );
00359 a[27] = lapack_make_complex_float( 4.179999828e+000, 0.000000000e+000 );
00360 }
00361 static void init_d( lapack_int size, float *d ) {
00362 lapack_int i;
00363 for( i = 0; i < size; i++ ) {
00364 d[i] = 0;
00365 }
00366 }
00367 static void init_e( lapack_int size, float *e ) {
00368 lapack_int i;
00369 for( i = 0; i < size; i++ ) {
00370 e[i] = 0;
00371 }
00372 }
00373 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00374 lapack_int i;
00375 for( i = 0; i < size; i++ ) {
00376 tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00377 }
00378 }
00379 static void init_work( lapack_int size, lapack_complex_float *work ) {
00380 lapack_int i;
00381 for( i = 0; i < size; i++ ) {
00382 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00383 }
00384 }
00385
00386
00387
00388 static int compare_chetrd( lapack_complex_float *a, lapack_complex_float *a_i,
00389 float *d, float *d_i, float *e, float *e_i,
00390 lapack_complex_float *tau,
00391 lapack_complex_float *tau_i, lapack_int info,
00392 lapack_int info_i, lapack_int lda, lapack_int n )
00393 {
00394 lapack_int i;
00395 int failed = 0;
00396 for( i = 0; i < lda*n; i++ ) {
00397 failed += compare_complex_floats(a[i],a_i[i]);
00398 }
00399 for( i = 0; i < n; i++ ) {
00400 failed += compare_floats(d[i],d_i[i]);
00401 }
00402 for( i = 0; i < (n-1); i++ ) {
00403 failed += compare_floats(e[i],e_i[i]);
00404 }
00405 for( i = 0; i < (n-1); i++ ) {
00406 failed += compare_complex_floats(tau[i],tau_i[i]);
00407 }
00408 failed += (info == info_i) ? 0 : 1;
00409 if( info != 0 || info_i != 0 ) {
00410 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00411 }
00412
00413 return failed;
00414 }