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_spbtrs( char *uplo, lapack_int *n, lapack_int *kd,
00055 lapack_int *nrhs, lapack_int *ldab,
00056 lapack_int *ldb );
00057 static void init_ab( lapack_int size, float *ab );
00058 static void init_b( lapack_int size, float *b );
00059 static int compare_spbtrs( float *b, float *b_i, lapack_int info,
00060 lapack_int info_i, lapack_int ldb, lapack_int nrhs );
00061
00062 int main(void)
00063 {
00064
00065 char uplo, uplo_i;
00066 lapack_int n, n_i;
00067 lapack_int kd, kd_i;
00068 lapack_int nrhs, nrhs_i;
00069 lapack_int ldab, ldab_i;
00070 lapack_int ldab_r;
00071 lapack_int ldb, ldb_i;
00072 lapack_int ldb_r;
00073 lapack_int info, info_i;
00074 lapack_int i;
00075 int failed;
00076
00077
00078 float *ab = NULL, *ab_i = NULL;
00079 float *b = NULL, *b_i = NULL;
00080 float *b_save = NULL;
00081 float *ab_r = NULL;
00082 float *b_r = NULL;
00083
00084
00085 init_scalars_spbtrs( &uplo, &n, &kd, &nrhs, &ldab, &ldb );
00086 ldab_r = n+2;
00087 ldb_r = nrhs+2;
00088 uplo_i = uplo;
00089 n_i = n;
00090 kd_i = kd;
00091 nrhs_i = nrhs;
00092 ldab_i = ldab;
00093 ldb_i = ldb;
00094
00095
00096 ab = (float *)LAPACKE_malloc( ldab*n * sizeof(float) );
00097 b = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00098
00099
00100 ab_i = (float *)LAPACKE_malloc( ldab*n * sizeof(float) );
00101 b_i = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00102
00103
00104 b_save = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00105
00106
00107 ab_r = (float *)LAPACKE_malloc( (kd+1)*(n+2) * sizeof(float) );
00108 b_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00109
00110
00111 init_ab( ldab*n, ab );
00112 init_b( ldb*nrhs, b );
00113
00114
00115 for( i = 0; i < ldb*nrhs; i++ ) {
00116 b_save[i] = b[i];
00117 }
00118
00119
00120 spbtrs_( &uplo, &n, &kd, &nrhs, ab, &ldab, b, &ldb, &info );
00121
00122
00123
00124 for( i = 0; i < ldab*n; i++ ) {
00125 ab_i[i] = ab[i];
00126 }
00127 for( i = 0; i < ldb*nrhs; i++ ) {
00128 b_i[i] = b_save[i];
00129 }
00130 info_i = LAPACKE_spbtrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, kd_i, nrhs_i,
00131 ab_i, ldab_i, b_i, ldb_i );
00132
00133 failed = compare_spbtrs( b, b_i, info, info_i, ldb, nrhs );
00134 if( failed == 0 ) {
00135 printf( "PASSED: column-major middle-level interface to spbtrs\n" );
00136 } else {
00137 printf( "FAILED: column-major middle-level interface to spbtrs\n" );
00138 }
00139
00140
00141
00142 for( i = 0; i < ldab*n; i++ ) {
00143 ab_i[i] = ab[i];
00144 }
00145 for( i = 0; i < ldb*nrhs; i++ ) {
00146 b_i[i] = b_save[i];
00147 }
00148 info_i = LAPACKE_spbtrs( LAPACK_COL_MAJOR, uplo_i, n_i, kd_i, nrhs_i, ab_i,
00149 ldab_i, b_i, ldb_i );
00150
00151 failed = compare_spbtrs( b, b_i, info, info_i, ldb, nrhs );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major high-level interface to spbtrs\n" );
00154 } else {
00155 printf( "FAILED: column-major high-level interface to spbtrs\n" );
00156 }
00157
00158
00159
00160 for( i = 0; i < ldab*n; i++ ) {
00161 ab_i[i] = ab[i];
00162 }
00163 for( i = 0; i < ldb*nrhs; i++ ) {
00164 b_i[i] = b_save[i];
00165 }
00166
00167 LAPACKE_sge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00168 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00169 info_i = LAPACKE_spbtrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, kd_i, nrhs_i,
00170 ab_r, ldab_r, b_r, ldb_r );
00171
00172 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00173
00174 failed = compare_spbtrs( b, b_i, info, info_i, ldb, nrhs );
00175 if( failed == 0 ) {
00176 printf( "PASSED: row-major middle-level interface to spbtrs\n" );
00177 } else {
00178 printf( "FAILED: row-major middle-level interface to spbtrs\n" );
00179 }
00180
00181
00182
00183 for( i = 0; i < ldab*n; i++ ) {
00184 ab_i[i] = ab[i];
00185 }
00186 for( i = 0; i < ldb*nrhs; i++ ) {
00187 b_i[i] = b_save[i];
00188 }
00189
00190
00191 LAPACKE_sge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00192 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00193 info_i = LAPACKE_spbtrs( LAPACK_ROW_MAJOR, uplo_i, n_i, kd_i, nrhs_i, ab_r,
00194 ldab_r, b_r, ldb_r );
00195
00196 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00197
00198 failed = compare_spbtrs( b, b_i, info, info_i, ldb, nrhs );
00199 if( failed == 0 ) {
00200 printf( "PASSED: row-major high-level interface to spbtrs\n" );
00201 } else {
00202 printf( "FAILED: row-major high-level interface to spbtrs\n" );
00203 }
00204
00205
00206 if( ab != NULL ) {
00207 LAPACKE_free( ab );
00208 }
00209 if( ab_i != NULL ) {
00210 LAPACKE_free( ab_i );
00211 }
00212 if( ab_r != NULL ) {
00213 LAPACKE_free( ab_r );
00214 }
00215 if( b != NULL ) {
00216 LAPACKE_free( b );
00217 }
00218 if( b_i != NULL ) {
00219 LAPACKE_free( b_i );
00220 }
00221 if( b_r != NULL ) {
00222 LAPACKE_free( b_r );
00223 }
00224 if( b_save != NULL ) {
00225 LAPACKE_free( b_save );
00226 }
00227
00228 return 0;
00229 }
00230
00231
00232 static void init_scalars_spbtrs( char *uplo, lapack_int *n, lapack_int *kd,
00233 lapack_int *nrhs, lapack_int *ldab,
00234 lapack_int *ldb )
00235 {
00236 *uplo = 'L';
00237 *n = 4;
00238 *kd = 1;
00239 *nrhs = 2;
00240 *ldab = 9;
00241 *ldb = 8;
00242
00243 return;
00244 }
00245
00246
00247 static void init_ab( lapack_int size, float *ab ) {
00248 lapack_int i;
00249 for( i = 0; i < size; i++ ) {
00250 ab[i] = 0;
00251 }
00252 ab[0] = 2.343074799e+000;
00253 ab[9] = 2.078877211e+000;
00254 ab[18] = 1.130612254e+000;
00255 ab[27] = 1.146524668e+000;
00256 ab[1] = 1.143796206e+000;
00257 ab[10] = -1.149659038e+000;
00258 ab[19] = -1.963537931e+000;
00259 ab[28] = 0.000000000e+000;
00260 }
00261 static void init_b( lapack_int size, float *b ) {
00262 lapack_int i;
00263 for( i = 0; i < size; i++ ) {
00264 b[i] = 0;
00265 }
00266 b[0] = 2.209000015e+001;
00267 b[8] = 5.099999905e+000;
00268 b[1] = 9.310000420e+000;
00269 b[9] = 3.080999947e+001;
00270 b[2] = -5.239999771e+000;
00271 b[10] = -2.581999969e+001;
00272 b[3] = 1.182999992e+001;
00273 b[11] = 2.289999962e+001;
00274 }
00275
00276
00277
00278 static int compare_spbtrs( float *b, float *b_i, lapack_int info,
00279 lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00280 {
00281 lapack_int i;
00282 int failed = 0;
00283 for( i = 0; i < ldb*nrhs; i++ ) {
00284 failed += compare_floats(b[i],b_i[i]);
00285 }
00286 failed += (info == info_i) ? 0 : 1;
00287 if( info != 0 || info_i != 0 ) {
00288 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00289 }
00290
00291 return failed;
00292 }