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_spptrf( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, float *ap );
00056 static int compare_spptrf( float *ap, float *ap_i, lapack_int info,
00057 lapack_int info_i, lapack_int n );
00058
00059 int main(void)
00060 {
00061
00062 char uplo, uplo_i;
00063 lapack_int n, n_i;
00064 lapack_int info, info_i;
00065 lapack_int i;
00066 int failed;
00067
00068
00069 float *ap = NULL, *ap_i = NULL;
00070 float *ap_save = NULL;
00071 float *ap_r = NULL;
00072
00073
00074 init_scalars_spptrf( &uplo, &n );
00075 uplo_i = uplo;
00076 n_i = n;
00077
00078
00079 ap = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00080
00081
00082 ap_i = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00083
00084
00085 ap_save = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00086
00087
00088 ap_r = (float *)LAPACKE_malloc( n*(n+1)/2 * sizeof(float) );
00089
00090
00091 init_ap( (n*(n+1)/2), ap );
00092
00093
00094 for( i = 0; i < (n*(n+1)/2); i++ ) {
00095 ap_save[i] = ap[i];
00096 }
00097
00098
00099 spptrf_( &uplo, &n, ap, &info );
00100
00101
00102
00103 for( i = 0; i < (n*(n+1)/2); i++ ) {
00104 ap_i[i] = ap_save[i];
00105 }
00106 info_i = LAPACKE_spptrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i );
00107
00108 failed = compare_spptrf( ap, ap_i, info, info_i, n );
00109 if( failed == 0 ) {
00110 printf( "PASSED: column-major middle-level interface to spptrf\n" );
00111 } else {
00112 printf( "FAILED: column-major middle-level interface to spptrf\n" );
00113 }
00114
00115
00116
00117 for( i = 0; i < (n*(n+1)/2); i++ ) {
00118 ap_i[i] = ap_save[i];
00119 }
00120 info_i = LAPACKE_spptrf( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i );
00121
00122 failed = compare_spptrf( ap, ap_i, info, info_i, n );
00123 if( failed == 0 ) {
00124 printf( "PASSED: column-major high-level interface to spptrf\n" );
00125 } else {
00126 printf( "FAILED: column-major high-level interface to spptrf\n" );
00127 }
00128
00129
00130
00131 for( i = 0; i < (n*(n+1)/2); i++ ) {
00132 ap_i[i] = ap_save[i];
00133 }
00134
00135 LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00136 info_i = LAPACKE_spptrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r );
00137
00138 LAPACKE_spp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00139
00140 failed = compare_spptrf( ap, ap_i, info, info_i, n );
00141 if( failed == 0 ) {
00142 printf( "PASSED: row-major middle-level interface to spptrf\n" );
00143 } else {
00144 printf( "FAILED: row-major middle-level interface to spptrf\n" );
00145 }
00146
00147
00148
00149 for( i = 0; i < (n*(n+1)/2); i++ ) {
00150 ap_i[i] = ap_save[i];
00151 }
00152
00153
00154 LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00155 info_i = LAPACKE_spptrf( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r );
00156
00157 LAPACKE_spp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00158
00159 failed = compare_spptrf( ap, ap_i, info, info_i, n );
00160 if( failed == 0 ) {
00161 printf( "PASSED: row-major high-level interface to spptrf\n" );
00162 } else {
00163 printf( "FAILED: row-major high-level interface to spptrf\n" );
00164 }
00165
00166
00167 if( ap != NULL ) {
00168 LAPACKE_free( ap );
00169 }
00170 if( ap_i != NULL ) {
00171 LAPACKE_free( ap_i );
00172 }
00173 if( ap_r != NULL ) {
00174 LAPACKE_free( ap_r );
00175 }
00176 if( ap_save != NULL ) {
00177 LAPACKE_free( ap_save );
00178 }
00179
00180 return 0;
00181 }
00182
00183
00184 static void init_scalars_spptrf( char *uplo, lapack_int *n )
00185 {
00186 *uplo = 'L';
00187 *n = 4;
00188
00189 return;
00190 }
00191
00192
00193 static void init_ap( lapack_int size, float *ap ) {
00194 lapack_int i;
00195 for( i = 0; i < size; i++ ) {
00196 ap[i] = 0;
00197 }
00198 ap[0] = 4.159999847e+000;
00199 ap[1] = -3.119999886e+000;
00200 ap[2] = 5.600000024e-001;
00201 ap[3] = -1.000000015e-001;
00202 ap[4] = 5.030000210e+000;
00203 ap[5] = -8.299999833e-001;
00204 ap[6] = 1.090000033e+000;
00205 ap[7] = 7.599999905e-001;
00206 ap[8] = 3.400000036e-001;
00207 ap[9] = 1.179999948e+000;
00208 }
00209
00210
00211
00212 static int compare_spptrf( float *ap, float *ap_i, lapack_int info,
00213 lapack_int info_i, lapack_int n )
00214 {
00215 lapack_int i;
00216 int failed = 0;
00217 for( i = 0; i < (n*(n+1)/2); i++ ) {
00218 failed += compare_floats(ap[i],ap_i[i]);
00219 }
00220 failed += (info == info_i) ? 0 : 1;
00221 if( info != 0 || info_i != 0 ) {
00222 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00223 }
00224
00225 return failed;
00226 }