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