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_ssteqr( 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_ssteqr( float *d, float *d_i, float *e, float *e_i, float *z,
00060 float *z_i, lapack_int info, lapack_int info_i,
00061 char compz, 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_ssteqr( &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( ((MAX(1,2*n-2))) * 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( ((MAX(1,2*n-2))) * 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( (MAX(1,2*n-2)), 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 ssteqr_( &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 < (MAX(1,2*n-2)); i++ ) {
00143 work_i[i] = work[i];
00144 }
00145 info_i = LAPACKE_ssteqr_work( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00146 ldz_i, work_i );
00147
00148 failed = compare_ssteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00149 n );
00150 if( failed == 0 ) {
00151 printf( "PASSED: column-major middle-level interface to ssteqr\n" );
00152 } else {
00153 printf( "FAILED: column-major middle-level interface to ssteqr\n" );
00154 }
00155
00156
00157
00158 for( i = 0; i < n; i++ ) {
00159 d_i[i] = d_save[i];
00160 }
00161 for( i = 0; i < (n-1); i++ ) {
00162 e_i[i] = e_save[i];
00163 }
00164 for( i = 0; i < ldz*n; i++ ) {
00165 z_i[i] = z_save[i];
00166 }
00167 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00168 work_i[i] = work[i];
00169 }
00170 info_i = LAPACKE_ssteqr( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00171 ldz_i );
00172
00173 failed = compare_ssteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00174 n );
00175 if( failed == 0 ) {
00176 printf( "PASSED: column-major high-level interface to ssteqr\n" );
00177 } else {
00178 printf( "FAILED: column-major high-level interface to ssteqr\n" );
00179 }
00180
00181
00182
00183 for( i = 0; i < n; i++ ) {
00184 d_i[i] = d_save[i];
00185 }
00186 for( i = 0; i < (n-1); i++ ) {
00187 e_i[i] = e_save[i];
00188 }
00189 for( i = 0; i < ldz*n; i++ ) {
00190 z_i[i] = z_save[i];
00191 }
00192 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00193 work_i[i] = work[i];
00194 }
00195
00196 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00197 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00198 }
00199 info_i = LAPACKE_ssteqr_work( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00200 ldz_r, work_i );
00201
00202 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00203 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00204 }
00205
00206 failed = compare_ssteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00207 n );
00208 if( failed == 0 ) {
00209 printf( "PASSED: row-major middle-level interface to ssteqr\n" );
00210 } else {
00211 printf( "FAILED: row-major middle-level interface to ssteqr\n" );
00212 }
00213
00214
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 < ldz*n; i++ ) {
00223 z_i[i] = z_save[i];
00224 }
00225 for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00226 work_i[i] = work[i];
00227 }
00228
00229
00230 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00231 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00232 }
00233 info_i = LAPACKE_ssteqr( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00234 ldz_r );
00235
00236 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00237 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00238 }
00239
00240 failed = compare_ssteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00241 n );
00242 if( failed == 0 ) {
00243 printf( "PASSED: row-major high-level interface to ssteqr\n" );
00244 } else {
00245 printf( "FAILED: row-major high-level interface to ssteqr\n" );
00246 }
00247
00248
00249 if( d != NULL ) {
00250 LAPACKE_free( d );
00251 }
00252 if( d_i != NULL ) {
00253 LAPACKE_free( d_i );
00254 }
00255 if( d_save != NULL ) {
00256 LAPACKE_free( d_save );
00257 }
00258 if( e != NULL ) {
00259 LAPACKE_free( e );
00260 }
00261 if( e_i != NULL ) {
00262 LAPACKE_free( e_i );
00263 }
00264 if( e_save != NULL ) {
00265 LAPACKE_free( e_save );
00266 }
00267 if( z != NULL ) {
00268 LAPACKE_free( z );
00269 }
00270 if( z_i != NULL ) {
00271 LAPACKE_free( z_i );
00272 }
00273 if( z_r != NULL ) {
00274 LAPACKE_free( z_r );
00275 }
00276 if( z_save != NULL ) {
00277 LAPACKE_free( z_save );
00278 }
00279 if( work != NULL ) {
00280 LAPACKE_free( work );
00281 }
00282 if( work_i != NULL ) {
00283 LAPACKE_free( work_i );
00284 }
00285
00286 return 0;
00287 }
00288
00289
00290 static void init_scalars_ssteqr( char *compz, lapack_int *n, lapack_int *ldz )
00291 {
00292 *compz = 'V';
00293 *n = 4;
00294 *ldz = 8;
00295
00296 return;
00297 }
00298
00299
00300 static void init_d( lapack_int size, float *d ) {
00301 lapack_int i;
00302 for( i = 0; i < size; i++ ) {
00303 d[i] = 0;
00304 }
00305 d[0] = 4.989999771e+000;
00306 d[1] = -2.480559826e+000;
00307 d[2] = -6.611364335e-002;
00308 d[3] = 8.566736579e-001;
00309 }
00310 static void init_e( lapack_int size, float *e ) {
00311 lapack_int i;
00312 for( i = 0; i < size; i++ ) {
00313 e[i] = 0;
00314 }
00315 e[0] = 2.236067951e-001;
00316 e[1] = 1.102975368e+000;
00317 e[2] = 1.430096507e+000;
00318 }
00319 static void init_z( lapack_int size, float *z ) {
00320 lapack_int i;
00321 for( i = 0; i < size; i++ ) {
00322 z[i] = 0;
00323 }
00324 z[0] = 1.000000000e+000;
00325 z[8] = 0.000000000e+000;
00326 z[16] = 0.000000000e+000;
00327 z[24] = 0.000000000e+000;
00328 z[1] = 0.000000000e+000;
00329 z[9] = 1.788854301e-001;
00330 z[17] = -1.320895553e-001;
00331 z[25] = -9.749627709e-001;
00332 z[2] = 0.000000000e+000;
00333 z[10] = 9.838699102e-001;
00334 z[18] = 2.401627973e-002;
00335 z[26] = 1.772659570e-001;
00336 z[3] = 0.000000000e+000;
00337 z[11] = 0.000000000e+000;
00338 z[19] = -9.909468293e-001;
00339 z[27] = 1.342550963e-001;
00340 }
00341 static void init_work( lapack_int size, float *work ) {
00342 lapack_int i;
00343 for( i = 0; i < size; i++ ) {
00344 work[i] = 0;
00345 }
00346 }
00347
00348
00349
00350 static int compare_ssteqr( float *d, float *d_i, float *e, float *e_i, float *z,
00351 float *z_i, lapack_int info, lapack_int info_i,
00352 char compz, lapack_int ldz, lapack_int n )
00353 {
00354 lapack_int i;
00355 int failed = 0;
00356 for( i = 0; i < n; i++ ) {
00357 failed += compare_floats(d[i],d_i[i]);
00358 }
00359 for( i = 0; i < (n-1); i++ ) {
00360 failed += compare_floats(e[i],e_i[i]);
00361 }
00362 if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00363 for( i = 0; i < ldz*n; i++ ) {
00364 failed += compare_floats(z[i],z_i[i]);
00365 }
00366 }
00367 failed += (info == info_i) ? 0 : 1;
00368 if( info != 0 || info_i != 0 ) {
00369 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00370 }
00371
00372 return failed;
00373 }