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