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_zhptri( 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 void init_work( lapack_int size, lapack_complex_double *work );
00058 static int compare_zhptri( lapack_complex_double *ap,
00059 lapack_complex_double *ap_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 *work = NULL, *work_i = NULL;
00075 lapack_complex_double *ap_save = NULL;
00076 lapack_complex_double *ap_r = NULL;
00077
00078
00079 init_scalars_zhptri( &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 work = (lapack_complex_double *)
00088 LAPACKE_malloc( n * sizeof(lapack_complex_double) );
00089
00090
00091 ap_i = (lapack_complex_double *)
00092 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00093 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00094 work_i = (lapack_complex_double *)
00095 LAPACKE_malloc( n * sizeof(lapack_complex_double) );
00096
00097
00098 ap_save = (lapack_complex_double *)
00099 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00100
00101
00102 ap_r = (lapack_complex_double *)
00103 LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00104
00105
00106 init_ap( (n*(n+1)/2), ap );
00107 init_ipiv( n, ipiv );
00108 init_work( n, work );
00109
00110
00111 for( i = 0; i < (n*(n+1)/2); i++ ) {
00112 ap_save[i] = ap[i];
00113 }
00114
00115
00116 zhptri_( &uplo, &n, ap, ipiv, work, &info );
00117
00118
00119
00120 for( i = 0; i < (n*(n+1)/2); i++ ) {
00121 ap_i[i] = ap_save[i];
00122 }
00123 for( i = 0; i < n; i++ ) {
00124 ipiv_i[i] = ipiv[i];
00125 }
00126 for( i = 0; i < n; i++ ) {
00127 work_i[i] = work[i];
00128 }
00129 info_i = LAPACKE_zhptri_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i,
00130 work_i );
00131
00132 failed = compare_zhptri( ap, ap_i, info, info_i, n );
00133 if( failed == 0 ) {
00134 printf( "PASSED: column-major middle-level interface to zhptri\n" );
00135 } else {
00136 printf( "FAILED: column-major middle-level interface to zhptri\n" );
00137 }
00138
00139
00140
00141 for( i = 0; i < (n*(n+1)/2); i++ ) {
00142 ap_i[i] = ap_save[i];
00143 }
00144 for( i = 0; i < n; i++ ) {
00145 ipiv_i[i] = ipiv[i];
00146 }
00147 for( i = 0; i < n; i++ ) {
00148 work_i[i] = work[i];
00149 }
00150 info_i = LAPACKE_zhptri( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00151
00152 failed = compare_zhptri( ap, ap_i, info, info_i, n );
00153 if( failed == 0 ) {
00154 printf( "PASSED: column-major high-level interface to zhptri\n" );
00155 } else {
00156 printf( "FAILED: column-major high-level interface to zhptri\n" );
00157 }
00158
00159
00160
00161 for( i = 0; i < (n*(n+1)/2); i++ ) {
00162 ap_i[i] = ap_save[i];
00163 }
00164 for( i = 0; i < n; i++ ) {
00165 ipiv_i[i] = ipiv[i];
00166 }
00167 for( i = 0; i < n; i++ ) {
00168 work_i[i] = work[i];
00169 }
00170
00171 LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00172 info_i = LAPACKE_zhptri_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i,
00173 work_i );
00174
00175 LAPACKE_zpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00176
00177 failed = compare_zhptri( ap, ap_i, info, info_i, n );
00178 if( failed == 0 ) {
00179 printf( "PASSED: row-major middle-level interface to zhptri\n" );
00180 } else {
00181 printf( "FAILED: row-major middle-level interface to zhptri\n" );
00182 }
00183
00184
00185
00186 for( i = 0; i < (n*(n+1)/2); i++ ) {
00187 ap_i[i] = ap_save[i];
00188 }
00189 for( i = 0; i < n; i++ ) {
00190 ipiv_i[i] = ipiv[i];
00191 }
00192 for( i = 0; i < n; i++ ) {
00193 work_i[i] = work[i];
00194 }
00195
00196
00197 LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198 info_i = LAPACKE_zhptri( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00199
00200 LAPACKE_zpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00201
00202 failed = compare_zhptri( ap, ap_i, info, info_i, n );
00203 if( failed == 0 ) {
00204 printf( "PASSED: row-major high-level interface to zhptri\n" );
00205 } else {
00206 printf( "FAILED: row-major high-level interface to zhptri\n" );
00207 }
00208
00209
00210 if( ap != NULL ) {
00211 LAPACKE_free( ap );
00212 }
00213 if( ap_i != NULL ) {
00214 LAPACKE_free( ap_i );
00215 }
00216 if( ap_r != NULL ) {
00217 LAPACKE_free( ap_r );
00218 }
00219 if( ap_save != NULL ) {
00220 LAPACKE_free( ap_save );
00221 }
00222 if( ipiv != NULL ) {
00223 LAPACKE_free( ipiv );
00224 }
00225 if( ipiv_i != NULL ) {
00226 LAPACKE_free( ipiv_i );
00227 }
00228 if( work != NULL ) {
00229 LAPACKE_free( work );
00230 }
00231 if( work_i != NULL ) {
00232 LAPACKE_free( work_i );
00233 }
00234
00235 return 0;
00236 }
00237
00238
00239 static void init_scalars_zhptri( char *uplo, lapack_int *n )
00240 {
00241 *uplo = 'L';
00242 *n = 4;
00243
00244 return;
00245 }
00246
00247
00248 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00249 lapack_int i;
00250 for( i = 0; i < size; i++ ) {
00251 ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00252 }
00253 ap[0] = lapack_make_complex_double( -1.36000000000000010e+000,
00254 0.00000000000000000e+000 );
00255 ap[1] = lapack_make_complex_double( 3.91000000000000010e+000,
00256 -1.50000000000000000e+000 );
00257 ap[2] = lapack_make_complex_double( 3.10028798127124030e-001,
00258 4.33302074396270180e-002 );
00259 ap[3] = lapack_make_complex_double( -1.51812020724010200e-001,
00260 3.74295842561370500e-001 );
00261 ap[4] = lapack_make_complex_double( -1.84000000000000010e+000,
00262 0.00000000000000000e+000 );
00263 ap[5] = lapack_make_complex_double( 5.63705048650877560e-001,
00264 2.85034950151971610e-001 );
00265 ap[6] = lapack_make_complex_double( 3.39658279960360960e-001,
00266 3.03145181135563540e-002 );
00267 ap[7] = lapack_make_complex_double( -5.41762438729157920e+000,
00268 0.00000000000000000e+000 );
00269 ap[8] = lapack_make_complex_double( 2.99724464607583510e-001,
00270 1.57826837278577770e-001 );
00271 ap[9] = lapack_make_complex_double( -7.10280989580184220e+000,
00272 0.00000000000000000e+000 );
00273 }
00274 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00275 lapack_int i;
00276 for( i = 0; i < size; i++ ) {
00277 ipiv[i] = 0;
00278 }
00279 ipiv[0] = -4;
00280 ipiv[1] = -4;
00281 ipiv[2] = 3;
00282 ipiv[3] = 4;
00283 }
00284 static void init_work( lapack_int size, lapack_complex_double *work ) {
00285 lapack_int i;
00286 for( i = 0; i < size; i++ ) {
00287 work[i] = lapack_make_complex_double( 0.0, 0.0 );
00288 }
00289 }
00290
00291
00292
00293 static int compare_zhptri( lapack_complex_double *ap,
00294 lapack_complex_double *ap_i, lapack_int info,
00295 lapack_int info_i, lapack_int n )
00296 {
00297 lapack_int i;
00298 int failed = 0;
00299 for( i = 0; i < (n*(n+1)/2); i++ ) {
00300 failed += compare_complex_doubles(ap[i],ap_i[i]);
00301 }
00302 failed += (info == info_i) ? 0 : 1;
00303 if( info != 0 || info_i != 0 ) {
00304 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00305 }
00306
00307 return failed;
00308 }