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