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_stprfs( char *uplo, char *trans, char *diag,
00055 lapack_int *n, lapack_int *nrhs,
00056 lapack_int *ldb, lapack_int *ldx );
00057 static void init_ap( lapack_int size, float *ap );
00058 static void init_b( lapack_int size, float *b );
00059 static void init_x( lapack_int size, float *x );
00060 static void init_ferr( lapack_int size, float *ferr );
00061 static void init_berr( lapack_int size, float *berr );
00062 static void init_work( lapack_int size, float *work );
00063 static void init_iwork( lapack_int size, lapack_int *iwork );
00064 static int compare_stprfs( float *ferr, float *ferr_i, float *berr,
00065 float *berr_i, lapack_int info, lapack_int info_i,
00066 lapack_int nrhs );
00067
00068 int main(void)
00069 {
00070
00071 char uplo, uplo_i;
00072 char trans, trans_i;
00073 char diag, diag_i;
00074 lapack_int n, n_i;
00075 lapack_int nrhs, nrhs_i;
00076 lapack_int ldb, ldb_i;
00077 lapack_int ldb_r;
00078 lapack_int ldx, ldx_i;
00079 lapack_int ldx_r;
00080 lapack_int info, info_i;
00081 lapack_int i;
00082 int failed;
00083
00084
00085 float *ap = NULL, *ap_i = NULL;
00086 float *b = NULL, *b_i = NULL;
00087 float *x = NULL, *x_i = NULL;
00088 float *ferr = NULL, *ferr_i = NULL;
00089 float *berr = NULL, *berr_i = NULL;
00090 float *work = NULL, *work_i = NULL;
00091 lapack_int *iwork = NULL, *iwork_i = NULL;
00092 float *ferr_save = NULL;
00093 float *berr_save = NULL;
00094 float *ap_r = NULL;
00095 float *b_r = NULL;
00096 float *x_r = NULL;
00097
00098
00099 init_scalars_stprfs( &uplo, &trans, &diag, &n, &nrhs, &ldb, &ldx );
00100 ldb_r = nrhs+2;
00101 ldx_r = nrhs+2;
00102 uplo_i = uplo;
00103 trans_i = trans;
00104 diag_i = diag;
00105 n_i = n;
00106 nrhs_i = nrhs;
00107 ldb_i = ldb;
00108 ldx_i = ldx;
00109
00110
00111 ap = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00112 b = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00113 x = (float *)LAPACKE_malloc( ldx*nrhs * sizeof(float) );
00114 ferr = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00115 berr = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00116 work = (float *)LAPACKE_malloc( 3*n * sizeof(float) );
00117 iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00118
00119
00120 ap_i = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00121 b_i = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00122 x_i = (float *)LAPACKE_malloc( ldx*nrhs * sizeof(float) );
00123 ferr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00124 berr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00125 work_i = (float *)LAPACKE_malloc( 3*n * sizeof(float) );
00126 iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00127
00128
00129 ferr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00130 berr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00131
00132
00133 ap_r = (float *)LAPACKE_malloc( n*(n+1)/2 * sizeof(float) );
00134 b_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00135 x_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00136
00137
00138 init_ap( (n*(n+1)/2), ap );
00139 init_b( ldb*nrhs, b );
00140 init_x( ldx*nrhs, x );
00141 init_ferr( nrhs, ferr );
00142 init_berr( nrhs, berr );
00143 init_work( 3*n, work );
00144 init_iwork( n, iwork );
00145
00146
00147 for( i = 0; i < nrhs; i++ ) {
00148 ferr_save[i] = ferr[i];
00149 }
00150 for( i = 0; i < nrhs; i++ ) {
00151 berr_save[i] = berr[i];
00152 }
00153
00154
00155 stprfs_( &uplo, &trans, &diag, &n, &nrhs, ap, b, &ldb, x, &ldx, ferr, berr,
00156 work, iwork, &info );
00157
00158
00159
00160 for( i = 0; i < (n*(n+1)/2); i++ ) {
00161 ap_i[i] = ap[i];
00162 }
00163 for( i = 0; i < ldb*nrhs; i++ ) {
00164 b_i[i] = b[i];
00165 }
00166 for( i = 0; i < ldx*nrhs; i++ ) {
00167 x_i[i] = x[i];
00168 }
00169 for( i = 0; i < nrhs; i++ ) {
00170 ferr_i[i] = ferr_save[i];
00171 }
00172 for( i = 0; i < nrhs; i++ ) {
00173 berr_i[i] = berr_save[i];
00174 }
00175 for( i = 0; i < 3*n; i++ ) {
00176 work_i[i] = work[i];
00177 }
00178 for( i = 0; i < n; i++ ) {
00179 iwork_i[i] = iwork[i];
00180 }
00181 info_i = LAPACKE_stprfs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00182 n_i, nrhs_i, ap_i, b_i, ldb_i, x_i, ldx_i,
00183 ferr_i, berr_i, work_i, iwork_i );
00184
00185 failed = compare_stprfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00186 if( failed == 0 ) {
00187 printf( "PASSED: column-major middle-level interface to stprfs\n" );
00188 } else {
00189 printf( "FAILED: column-major middle-level interface to stprfs\n" );
00190 }
00191
00192
00193
00194 for( i = 0; i < (n*(n+1)/2); i++ ) {
00195 ap_i[i] = ap[i];
00196 }
00197 for( i = 0; i < ldb*nrhs; i++ ) {
00198 b_i[i] = b[i];
00199 }
00200 for( i = 0; i < ldx*nrhs; i++ ) {
00201 x_i[i] = x[i];
00202 }
00203 for( i = 0; i < nrhs; i++ ) {
00204 ferr_i[i] = ferr_save[i];
00205 }
00206 for( i = 0; i < nrhs; i++ ) {
00207 berr_i[i] = berr_save[i];
00208 }
00209 for( i = 0; i < 3*n; i++ ) {
00210 work_i[i] = work[i];
00211 }
00212 for( i = 0; i < n; i++ ) {
00213 iwork_i[i] = iwork[i];
00214 }
00215 info_i = LAPACKE_stprfs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00216 nrhs_i, ap_i, b_i, ldb_i, x_i, ldx_i, ferr_i,
00217 berr_i );
00218
00219 failed = compare_stprfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00220 if( failed == 0 ) {
00221 printf( "PASSED: column-major high-level interface to stprfs\n" );
00222 } else {
00223 printf( "FAILED: column-major high-level interface to stprfs\n" );
00224 }
00225
00226
00227
00228 for( i = 0; i < (n*(n+1)/2); i++ ) {
00229 ap_i[i] = ap[i];
00230 }
00231 for( i = 0; i < ldb*nrhs; i++ ) {
00232 b_i[i] = b[i];
00233 }
00234 for( i = 0; i < ldx*nrhs; i++ ) {
00235 x_i[i] = x[i];
00236 }
00237 for( i = 0; i < nrhs; i++ ) {
00238 ferr_i[i] = ferr_save[i];
00239 }
00240 for( i = 0; i < nrhs; i++ ) {
00241 berr_i[i] = berr_save[i];
00242 }
00243 for( i = 0; i < 3*n; i++ ) {
00244 work_i[i] = work[i];
00245 }
00246 for( i = 0; i < n; i++ ) {
00247 iwork_i[i] = iwork[i];
00248 }
00249
00250 LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00251 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00252 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00253 info_i = LAPACKE_stprfs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00254 n_i, nrhs_i, ap_r, b_r, ldb_r, x_r, ldx_r,
00255 ferr_i, berr_i, work_i, iwork_i );
00256
00257 failed = compare_stprfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00258 if( failed == 0 ) {
00259 printf( "PASSED: row-major middle-level interface to stprfs\n" );
00260 } else {
00261 printf( "FAILED: row-major middle-level interface to stprfs\n" );
00262 }
00263
00264
00265
00266 for( i = 0; i < (n*(n+1)/2); i++ ) {
00267 ap_i[i] = ap[i];
00268 }
00269 for( i = 0; i < ldb*nrhs; i++ ) {
00270 b_i[i] = b[i];
00271 }
00272 for( i = 0; i < ldx*nrhs; i++ ) {
00273 x_i[i] = x[i];
00274 }
00275 for( i = 0; i < nrhs; i++ ) {
00276 ferr_i[i] = ferr_save[i];
00277 }
00278 for( i = 0; i < nrhs; i++ ) {
00279 berr_i[i] = berr_save[i];
00280 }
00281 for( i = 0; i < 3*n; i++ ) {
00282 work_i[i] = work[i];
00283 }
00284 for( i = 0; i < n; i++ ) {
00285 iwork_i[i] = iwork[i];
00286 }
00287
00288
00289 LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00290 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00291 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00292 info_i = LAPACKE_stprfs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00293 nrhs_i, ap_r, b_r, ldb_r, x_r, ldx_r, ferr_i,
00294 berr_i );
00295
00296 failed = compare_stprfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00297 if( failed == 0 ) {
00298 printf( "PASSED: row-major high-level interface to stprfs\n" );
00299 } else {
00300 printf( "FAILED: row-major high-level interface to stprfs\n" );
00301 }
00302
00303
00304 if( ap != NULL ) {
00305 LAPACKE_free( ap );
00306 }
00307 if( ap_i != NULL ) {
00308 LAPACKE_free( ap_i );
00309 }
00310 if( ap_r != NULL ) {
00311 LAPACKE_free( ap_r );
00312 }
00313 if( b != NULL ) {
00314 LAPACKE_free( b );
00315 }
00316 if( b_i != NULL ) {
00317 LAPACKE_free( b_i );
00318 }
00319 if( b_r != NULL ) {
00320 LAPACKE_free( b_r );
00321 }
00322 if( x != NULL ) {
00323 LAPACKE_free( x );
00324 }
00325 if( x_i != NULL ) {
00326 LAPACKE_free( x_i );
00327 }
00328 if( x_r != NULL ) {
00329 LAPACKE_free( x_r );
00330 }
00331 if( ferr != NULL ) {
00332 LAPACKE_free( ferr );
00333 }
00334 if( ferr_i != NULL ) {
00335 LAPACKE_free( ferr_i );
00336 }
00337 if( ferr_save != NULL ) {
00338 LAPACKE_free( ferr_save );
00339 }
00340 if( berr != NULL ) {
00341 LAPACKE_free( berr );
00342 }
00343 if( berr_i != NULL ) {
00344 LAPACKE_free( berr_i );
00345 }
00346 if( berr_save != NULL ) {
00347 LAPACKE_free( berr_save );
00348 }
00349 if( work != NULL ) {
00350 LAPACKE_free( work );
00351 }
00352 if( work_i != NULL ) {
00353 LAPACKE_free( work_i );
00354 }
00355 if( iwork != NULL ) {
00356 LAPACKE_free( iwork );
00357 }
00358 if( iwork_i != NULL ) {
00359 LAPACKE_free( iwork_i );
00360 }
00361
00362 return 0;
00363 }
00364
00365
00366 static void init_scalars_stprfs( char *uplo, char *trans, char *diag,
00367 lapack_int *n, lapack_int *nrhs,
00368 lapack_int *ldb, lapack_int *ldx )
00369 {
00370 *uplo = 'L';
00371 *trans = 'N';
00372 *diag = 'N';
00373 *n = 4;
00374 *nrhs = 2;
00375 *ldb = 8;
00376 *ldx = 8;
00377
00378 return;
00379 }
00380
00381
00382 static void init_ap( lapack_int size, float *ap ) {
00383 lapack_int i;
00384 for( i = 0; i < size; i++ ) {
00385 ap[i] = 0;
00386 }
00387 ap[0] = 4.300000191e+000;
00388 ap[1] = -3.960000038e+000;
00389 ap[2] = 4.000000060e-001;
00390 ap[3] = -2.700000107e-001;
00391 ap[4] = -4.869999886e+000;
00392 ap[5] = 3.100000024e-001;
00393 ap[6] = 7.000000030e-002;
00394 ap[7] = -8.020000458e+000;
00395 ap[8] = -5.949999809e+000;
00396 ap[9] = 1.199999973e-001;
00397 }
00398 static void init_b( lapack_int size, float *b ) {
00399 lapack_int i;
00400 for( i = 0; i < size; i++ ) {
00401 b[i] = 0;
00402 }
00403 b[0] = -1.289999962e+001;
00404 b[8] = -2.150000000e+001;
00405 b[1] = 1.675000000e+001;
00406 b[9] = 1.493000031e+001;
00407 b[2] = -1.754999924e+001;
00408 b[10] = 6.329999924e+000;
00409 b[3] = -1.103999996e+001;
00410 b[11] = 8.090000153e+000;
00411 }
00412 static void init_x( lapack_int size, float *x ) {
00413 lapack_int i;
00414 for( i = 0; i < size; i++ ) {
00415 x[i] = 0;
00416 }
00417 x[0] = -2.999999762e+000;
00418 x[8] = -5.000000000e+000;
00419 x[1] = -1.000000238e+000;
00420 x[9] = 9.999998212e-001;
00421 x[2] = 1.999999762e+000;
00422 x[10] = -1.000000000e+000;
00423 x[3] = 9.999831915e-001;
00424 x[11] = 6.000002384e+000;
00425 }
00426 static void init_ferr( lapack_int size, float *ferr ) {
00427 lapack_int i;
00428 for( i = 0; i < size; i++ ) {
00429 ferr[i] = 0;
00430 }
00431 }
00432 static void init_berr( lapack_int size, float *berr ) {
00433 lapack_int i;
00434 for( i = 0; i < size; i++ ) {
00435 berr[i] = 0;
00436 }
00437 }
00438 static void init_work( lapack_int size, float *work ) {
00439 lapack_int i;
00440 for( i = 0; i < size; i++ ) {
00441 work[i] = 0;
00442 }
00443 }
00444 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00445 lapack_int i;
00446 for( i = 0; i < size; i++ ) {
00447 iwork[i] = 0;
00448 }
00449 }
00450
00451
00452
00453 static int compare_stprfs( float *ferr, float *ferr_i, float *berr,
00454 float *berr_i, lapack_int info, lapack_int info_i,
00455 lapack_int nrhs )
00456 {
00457 lapack_int i;
00458 int failed = 0;
00459 for( i = 0; i < nrhs; i++ ) {
00460 failed += compare_floats(ferr[i],ferr_i[i]);
00461 }
00462 for( i = 0; i < nrhs; i++ ) {
00463 failed += compare_floats(berr[i],berr_i[i]);
00464 }
00465 failed += (info == info_i) ? 0 : 1;
00466 if( info != 0 || info_i != 0 ) {
00467 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00468 }
00469
00470 return failed;
00471 }