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_chptrd( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, lapack_complex_float *ap );
00056 static void init_d( lapack_int size, float *d );
00057 static void init_e( lapack_int size, float *e );
00058 static void init_tau( lapack_int size, lapack_complex_float *tau );
00059 static int compare_chptrd( lapack_complex_float *ap, lapack_complex_float *ap_i,
00060 float *d, float *d_i, float *e, float *e_i,
00061 lapack_complex_float *tau,
00062 lapack_complex_float *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_float *ap = NULL, *ap_i = NULL;
00076 float *d = NULL, *d_i = NULL;
00077 float *e = NULL, *e_i = NULL;
00078 lapack_complex_float *tau = NULL, *tau_i = NULL;
00079 lapack_complex_float *ap_save = NULL;
00080 float *d_save = NULL;
00081 float *e_save = NULL;
00082 lapack_complex_float *tau_save = NULL;
00083 lapack_complex_float *ap_r = NULL;
00084
00085
00086 init_scalars_chptrd( &uplo, &n );
00087 uplo_i = uplo;
00088 n_i = n;
00089
00090
00091 ap = (lapack_complex_float *)
00092 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00093 d = (float *)LAPACKE_malloc( n * sizeof(float) );
00094 e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00095 tau = (lapack_complex_float *)
00096 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00097
00098
00099 ap_i = (lapack_complex_float *)
00100 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00101 d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00102 e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00103 tau_i = (lapack_complex_float *)
00104 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00105
00106
00107 ap_save = (lapack_complex_float *)
00108 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00109 d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00110 e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00111 tau_save = (lapack_complex_float *)
00112 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00113
00114
00115 ap_r = (lapack_complex_float *)
00116 LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
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 chptrd_( &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_chptrd_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00156 tau_i );
00157
00158 failed = compare_chptrd( 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 chptrd\n" );
00162 } else {
00163 printf( "FAILED: column-major middle-level interface to chptrd\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_chptrd( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00181 tau_i );
00182
00183 failed = compare_chptrd( 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 chptrd\n" );
00187 } else {
00188 printf( "FAILED: column-major high-level interface to chptrd\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_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00207 info_i = LAPACKE_chptrd_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00208 tau_i );
00209
00210 LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00211
00212 failed = compare_chptrd( 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 chptrd\n" );
00216 } else {
00217 printf( "FAILED: row-major middle-level interface to chptrd\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_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00237 info_i = LAPACKE_chptrd( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00238 tau_i );
00239
00240 LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00241
00242 failed = compare_chptrd( 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 chptrd\n" );
00246 } else {
00247 printf( "FAILED: row-major high-level interface to chptrd\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_chptrd( 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_float *ap ) {
00305 lapack_int i;
00306 for( i = 0; i < size; i++ ) {
00307 ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00308 }
00309 ap[0] = lapack_make_complex_float( -2.279999971e+000, 0.000000000e+000 );
00310 ap[1] = lapack_make_complex_float( 1.779999971e+000, 2.029999971e+000 );
00311 ap[2] = lapack_make_complex_float( 2.259999990e+000, -1.000000015e-001 );
00312 ap[3] = lapack_make_complex_float( -1.199999973e-001, -2.529999971e+000 );
00313 ap[4] = lapack_make_complex_float( -1.120000005e+000, 0.000000000e+000 );
00314 ap[5] = lapack_make_complex_float( 9.999999776e-003, -4.300000072e-001 );
00315 ap[6] = lapack_make_complex_float( -1.070000052e+000, -8.600000143e-001 );
00316 ap[7] = lapack_make_complex_float( -3.700000048e-001, 0.000000000e+000 );
00317 ap[8] = lapack_make_complex_float( 2.309999943e+000, 9.200000167e-001 );
00318 ap[9] = lapack_make_complex_float( -7.300000191e-001, 0.000000000e+000 );
00319 }
00320 static void init_d( lapack_int size, float *d ) {
00321 lapack_int i;
00322 for( i = 0; i < size; i++ ) {
00323 d[i] = 0;
00324 }
00325 }
00326 static void init_e( lapack_int size, float *e ) {
00327 lapack_int i;
00328 for( i = 0; i < size; i++ ) {
00329 e[i] = 0;
00330 }
00331 }
00332 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00333 lapack_int i;
00334 for( i = 0; i < size; i++ ) {
00335 tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00336 }
00337 }
00338
00339
00340
00341 static int compare_chptrd( lapack_complex_float *ap, lapack_complex_float *ap_i,
00342 float *d, float *d_i, float *e, float *e_i,
00343 lapack_complex_float *tau,
00344 lapack_complex_float *tau_i, lapack_int info,
00345 lapack_int info_i, lapack_int n )
00346 {
00347 lapack_int i;
00348 int failed = 0;
00349 for( i = 0; i < (n*(n+1)/2); i++ ) {
00350 failed += compare_complex_floats(ap[i],ap_i[i]);
00351 }
00352 for( i = 0; i < n; i++ ) {
00353 failed += compare_floats(d[i],d_i[i]);
00354 }
00355 for( i = 0; i < (n-1); i++ ) {
00356 failed += compare_floats(e[i],e_i[i]);
00357 }
00358 for( i = 0; i < (n-1); i++ ) {
00359 failed += compare_complex_floats(tau[i],tau_i[i]);
00360 }
00361 failed += (info == info_i) ? 0 : 1;
00362 if( info != 0 || info_i != 0 ) {
00363 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00364 }
00365
00366 return failed;
00367 }