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_zhptrd( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, lapack_complex_double *ap );
00056 static void init_d( lapack_int size, double *d );
00057 static void init_e( lapack_int size, double *e );
00058 static void init_tau( lapack_int size, lapack_complex_double *tau );
00059 static int compare_zhptrd( lapack_complex_double *ap,
00060 lapack_complex_double *ap_i, double *d, double *d_i,
00061 double *e, double *e_i, lapack_complex_double *tau,
00062 lapack_complex_double *tau_i, lapack_int info,
00063 lapack_int info_i, lapack_int n );
00064
00065 int main(void)
00066 {
00067
00068 char uplo, uplo_i;
00069 lapack_int n, n_i;
00070 lapack_int info, info_i;
00071 lapack_int i;
00072 int failed;
00073
00074
00075 lapack_complex_double *ap = NULL, *ap_i = NULL;
00076 double *d = NULL, *d_i = NULL;
00077 double *e = NULL, *e_i = NULL;
00078 lapack_complex_double *tau = NULL, *tau_i = NULL;
00079 lapack_complex_double *ap_save = NULL;
00080 double *d_save = NULL;
00081 double *e_save = NULL;
00082 lapack_complex_double *tau_save = NULL;
00083 lapack_complex_double *ap_r = NULL;
00084
00085
00086 init_scalars_zhptrd( &uplo, &n );
00087 uplo_i = uplo;
00088 n_i = n;
00089
00090
00091 ap = (lapack_complex_double *)
00092 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00093 d = (double *)LAPACKE_malloc( n * sizeof(double) );
00094 e = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00095 tau = (lapack_complex_double *)
00096 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00097
00098
00099 ap_i = (lapack_complex_double *)
00100 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00101 d_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00102 e_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00103 tau_i = (lapack_complex_double *)
00104 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00105
00106
00107 ap_save = (lapack_complex_double *)
00108 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00109 d_save = (double *)LAPACKE_malloc( n * sizeof(double) );
00110 e_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00111 tau_save = (lapack_complex_double *)
00112 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00113
00114
00115 ap_r = (lapack_complex_double *)
00116 LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00117
00118
00119 init_ap( (n*(n+1)/2), ap );
00120 init_d( n, d );
00121 init_e( (n-1), e );
00122 init_tau( (n-1), tau );
00123
00124
00125 for( i = 0; i < (n*(n+1)/2); i++ ) {
00126 ap_save[i] = ap[i];
00127 }
00128 for( i = 0; i < n; i++ ) {
00129 d_save[i] = d[i];
00130 }
00131 for( i = 0; i < (n-1); i++ ) {
00132 e_save[i] = e[i];
00133 }
00134 for( i = 0; i < (n-1); i++ ) {
00135 tau_save[i] = tau[i];
00136 }
00137
00138
00139 zhptrd_( &uplo, &n, ap, d, e, tau, &info );
00140
00141
00142
00143 for( i = 0; i < (n*(n+1)/2); i++ ) {
00144 ap_i[i] = ap_save[i];
00145 }
00146 for( i = 0; i < n; i++ ) {
00147 d_i[i] = d_save[i];
00148 }
00149 for( i = 0; i < (n-1); i++ ) {
00150 e_i[i] = e_save[i];
00151 }
00152 for( i = 0; i < (n-1); i++ ) {
00153 tau_i[i] = tau_save[i];
00154 }
00155 info_i = LAPACKE_zhptrd_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00156 tau_i );
00157
00158 failed = compare_zhptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00159 n );
00160 if( failed == 0 ) {
00161 printf( "PASSED: column-major middle-level interface to zhptrd\n" );
00162 } else {
00163 printf( "FAILED: column-major middle-level interface to zhptrd\n" );
00164 }
00165
00166
00167
00168 for( i = 0; i < (n*(n+1)/2); i++ ) {
00169 ap_i[i] = ap_save[i];
00170 }
00171 for( i = 0; i < n; i++ ) {
00172 d_i[i] = d_save[i];
00173 }
00174 for( i = 0; i < (n-1); i++ ) {
00175 e_i[i] = e_save[i];
00176 }
00177 for( i = 0; i < (n-1); i++ ) {
00178 tau_i[i] = tau_save[i];
00179 }
00180 info_i = LAPACKE_zhptrd( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00181 tau_i );
00182
00183 failed = compare_zhptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00184 n );
00185 if( failed == 0 ) {
00186 printf( "PASSED: column-major high-level interface to zhptrd\n" );
00187 } else {
00188 printf( "FAILED: column-major high-level interface to zhptrd\n" );
00189 }
00190
00191
00192
00193 for( i = 0; i < (n*(n+1)/2); i++ ) {
00194 ap_i[i] = ap_save[i];
00195 }
00196 for( i = 0; i < n; i++ ) {
00197 d_i[i] = d_save[i];
00198 }
00199 for( i = 0; i < (n-1); i++ ) {
00200 e_i[i] = e_save[i];
00201 }
00202 for( i = 0; i < (n-1); i++ ) {
00203 tau_i[i] = tau_save[i];
00204 }
00205
00206 LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00207 info_i = LAPACKE_zhptrd_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00208 tau_i );
00209
00210 LAPACKE_zpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00211
00212 failed = compare_zhptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00213 n );
00214 if( failed == 0 ) {
00215 printf( "PASSED: row-major middle-level interface to zhptrd\n" );
00216 } else {
00217 printf( "FAILED: row-major middle-level interface to zhptrd\n" );
00218 }
00219
00220
00221
00222 for( i = 0; i < (n*(n+1)/2); i++ ) {
00223 ap_i[i] = ap_save[i];
00224 }
00225 for( i = 0; i < n; i++ ) {
00226 d_i[i] = d_save[i];
00227 }
00228 for( i = 0; i < (n-1); i++ ) {
00229 e_i[i] = e_save[i];
00230 }
00231 for( i = 0; i < (n-1); i++ ) {
00232 tau_i[i] = tau_save[i];
00233 }
00234
00235
00236 LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00237 info_i = LAPACKE_zhptrd( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00238 tau_i );
00239
00240 LAPACKE_zpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00241
00242 failed = compare_zhptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00243 n );
00244 if( failed == 0 ) {
00245 printf( "PASSED: row-major high-level interface to zhptrd\n" );
00246 } else {
00247 printf( "FAILED: row-major high-level interface to zhptrd\n" );
00248 }
00249
00250
00251 if( ap != NULL ) {
00252 LAPACKE_free( ap );
00253 }
00254 if( ap_i != NULL ) {
00255 LAPACKE_free( ap_i );
00256 }
00257 if( ap_r != NULL ) {
00258 LAPACKE_free( ap_r );
00259 }
00260 if( ap_save != NULL ) {
00261 LAPACKE_free( ap_save );
00262 }
00263 if( d != NULL ) {
00264 LAPACKE_free( d );
00265 }
00266 if( d_i != NULL ) {
00267 LAPACKE_free( d_i );
00268 }
00269 if( d_save != NULL ) {
00270 LAPACKE_free( d_save );
00271 }
00272 if( e != NULL ) {
00273 LAPACKE_free( e );
00274 }
00275 if( e_i != NULL ) {
00276 LAPACKE_free( e_i );
00277 }
00278 if( e_save != NULL ) {
00279 LAPACKE_free( e_save );
00280 }
00281 if( tau != NULL ) {
00282 LAPACKE_free( tau );
00283 }
00284 if( tau_i != NULL ) {
00285 LAPACKE_free( tau_i );
00286 }
00287 if( tau_save != NULL ) {
00288 LAPACKE_free( tau_save );
00289 }
00290
00291 return 0;
00292 }
00293
00294
00295 static void init_scalars_zhptrd( char *uplo, lapack_int *n )
00296 {
00297 *uplo = 'L';
00298 *n = 4;
00299
00300 return;
00301 }
00302
00303
00304 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00305 lapack_int i;
00306 for( i = 0; i < size; i++ ) {
00307 ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00308 }
00309 ap[0] = lapack_make_complex_double( -2.27999999999999980e+000,
00310 0.00000000000000000e+000 );
00311 ap[1] = lapack_make_complex_double( 1.78000000000000000e+000,
00312 2.02999999999999980e+000 );
00313 ap[2] = lapack_make_complex_double( 2.25999999999999980e+000,
00314 -1.00000000000000010e-001 );
00315 ap[3] = lapack_make_complex_double( -1.20000000000000000e-001,
00316 -2.52999999999999980e+000 );
00317 ap[4] = lapack_make_complex_double( -1.12000000000000010e+000,
00318 0.00000000000000000e+000 );
00319 ap[5] = lapack_make_complex_double( 1.00000000000000000e-002,
00320 -4.29999999999999990e-001 );
00321 ap[6] = lapack_make_complex_double( -1.07000000000000010e+000,
00322 -8.59999999999999990e-001 );
00323 ap[7] = lapack_make_complex_double( -3.70000000000000000e-001,
00324 0.00000000000000000e+000 );
00325 ap[8] = lapack_make_complex_double( 2.31000000000000010e+000,
00326 9.20000000000000040e-001 );
00327 ap[9] = lapack_make_complex_double( -7.29999999999999980e-001,
00328 0.00000000000000000e+000 );
00329 }
00330 static void init_d( lapack_int size, double *d ) {
00331 lapack_int i;
00332 for( i = 0; i < size; i++ ) {
00333 d[i] = 0;
00334 }
00335 }
00336 static void init_e( lapack_int size, double *e ) {
00337 lapack_int i;
00338 for( i = 0; i < size; i++ ) {
00339 e[i] = 0;
00340 }
00341 }
00342 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00343 lapack_int i;
00344 for( i = 0; i < size; i++ ) {
00345 tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00346 }
00347 }
00348
00349
00350
00351 static int compare_zhptrd( lapack_complex_double *ap,
00352 lapack_complex_double *ap_i, double *d, double *d_i,
00353 double *e, double *e_i, lapack_complex_double *tau,
00354 lapack_complex_double *tau_i, lapack_int info,
00355 lapack_int info_i, lapack_int n )
00356 {
00357 lapack_int i;
00358 int failed = 0;
00359 for( i = 0; i < (n*(n+1)/2); i++ ) {
00360 failed += compare_complex_doubles(ap[i],ap_i[i]);
00361 }
00362 for( i = 0; i < n; i++ ) {
00363 failed += compare_doubles(d[i],d_i[i]);
00364 }
00365 for( i = 0; i < (n-1); i++ ) {
00366 failed += compare_doubles(e[i],e_i[i]);
00367 }
00368 for( i = 0; i < (n-1); i++ ) {
00369 failed += compare_complex_doubles(tau[i],tau_i[i]);
00370 }
00371 failed += (info == info_i) ? 0 : 1;
00372 if( info != 0 || info_i != 0 ) {
00373 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00374 }
00375
00376 return failed;
00377 }