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_zsptrs( 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_zsptrs( 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_zsptrs( &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 zsptrs_( &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_zsptrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00140 ipiv_i, b_i, ldb_i );
00141
00142 failed = compare_zsptrs( b, b_i, info, info_i, ldb, nrhs );
00143 if( failed == 0 ) {
00144 printf( "PASSED: column-major middle-level interface to zsptrs\n" );
00145 } else {
00146 printf( "FAILED: column-major middle-level interface to zsptrs\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_zsptrs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00161 ipiv_i, b_i, ldb_i );
00162
00163 failed = compare_zsptrs( b, b_i, info, info_i, ldb, nrhs );
00164 if( failed == 0 ) {
00165 printf( "PASSED: column-major high-level interface to zsptrs\n" );
00166 } else {
00167 printf( "FAILED: column-major high-level interface to zsptrs\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_zsptrs_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_zsptrs( b, b_i, info, info_i, ldb, nrhs );
00190 if( failed == 0 ) {
00191 printf( "PASSED: row-major middle-level interface to zsptrs\n" );
00192 } else {
00193 printf( "FAILED: row-major middle-level interface to zsptrs\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_zsptrs( 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_zsptrs( b, b_i, info, info_i, ldb, nrhs );
00217 if( failed == 0 ) {
00218 printf( "PASSED: row-major high-level interface to zsptrs\n" );
00219 } else {
00220 printf( "FAILED: row-major high-level interface to zsptrs\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_zsptrs( 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( -3.90000000000000010e-001,
00274 -7.09999999999999960e-001 );
00275 ap[1] = lapack_make_complex_double( -7.86000000000000030e+000,
00276 -2.96000000000000000e+000 );
00277 ap[2] = lapack_make_complex_double( 5.27872480164079950e-001,
00278 -3.71466001482590570e-001 );
00279 ap[3] = lapack_make_complex_double( 4.42558238872675090e-001,
00280 1.93648369829740290e-001 );
00281 ap[4] = lapack_make_complex_double( -2.83000000000000010e+000,
00282 -2.99999999999999990e-002 );
00283 ap[5] = lapack_make_complex_double( -6.07839105668319330e-001,
00284 2.81079647893121950e-001 );
00285 ap[6] = lapack_make_complex_double( -4.82282297518538240e-001,
00286 1.49893621910528460e-002 );
00287 ap[7] = lapack_make_complex_double( 4.40790623673101310e+000,
00288 5.39912067679694110e+000 );
00289 ap[8] = lapack_make_complex_double( -1.07082188009268410e-001,
00290 -3.15678086248845520e-001 );
00291 ap[9] = lapack_make_complex_double( -2.09541488784005650e+000,
00292 -2.20113928144078570e+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] = -3;
00300 ipiv[1] = -3;
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( -5.56400000000000010e+001,
00310 4.12199999999999990e+001 );
00311 b[8] = lapack_make_complex_double( -1.90900000000000000e+001,
00312 -3.59699999999999990e+001 );
00313 b[1] = lapack_make_complex_double( -4.81800000000000000e+001,
00314 6.60000000000000000e+001 );
00315 b[9] = lapack_make_complex_double( -1.20800000000000000e+001,
00316 -2.70200000000000000e+001 );
00317 b[2] = lapack_make_complex_double( -4.89999999999999990e-001,
00318 -1.47000000000000000e+000 );
00319 b[10] = lapack_make_complex_double( 6.95000000000000020e+000,
00320 2.04899999999999980e+001 );
00321 b[3] = lapack_make_complex_double( -6.42999999999999970e+000,
00322 1.92399999999999980e+001 );
00323 b[11] = lapack_make_complex_double( -4.58999999999999990e+000,
00324 -3.55300000000000010e+001 );
00325 }
00326
00327
00328
00329 static int compare_zsptrs( 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 }