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_dsptrf( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, double *ap );
00056 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00057 static int compare_dsptrf( double *ap, double *ap_i, lapack_int *ipiv,
00058 lapack_int *ipiv_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 double *ap = NULL, *ap_i = NULL;
00072 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00073 double *ap_save = NULL;
00074 lapack_int *ipiv_save = NULL;
00075 double *ap_r = NULL;
00076
00077
00078 init_scalars_dsptrf( &uplo, &n );
00079 uplo_i = uplo;
00080 n_i = n;
00081
00082
00083 ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00084 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00085
00086
00087 ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00088 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00089
00090
00091 ap_save = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00092 ipiv_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00093
00094
00095 ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00096
00097
00098 init_ap( (n*(n+1)/2), ap );
00099 init_ipiv( n, ipiv );
00100
00101
00102 for( i = 0; i < (n*(n+1)/2); i++ ) {
00103 ap_save[i] = ap[i];
00104 }
00105 for( i = 0; i < n; i++ ) {
00106 ipiv_save[i] = ipiv[i];
00107 }
00108
00109
00110 dsptrf_( &uplo, &n, ap, ipiv, &info );
00111
00112
00113
00114 for( i = 0; i < (n*(n+1)/2); i++ ) {
00115 ap_i[i] = ap_save[i];
00116 }
00117 for( i = 0; i < n; i++ ) {
00118 ipiv_i[i] = ipiv_save[i];
00119 }
00120 info_i = LAPACKE_dsptrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00121
00122 failed = compare_dsptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00123 if( failed == 0 ) {
00124 printf( "PASSED: column-major middle-level interface to dsptrf\n" );
00125 } else {
00126 printf( "FAILED: column-major middle-level interface to dsptrf\n" );
00127 }
00128
00129
00130
00131 for( i = 0; i < (n*(n+1)/2); i++ ) {
00132 ap_i[i] = ap_save[i];
00133 }
00134 for( i = 0; i < n; i++ ) {
00135 ipiv_i[i] = ipiv_save[i];
00136 }
00137 info_i = LAPACKE_dsptrf( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00138
00139 failed = compare_dsptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00140 if( failed == 0 ) {
00141 printf( "PASSED: column-major high-level interface to dsptrf\n" );
00142 } else {
00143 printf( "FAILED: column-major high-level interface to dsptrf\n" );
00144 }
00145
00146
00147
00148 for( i = 0; i < (n*(n+1)/2); i++ ) {
00149 ap_i[i] = ap_save[i];
00150 }
00151 for( i = 0; i < n; i++ ) {
00152 ipiv_i[i] = ipiv_save[i];
00153 }
00154
00155 LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00156 info_i = LAPACKE_dsptrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00157
00158 LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00159
00160 failed = compare_dsptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00161 if( failed == 0 ) {
00162 printf( "PASSED: row-major middle-level interface to dsptrf\n" );
00163 } else {
00164 printf( "FAILED: row-major middle-level interface to dsptrf\n" );
00165 }
00166
00167
00168
00169 for( i = 0; i < (n*(n+1)/2); i++ ) {
00170 ap_i[i] = ap_save[i];
00171 }
00172 for( i = 0; i < n; i++ ) {
00173 ipiv_i[i] = ipiv_save[i];
00174 }
00175
00176
00177 LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00178 info_i = LAPACKE_dsptrf( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00179
00180 LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00181
00182 failed = compare_dsptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00183 if( failed == 0 ) {
00184 printf( "PASSED: row-major high-level interface to dsptrf\n" );
00185 } else {
00186 printf( "FAILED: row-major high-level interface to dsptrf\n" );
00187 }
00188
00189
00190 if( ap != NULL ) {
00191 LAPACKE_free( ap );
00192 }
00193 if( ap_i != NULL ) {
00194 LAPACKE_free( ap_i );
00195 }
00196 if( ap_r != NULL ) {
00197 LAPACKE_free( ap_r );
00198 }
00199 if( ap_save != NULL ) {
00200 LAPACKE_free( ap_save );
00201 }
00202 if( ipiv != NULL ) {
00203 LAPACKE_free( ipiv );
00204 }
00205 if( ipiv_i != NULL ) {
00206 LAPACKE_free( ipiv_i );
00207 }
00208 if( ipiv_save != NULL ) {
00209 LAPACKE_free( ipiv_save );
00210 }
00211
00212 return 0;
00213 }
00214
00215
00216 static void init_scalars_dsptrf( char *uplo, lapack_int *n )
00217 {
00218 *uplo = 'L';
00219 *n = 4;
00220
00221 return;
00222 }
00223
00224
00225 static void init_ap( lapack_int size, double *ap ) {
00226 lapack_int i;
00227 for( i = 0; i < size; i++ ) {
00228 ap[i] = 0;
00229 }
00230 ap[0] = 2.06999999999999980e+000;
00231 ap[1] = 3.87000000000000010e+000;
00232 ap[2] = 4.20000000000000020e+000;
00233 ap[3] = -1.14999999999999990e+000;
00234 ap[4] = -2.09999999999999990e-001;
00235 ap[5] = 1.87000000000000010e+000;
00236 ap[6] = 6.30000000000000000e-001;
00237 ap[7] = 1.14999999999999990e+000;
00238 ap[8] = 2.06000000000000010e+000;
00239 ap[9] = -1.81000000000000010e+000;
00240 }
00241 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00242 lapack_int i;
00243 for( i = 0; i < size; i++ ) {
00244 ipiv[i] = 0;
00245 }
00246 }
00247
00248
00249
00250 static int compare_dsptrf( double *ap, double *ap_i, lapack_int *ipiv,
00251 lapack_int *ipiv_i, lapack_int info,
00252 lapack_int info_i, lapack_int n )
00253 {
00254 lapack_int i;
00255 int failed = 0;
00256 for( i = 0; i < (n*(n+1)/2); i++ ) {
00257 failed += compare_doubles(ap[i],ap_i[i]);
00258 }
00259 for( i = 0; i < n; i++ ) {
00260 failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00261 }
00262 failed += (info == info_i) ? 0 : 1;
00263 if( info != 0 || info_i != 0 ) {
00264 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00265 }
00266
00267 return failed;
00268 }