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