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_csptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00055 lapack_int *ldb );
00056 static void init_ap( lapack_int size, lapack_complex_float *ap );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_b( lapack_int size, lapack_complex_float *b );
00059 static int compare_csptrs( lapack_complex_float *b, lapack_complex_float *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_float *ap = NULL, *ap_i = NULL;
00077 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00078 lapack_complex_float *b = NULL, *b_i = NULL;
00079 lapack_complex_float *b_save = NULL;
00080 lapack_complex_float *ap_r = NULL;
00081 lapack_complex_float *b_r = NULL;
00082
00083
00084 init_scalars_csptrs( &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_float *)
00093 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00094 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00095 b = (lapack_complex_float *)
00096 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00097
00098
00099 ap_i = (lapack_complex_float *)
00100 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00101 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00102 b_i = (lapack_complex_float *)
00103 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00104
00105
00106 b_save = (lapack_complex_float *)
00107 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00108
00109
00110 ap_r = (lapack_complex_float *)
00111 LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00112 b_r = (lapack_complex_float *)
00113 LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_float) );
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 csptrs_( &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_csptrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00140 ipiv_i, b_i, ldb_i );
00141
00142 failed = compare_csptrs( b, b_i, info, info_i, ldb, nrhs );
00143 if( failed == 0 ) {
00144 printf( "PASSED: column-major middle-level interface to csptrs\n" );
00145 } else {
00146 printf( "FAILED: column-major middle-level interface to csptrs\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_csptrs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00161 ipiv_i, b_i, ldb_i );
00162
00163 failed = compare_csptrs( b, b_i, info, info_i, ldb, nrhs );
00164 if( failed == 0 ) {
00165 printf( "PASSED: column-major high-level interface to csptrs\n" );
00166 } else {
00167 printf( "FAILED: column-major high-level interface to csptrs\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_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00183 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00184 info_i = LAPACKE_csptrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00185 ipiv_i, b_r, ldb_r );
00186
00187 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00188
00189 failed = compare_csptrs( b, b_i, info, info_i, ldb, nrhs );
00190 if( failed == 0 ) {
00191 printf( "PASSED: row-major middle-level interface to csptrs\n" );
00192 } else {
00193 printf( "FAILED: row-major middle-level interface to csptrs\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_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00210 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00211 info_i = LAPACKE_csptrs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00212 ipiv_i, b_r, ldb_r );
00213
00214 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00215
00216 failed = compare_csptrs( b, b_i, info, info_i, ldb, nrhs );
00217 if( failed == 0 ) {
00218 printf( "PASSED: row-major high-level interface to csptrs\n" );
00219 } else {
00220 printf( "FAILED: row-major high-level interface to csptrs\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_csptrs( 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_float *ap ) {
00269 lapack_int i;
00270 for( i = 0; i < size; i++ ) {
00271 ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00272 }
00273 ap[0] = lapack_make_complex_float( -3.899999857e-001, -7.099999785e-001 );
00274 ap[1] = lapack_make_complex_float( -7.860000134e+000, -2.960000038e+000 );
00275 ap[2] = lapack_make_complex_float( 5.278724432e-001, -3.714659810e-001 );
00276 ap[3] = lapack_make_complex_float( 4.425582290e-001, 1.936483681e-001 );
00277 ap[4] = lapack_make_complex_float( -2.829999924e+000, -2.999999933e-002 );
00278 ap[5] = lapack_make_complex_float( -6.078390479e-001, 2.810796499e-001 );
00279 ap[6] = lapack_make_complex_float( -4.822822809e-001, 1.498936117e-002 );
00280 ap[7] = lapack_make_complex_float( 4.407906532e+000, 5.399120808e+000 );
00281 ap[8] = lapack_make_complex_float( -1.070821285e-001, -3.156781197e-001 );
00282 ap[9] = lapack_make_complex_float( -2.095414639e+000, -2.201138735e+000 );
00283 }
00284 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00285 lapack_int i;
00286 for( i = 0; i < size; i++ ) {
00287 ipiv[i] = 0;
00288 }
00289 ipiv[0] = -3;
00290 ipiv[1] = -3;
00291 ipiv[2] = 3;
00292 ipiv[3] = 4;
00293 }
00294 static void init_b( lapack_int size, lapack_complex_float *b ) {
00295 lapack_int i;
00296 for( i = 0; i < size; i++ ) {
00297 b[i] = lapack_make_complex_float( 0.0f, 0.0f );
00298 }
00299 b[0] = lapack_make_complex_float( -5.563999939e+001, 4.122000122e+001 );
00300 b[8] = lapack_make_complex_float( -1.909000015e+001, -3.597000122e+001 );
00301 b[1] = lapack_make_complex_float( -4.818000031e+001, 6.600000000e+001 );
00302 b[9] = lapack_make_complex_float( -1.207999992e+001, -2.702000046e+001 );
00303 b[2] = lapack_make_complex_float( -4.900000095e-001, -1.470000029e+000 );
00304 b[10] = lapack_make_complex_float( 6.949999809e+000, 2.048999977e+001 );
00305 b[3] = lapack_make_complex_float( -6.429999828e+000, 1.923999977e+001 );
00306 b[11] = lapack_make_complex_float( -4.590000153e+000, -3.552999878e+001 );
00307 }
00308
00309
00310
00311 static int compare_csptrs( lapack_complex_float *b, lapack_complex_float *b_i,
00312 lapack_int info, lapack_int info_i, lapack_int ldb,
00313 lapack_int nrhs )
00314 {
00315 lapack_int i;
00316 int failed = 0;
00317 for( i = 0; i < ldb*nrhs; i++ ) {
00318 failed += compare_complex_floats(b[i],b_i[i]);
00319 }
00320 failed += (info == info_i) ? 0 : 1;
00321 if( info != 0 || info_i != 0 ) {
00322 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00323 }
00324
00325 return failed;
00326 }