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_dstein( lapack_int *n, lapack_int *m,
00055 lapack_int *ldz );
00056 static void init_d( lapack_int size, double *d );
00057 static void init_e( lapack_int size, double *e );
00058 static void init_w( lapack_int size, double *w );
00059 static void init_iblock( lapack_int size, lapack_int *iblock );
00060 static void init_isplit( lapack_int size, lapack_int *isplit );
00061 static void init_z( lapack_int size, double *z );
00062 static void init_work( lapack_int size, double *work );
00063 static void init_iwork( lapack_int size, lapack_int *iwork );
00064 static void init_ifailv( lapack_int size, lapack_int *ifailv );
00065 static int compare_dstein( double *z, double *z_i, lapack_int *ifailv,
00066 lapack_int *ifailv_i, lapack_int info,
00067 lapack_int info_i, lapack_int ldz, lapack_int m );
00068
00069 int main(void)
00070 {
00071
00072 lapack_int n, n_i;
00073 lapack_int m, m_i;
00074 lapack_int ldz, ldz_i;
00075 lapack_int ldz_r;
00076 lapack_int info, info_i;
00077 lapack_int i;
00078 int failed;
00079
00080
00081 double *d = NULL, *d_i = NULL;
00082 double *e = NULL, *e_i = NULL;
00083 double *w = NULL, *w_i = NULL;
00084 lapack_int *iblock = NULL, *iblock_i = NULL;
00085 lapack_int *isplit = NULL, *isplit_i = NULL;
00086 double *z = NULL, *z_i = NULL;
00087 double *work = NULL, *work_i = NULL;
00088 lapack_int *iwork = NULL, *iwork_i = NULL;
00089 lapack_int *ifailv = NULL, *ifailv_i = NULL;
00090 double *z_save = NULL;
00091 lapack_int *ifailv_save = NULL;
00092 double *z_r = NULL;
00093
00094
00095 init_scalars_dstein( &n, &m, &ldz );
00096 ldz_r = m+2;
00097 n_i = n;
00098 m_i = m;
00099 ldz_i = ldz;
00100
00101
00102 d = (double *)LAPACKE_malloc( n * sizeof(double) );
00103 e = (double *)LAPACKE_malloc( n * sizeof(double) );
00104 w = (double *)LAPACKE_malloc( n * sizeof(double) );
00105 iblock = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00106 isplit = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00107 z = (double *)LAPACKE_malloc( ldz*m * sizeof(double) );
00108 work = (double *)LAPACKE_malloc( 5*n * sizeof(double) );
00109 iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00110 ifailv = (lapack_int *)LAPACKE_malloc( m * sizeof(lapack_int) );
00111
00112
00113 d_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00114 e_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00115 w_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00116 iblock_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00117 isplit_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00118 z_i = (double *)LAPACKE_malloc( ldz*m * sizeof(double) );
00119 work_i = (double *)LAPACKE_malloc( 5*n * sizeof(double) );
00120 iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00121 ifailv_i = (lapack_int *)LAPACKE_malloc( m * sizeof(lapack_int) );
00122
00123
00124 z_save = (double *)LAPACKE_malloc( ldz*m * sizeof(double) );
00125 ifailv_save = (lapack_int *)LAPACKE_malloc( m * sizeof(lapack_int) );
00126
00127
00128 z_r = (double *)LAPACKE_malloc( n*(m+2) * sizeof(double) );
00129
00130
00131 init_d( n, d );
00132 init_e( n, e );
00133 init_w( n, w );
00134 init_iblock( n, iblock );
00135 init_isplit( n, isplit );
00136 init_z( ldz*m, z );
00137 init_work( 5*n, work );
00138 init_iwork( n, iwork );
00139 init_ifailv( m, ifailv );
00140
00141
00142 for( i = 0; i < ldz*m; i++ ) {
00143 z_save[i] = z[i];
00144 }
00145 for( i = 0; i < m; i++ ) {
00146 ifailv_save[i] = ifailv[i];
00147 }
00148
00149
00150 dstein_( &n, d, e, &m, w, iblock, isplit, z, &ldz, work, iwork, ifailv,
00151 &info );
00152
00153
00154
00155 for( i = 0; i < n; i++ ) {
00156 d_i[i] = d[i];
00157 }
00158 for( i = 0; i < n; i++ ) {
00159 e_i[i] = e[i];
00160 }
00161 for( i = 0; i < n; i++ ) {
00162 w_i[i] = w[i];
00163 }
00164 for( i = 0; i < n; i++ ) {
00165 iblock_i[i] = iblock[i];
00166 }
00167 for( i = 0; i < n; i++ ) {
00168 isplit_i[i] = isplit[i];
00169 }
00170 for( i = 0; i < ldz*m; i++ ) {
00171 z_i[i] = z_save[i];
00172 }
00173 for( i = 0; i < 5*n; i++ ) {
00174 work_i[i] = work[i];
00175 }
00176 for( i = 0; i < n; i++ ) {
00177 iwork_i[i] = iwork[i];
00178 }
00179 for( i = 0; i < m; i++ ) {
00180 ifailv_i[i] = ifailv_save[i];
00181 }
00182 info_i = LAPACKE_dstein_work( LAPACK_COL_MAJOR, n_i, d_i, e_i, m_i, w_i,
00183 iblock_i, isplit_i, z_i, ldz_i, work_i,
00184 iwork_i, ifailv_i );
00185
00186 failed = compare_dstein( z, z_i, ifailv, ifailv_i, info, info_i, ldz, m );
00187 if( failed == 0 ) {
00188 printf( "PASSED: column-major middle-level interface to dstein\n" );
00189 } else {
00190 printf( "FAILED: column-major middle-level interface to dstein\n" );
00191 }
00192
00193
00194
00195 for( i = 0; i < n; i++ ) {
00196 d_i[i] = d[i];
00197 }
00198 for( i = 0; i < n; i++ ) {
00199 e_i[i] = e[i];
00200 }
00201 for( i = 0; i < n; i++ ) {
00202 w_i[i] = w[i];
00203 }
00204 for( i = 0; i < n; i++ ) {
00205 iblock_i[i] = iblock[i];
00206 }
00207 for( i = 0; i < n; i++ ) {
00208 isplit_i[i] = isplit[i];
00209 }
00210 for( i = 0; i < ldz*m; i++ ) {
00211 z_i[i] = z_save[i];
00212 }
00213 for( i = 0; i < 5*n; i++ ) {
00214 work_i[i] = work[i];
00215 }
00216 for( i = 0; i < n; i++ ) {
00217 iwork_i[i] = iwork[i];
00218 }
00219 for( i = 0; i < m; i++ ) {
00220 ifailv_i[i] = ifailv_save[i];
00221 }
00222 info_i = LAPACKE_dstein( LAPACK_COL_MAJOR, n_i, d_i, e_i, m_i, w_i,
00223 iblock_i, isplit_i, z_i, ldz_i, ifailv_i );
00224
00225 failed = compare_dstein( z, z_i, ifailv, ifailv_i, info, info_i, ldz, m );
00226 if( failed == 0 ) {
00227 printf( "PASSED: column-major high-level interface to dstein\n" );
00228 } else {
00229 printf( "FAILED: column-major high-level interface to dstein\n" );
00230 }
00231
00232
00233
00234 for( i = 0; i < n; i++ ) {
00235 d_i[i] = d[i];
00236 }
00237 for( i = 0; i < n; i++ ) {
00238 e_i[i] = e[i];
00239 }
00240 for( i = 0; i < n; i++ ) {
00241 w_i[i] = w[i];
00242 }
00243 for( i = 0; i < n; i++ ) {
00244 iblock_i[i] = iblock[i];
00245 }
00246 for( i = 0; i < n; i++ ) {
00247 isplit_i[i] = isplit[i];
00248 }
00249 for( i = 0; i < ldz*m; i++ ) {
00250 z_i[i] = z_save[i];
00251 }
00252 for( i = 0; i < 5*n; i++ ) {
00253 work_i[i] = work[i];
00254 }
00255 for( i = 0; i < n; i++ ) {
00256 iwork_i[i] = iwork[i];
00257 }
00258 for( i = 0; i < m; i++ ) {
00259 ifailv_i[i] = ifailv_save[i];
00260 }
00261
00262 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, m, z_i, ldz, z_r, m+2 );
00263 info_i = LAPACKE_dstein_work( LAPACK_ROW_MAJOR, n_i, d_i, e_i, m_i, w_i,
00264 iblock_i, isplit_i, z_r, ldz_r, work_i,
00265 iwork_i, ifailv_i );
00266
00267 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, m, z_r, m+2, z_i, ldz );
00268
00269 failed = compare_dstein( z, z_i, ifailv, ifailv_i, info, info_i, ldz, m );
00270 if( failed == 0 ) {
00271 printf( "PASSED: row-major middle-level interface to dstein\n" );
00272 } else {
00273 printf( "FAILED: row-major middle-level interface to dstein\n" );
00274 }
00275
00276
00277
00278 for( i = 0; i < n; i++ ) {
00279 d_i[i] = d[i];
00280 }
00281 for( i = 0; i < n; i++ ) {
00282 e_i[i] = e[i];
00283 }
00284 for( i = 0; i < n; i++ ) {
00285 w_i[i] = w[i];
00286 }
00287 for( i = 0; i < n; i++ ) {
00288 iblock_i[i] = iblock[i];
00289 }
00290 for( i = 0; i < n; i++ ) {
00291 isplit_i[i] = isplit[i];
00292 }
00293 for( i = 0; i < ldz*m; i++ ) {
00294 z_i[i] = z_save[i];
00295 }
00296 for( i = 0; i < 5*n; i++ ) {
00297 work_i[i] = work[i];
00298 }
00299 for( i = 0; i < n; i++ ) {
00300 iwork_i[i] = iwork[i];
00301 }
00302 for( i = 0; i < m; i++ ) {
00303 ifailv_i[i] = ifailv_save[i];
00304 }
00305
00306
00307 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, m, z_i, ldz, z_r, m+2 );
00308 info_i = LAPACKE_dstein( LAPACK_ROW_MAJOR, n_i, d_i, e_i, m_i, w_i,
00309 iblock_i, isplit_i, z_r, ldz_r, ifailv_i );
00310
00311 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, m, z_r, m+2, z_i, ldz );
00312
00313 failed = compare_dstein( z, z_i, ifailv, ifailv_i, info, info_i, ldz, m );
00314 if( failed == 0 ) {
00315 printf( "PASSED: row-major high-level interface to dstein\n" );
00316 } else {
00317 printf( "FAILED: row-major high-level interface to dstein\n" );
00318 }
00319
00320
00321 if( d != NULL ) {
00322 LAPACKE_free( d );
00323 }
00324 if( d_i != NULL ) {
00325 LAPACKE_free( d_i );
00326 }
00327 if( e != NULL ) {
00328 LAPACKE_free( e );
00329 }
00330 if( e_i != NULL ) {
00331 LAPACKE_free( e_i );
00332 }
00333 if( w != NULL ) {
00334 LAPACKE_free( w );
00335 }
00336 if( w_i != NULL ) {
00337 LAPACKE_free( w_i );
00338 }
00339 if( iblock != NULL ) {
00340 LAPACKE_free( iblock );
00341 }
00342 if( iblock_i != NULL ) {
00343 LAPACKE_free( iblock_i );
00344 }
00345 if( isplit != NULL ) {
00346 LAPACKE_free( isplit );
00347 }
00348 if( isplit_i != NULL ) {
00349 LAPACKE_free( isplit_i );
00350 }
00351 if( z != NULL ) {
00352 LAPACKE_free( z );
00353 }
00354 if( z_i != NULL ) {
00355 LAPACKE_free( z_i );
00356 }
00357 if( z_r != NULL ) {
00358 LAPACKE_free( z_r );
00359 }
00360 if( z_save != NULL ) {
00361 LAPACKE_free( z_save );
00362 }
00363 if( work != NULL ) {
00364 LAPACKE_free( work );
00365 }
00366 if( work_i != NULL ) {
00367 LAPACKE_free( work_i );
00368 }
00369 if( iwork != NULL ) {
00370 LAPACKE_free( iwork );
00371 }
00372 if( iwork_i != NULL ) {
00373 LAPACKE_free( iwork_i );
00374 }
00375 if( ifailv != NULL ) {
00376 LAPACKE_free( ifailv );
00377 }
00378 if( ifailv_i != NULL ) {
00379 LAPACKE_free( ifailv_i );
00380 }
00381 if( ifailv_save != NULL ) {
00382 LAPACKE_free( ifailv_save );
00383 }
00384
00385 return 0;
00386 }
00387
00388
00389 static void init_scalars_dstein( lapack_int *n, lapack_int *m, lapack_int *ldz )
00390 {
00391 *n = 4;
00392 *m = 2;
00393 *ldz = 8;
00394
00395 return;
00396 }
00397
00398
00399 static void init_d( lapack_int size, double *d ) {
00400 lapack_int i;
00401 for( i = 0; i < size; i++ ) {
00402 d[i] = 0;
00403 }
00404 d[0] = 2.06999999999999980e+000;
00405 d[1] = 1.47409370819755310e+000;
00406 d[2] = -6.49159507545784330e-001;
00407 d[3] = -1.69493420065176800e+000;
00408 }
00409 static void init_e( lapack_int size, double *e ) {
00410 lapack_int i;
00411 for( i = 0; i < size; i++ ) {
00412 e[i] = 0;
00413 }
00414 e[0] = -5.82575317019181590e+000;
00415 e[1] = 2.62404517879558740e+000;
00416 e[2] = 9.16272756321918620e-001;
00417 e[3] = 0.00000000000000000e+000;
00418 }
00419 static void init_w( lapack_int size, double *w ) {
00420 lapack_int i;
00421 for( i = 0; i < size; i++ ) {
00422 w[i] = 0;
00423 }
00424 w[0] = -5.00335314549203240e+000;
00425 w[1] = -1.99870457480866890e+000;
00426 w[2] = 0.00000000000000000e+000;
00427 w[3] = 0.00000000000000000e+000;
00428 }
00429 static void init_iblock( lapack_int size, lapack_int *iblock ) {
00430 lapack_int i;
00431 for( i = 0; i < size; i++ ) {
00432 iblock[i] = 0;
00433 }
00434 iblock[0] = 1;
00435 iblock[1] = 1;
00436 iblock[2] = 0;
00437 iblock[3] = 0;
00438 }
00439 static void init_isplit( lapack_int size, lapack_int *isplit ) {
00440 lapack_int i;
00441 for( i = 0; i < size; i++ ) {
00442 isplit[i] = 0;
00443 }
00444 isplit[0] = 4;
00445 isplit[1] = 0;
00446 isplit[2] = 0;
00447 isplit[3] = 0;
00448 }
00449 static void init_z( lapack_int size, double *z ) {
00450 lapack_int i;
00451 for( i = 0; i < size; i++ ) {
00452 z[i] = 0;
00453 }
00454 }
00455 static void init_work( lapack_int size, double *work ) {
00456 lapack_int i;
00457 for( i = 0; i < size; i++ ) {
00458 work[i] = 0;
00459 }
00460 }
00461 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00462 lapack_int i;
00463 for( i = 0; i < size; i++ ) {
00464 iwork[i] = 0;
00465 }
00466 }
00467 static void init_ifailv( lapack_int size, lapack_int *ifailv ) {
00468 lapack_int i;
00469 for( i = 0; i < size; i++ ) {
00470 ifailv[i] = 0;
00471 }
00472 }
00473
00474
00475
00476 static int compare_dstein( double *z, double *z_i, lapack_int *ifailv,
00477 lapack_int *ifailv_i, lapack_int info,
00478 lapack_int info_i, lapack_int ldz, lapack_int m )
00479 {
00480 lapack_int i;
00481 int failed = 0;
00482 for( i = 0; i < ldz*m; i++ ) {
00483 failed += compare_doubles(z[i],z_i[i]);
00484 }
00485 for( i = 0; i < m; i++ ) {
00486 failed += (ifailv[i] == ifailv_i[i]) ? 0 : 1;
00487 }
00488 failed += (info == info_i) ? 0 : 1;
00489 if( info != 0 || info_i != 0 ) {
00490 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00491 }
00492
00493 return failed;
00494 }