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