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_zhptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00055 lapack_int *ldb );
00056 static void init_ap( lapack_int size, lapack_complex_double *ap );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_b( lapack_int size, lapack_complex_double *b );
00059 static int compare_zhptrs( lapack_complex_double *b, lapack_complex_double *b_i,
00060 lapack_int info, lapack_int info_i, lapack_int ldb,
00061 lapack_int nrhs );
00062
00063 int main(void)
00064 {
00065
00066 char uplo, uplo_i;
00067 lapack_int n, n_i;
00068 lapack_int nrhs, nrhs_i;
00069 lapack_int ldb, ldb_i;
00070 lapack_int ldb_r;
00071 lapack_int info, info_i;
00072 lapack_int i;
00073 int failed;
00074
00075
00076 lapack_complex_double *ap = NULL, *ap_i = NULL;
00077 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00078 lapack_complex_double *b = NULL, *b_i = NULL;
00079 lapack_complex_double *b_save = NULL;
00080 lapack_complex_double *ap_r = NULL;
00081 lapack_complex_double *b_r = NULL;
00082
00083
00084 init_scalars_zhptrs( &uplo, &n, &nrhs, &ldb );
00085 ldb_r = nrhs+2;
00086 uplo_i = uplo;
00087 n_i = n;
00088 nrhs_i = nrhs;
00089 ldb_i = ldb;
00090
00091
00092 ap = (lapack_complex_double *)
00093 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00094 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00095 b = (lapack_complex_double *)
00096 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00097
00098
00099 ap_i = (lapack_complex_double *)
00100 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00101 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00102 b_i = (lapack_complex_double *)
00103 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00104
00105
00106 b_save = (lapack_complex_double *)
00107 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00108
00109
00110 ap_r = (lapack_complex_double *)
00111 LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00112 b_r = (lapack_complex_double *)
00113 LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00114
00115
00116 init_ap( (n*(n+1)/2), ap );
00117 init_ipiv( n, ipiv );
00118 init_b( ldb*nrhs, b );
00119
00120
00121 for( i = 0; i < ldb*nrhs; i++ ) {
00122 b_save[i] = b[i];
00123 }
00124
00125
00126 zhptrs_( &uplo, &n, &nrhs, ap, ipiv, b, &ldb, &info );
00127
00128
00129
00130 for( i = 0; i < (n*(n+1)/2); i++ ) {
00131 ap_i[i] = ap[i];
00132 }
00133 for( i = 0; i < n; i++ ) {
00134 ipiv_i[i] = ipiv[i];
00135 }
00136 for( i = 0; i < ldb*nrhs; i++ ) {
00137 b_i[i] = b_save[i];
00138 }
00139 info_i = LAPACKE_zhptrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00140 ipiv_i, b_i, ldb_i );
00141
00142 failed = compare_zhptrs( b, b_i, info, info_i, ldb, nrhs );
00143 if( failed == 0 ) {
00144 printf( "PASSED: column-major middle-level interface to zhptrs\n" );
00145 } else {
00146 printf( "FAILED: column-major middle-level interface to zhptrs\n" );
00147 }
00148
00149
00150
00151 for( i = 0; i < (n*(n+1)/2); i++ ) {
00152 ap_i[i] = ap[i];
00153 }
00154 for( i = 0; i < n; i++ ) {
00155 ipiv_i[i] = ipiv[i];
00156 }
00157 for( i = 0; i < ldb*nrhs; i++ ) {
00158 b_i[i] = b_save[i];
00159 }
00160 info_i = LAPACKE_zhptrs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00161 ipiv_i, b_i, ldb_i );
00162
00163 failed = compare_zhptrs( b, b_i, info, info_i, ldb, nrhs );
00164 if( failed == 0 ) {
00165 printf( "PASSED: column-major high-level interface to zhptrs\n" );
00166 } else {
00167 printf( "FAILED: column-major high-level interface to zhptrs\n" );
00168 }
00169
00170
00171
00172 for( i = 0; i < (n*(n+1)/2); i++ ) {
00173 ap_i[i] = ap[i];
00174 }
00175 for( i = 0; i < n; i++ ) {
00176 ipiv_i[i] = ipiv[i];
00177 }
00178 for( i = 0; i < ldb*nrhs; i++ ) {
00179 b_i[i] = b_save[i];
00180 }
00181
00182 LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00183 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00184 info_i = LAPACKE_zhptrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00185 ipiv_i, b_r, ldb_r );
00186
00187 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00188
00189 failed = compare_zhptrs( b, b_i, info, info_i, ldb, nrhs );
00190 if( failed == 0 ) {
00191 printf( "PASSED: row-major middle-level interface to zhptrs\n" );
00192 } else {
00193 printf( "FAILED: row-major middle-level interface to zhptrs\n" );
00194 }
00195
00196
00197
00198 for( i = 0; i < (n*(n+1)/2); i++ ) {
00199 ap_i[i] = ap[i];
00200 }
00201 for( i = 0; i < n; i++ ) {
00202 ipiv_i[i] = ipiv[i];
00203 }
00204 for( i = 0; i < ldb*nrhs; i++ ) {
00205 b_i[i] = b_save[i];
00206 }
00207
00208
00209 LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00210 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00211 info_i = LAPACKE_zhptrs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00212 ipiv_i, b_r, ldb_r );
00213
00214 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00215
00216 failed = compare_zhptrs( b, b_i, info, info_i, ldb, nrhs );
00217 if( failed == 0 ) {
00218 printf( "PASSED: row-major high-level interface to zhptrs\n" );
00219 } else {
00220 printf( "FAILED: row-major high-level interface to zhptrs\n" );
00221 }
00222
00223
00224 if( ap != NULL ) {
00225 LAPACKE_free( ap );
00226 }
00227 if( ap_i != NULL ) {
00228 LAPACKE_free( ap_i );
00229 }
00230 if( ap_r != NULL ) {
00231 LAPACKE_free( ap_r );
00232 }
00233 if( ipiv != NULL ) {
00234 LAPACKE_free( ipiv );
00235 }
00236 if( ipiv_i != NULL ) {
00237 LAPACKE_free( ipiv_i );
00238 }
00239 if( b != NULL ) {
00240 LAPACKE_free( b );
00241 }
00242 if( b_i != NULL ) {
00243 LAPACKE_free( b_i );
00244 }
00245 if( b_r != NULL ) {
00246 LAPACKE_free( b_r );
00247 }
00248 if( b_save != NULL ) {
00249 LAPACKE_free( b_save );
00250 }
00251
00252 return 0;
00253 }
00254
00255
00256 static void init_scalars_zhptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00257 lapack_int *ldb )
00258 {
00259 *uplo = 'L';
00260 *n = 4;
00261 *nrhs = 2;
00262 *ldb = 8;
00263
00264 return;
00265 }
00266
00267
00268 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00269 lapack_int i;
00270 for( i = 0; i < size; i++ ) {
00271 ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00272 }
00273 ap[0] = lapack_make_complex_double( -1.36000000000000010e+000,
00274 0.00000000000000000e+000 );
00275 ap[1] = lapack_make_complex_double( 3.91000000000000010e+000,
00276 -1.50000000000000000e+000 );
00277 ap[2] = lapack_make_complex_double( 3.10028798127124030e-001,
00278 4.33302074396270180e-002 );
00279 ap[3] = lapack_make_complex_double( -1.51812020724010200e-001,
00280 3.74295842561370500e-001 );
00281 ap[4] = lapack_make_complex_double( -1.84000000000000010e+000,
00282 0.00000000000000000e+000 );
00283 ap[5] = lapack_make_complex_double( 5.63705048650877560e-001,
00284 2.85034950151971610e-001 );
00285 ap[6] = lapack_make_complex_double( 3.39658279960360960e-001,
00286 3.03145181135563540e-002 );
00287 ap[7] = lapack_make_complex_double( -5.41762438729157920e+000,
00288 0.00000000000000000e+000 );
00289 ap[8] = lapack_make_complex_double( 2.99724464607583510e-001,
00290 1.57826837278577770e-001 );
00291 ap[9] = lapack_make_complex_double( -7.10280989580184220e+000,
00292 0.00000000000000000e+000 );
00293 }
00294 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00295 lapack_int i;
00296 for( i = 0; i < size; i++ ) {
00297 ipiv[i] = 0;
00298 }
00299 ipiv[0] = -4;
00300 ipiv[1] = -4;
00301 ipiv[2] = 3;
00302 ipiv[3] = 4;
00303 }
00304 static void init_b( lapack_int size, lapack_complex_double *b ) {
00305 lapack_int i;
00306 for( i = 0; i < size; i++ ) {
00307 b[i] = lapack_make_complex_double( 0.0, 0.0 );
00308 }
00309 b[0] = lapack_make_complex_double( 7.79000000000000000e+000,
00310 5.48000000000000040e+000 );
00311 b[8] = lapack_make_complex_double( -3.53900000000000010e+001,
00312 1.80100000000000020e+001 );
00313 b[1] = lapack_make_complex_double( -7.70000000000000020e-001,
00314 -1.60500000000000010e+001 );
00315 b[9] = lapack_make_complex_double( 4.23000000000000040e+000,
00316 -7.00199999999999960e+001 );
00317 b[2] = lapack_make_complex_double( -9.58000000000000010e+000,
00318 3.87999999999999990e+000 );
00319 b[10] = lapack_make_complex_double( -2.47899999999999990e+001,
00320 -8.40000000000000040e+000 );
00321 b[3] = lapack_make_complex_double( 2.98000000000000000e+000,
00322 -1.01800000000000000e+001 );
00323 b[11] = lapack_make_complex_double( 2.86800000000000000e+001,
00324 -3.98900000000000010e+001 );
00325 }
00326
00327
00328
00329 static int compare_zhptrs( lapack_complex_double *b, lapack_complex_double *b_i,
00330 lapack_int info, lapack_int info_i, lapack_int ldb,
00331 lapack_int nrhs )
00332 {
00333 lapack_int i;
00334 int failed = 0;
00335 for( i = 0; i < ldb*nrhs; i++ ) {
00336 failed += compare_complex_doubles(b[i],b_i[i]);
00337 }
00338 failed += (info == info_i) ? 0 : 1;
00339 if( info != 0 || info_i != 0 ) {
00340 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00341 }
00342
00343 return failed;
00344 }