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_csytrf( char *uplo, lapack_int *n, lapack_int *lda,
00055 lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_float *a );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_work( lapack_int size, lapack_complex_float *work );
00059 static int compare_csytrf( lapack_complex_float *a, lapack_complex_float *a_i,
00060 lapack_int *ipiv, lapack_int *ipiv_i,
00061 lapack_int info, lapack_int info_i, lapack_int lda,
00062 lapack_int n );
00063
00064 int main(void)
00065 {
00066
00067 char uplo, uplo_i;
00068 lapack_int n, n_i;
00069 lapack_int lda, lda_i;
00070 lapack_int lda_r;
00071 lapack_int lwork, lwork_i;
00072 lapack_int info, info_i;
00073 lapack_int i;
00074 int failed;
00075
00076
00077 lapack_complex_float *a = NULL, *a_i = NULL;
00078 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00079 lapack_complex_float *work = NULL, *work_i = NULL;
00080 lapack_complex_float *a_save = NULL;
00081 lapack_int *ipiv_save = NULL;
00082 lapack_complex_float *a_r = NULL;
00083
00084
00085 init_scalars_csytrf( &uplo, &n, &lda, &lwork );
00086 lda_r = n+2;
00087 uplo_i = uplo;
00088 n_i = n;
00089 lda_i = lda;
00090 lwork_i = lwork;
00091
00092
00093 a = (lapack_complex_float *)
00094 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00095 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00096 work = (lapack_complex_float *)
00097 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00098
00099
00100 a_i = (lapack_complex_float *)
00101 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00102 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00103 work_i = (lapack_complex_float *)
00104 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00105
00106
00107 a_save = (lapack_complex_float *)
00108 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00109 ipiv_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00110
00111
00112 a_r = (lapack_complex_float *)
00113 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00114
00115
00116 init_a( lda*n, a );
00117 init_ipiv( n, ipiv );
00118 init_work( lwork, work );
00119
00120
00121 for( i = 0; i < lda*n; i++ ) {
00122 a_save[i] = a[i];
00123 }
00124 for( i = 0; i < n; i++ ) {
00125 ipiv_save[i] = ipiv[i];
00126 }
00127
00128
00129 csytrf_( &uplo, &n, a, &lda, ipiv, work, &lwork, &info );
00130
00131
00132
00133 for( i = 0; i < lda*n; i++ ) {
00134 a_i[i] = a_save[i];
00135 }
00136 for( i = 0; i < n; i++ ) {
00137 ipiv_i[i] = ipiv_save[i];
00138 }
00139 for( i = 0; i < lwork; i++ ) {
00140 work_i[i] = work[i];
00141 }
00142 info_i = LAPACKE_csytrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00143 ipiv_i, work_i, lwork_i );
00144
00145 failed = compare_csytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00146 if( failed == 0 ) {
00147 printf( "PASSED: column-major middle-level interface to csytrf\n" );
00148 } else {
00149 printf( "FAILED: column-major middle-level interface to csytrf\n" );
00150 }
00151
00152
00153
00154 for( i = 0; i < lda*n; i++ ) {
00155 a_i[i] = a_save[i];
00156 }
00157 for( i = 0; i < n; i++ ) {
00158 ipiv_i[i] = ipiv_save[i];
00159 }
00160 for( i = 0; i < lwork; i++ ) {
00161 work_i[i] = work[i];
00162 }
00163 info_i = LAPACKE_csytrf( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00164 ipiv_i );
00165
00166 failed = compare_csytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00167 if( failed == 0 ) {
00168 printf( "PASSED: column-major high-level interface to csytrf\n" );
00169 } else {
00170 printf( "FAILED: column-major high-level interface to csytrf\n" );
00171 }
00172
00173
00174
00175 for( i = 0; i < lda*n; i++ ) {
00176 a_i[i] = a_save[i];
00177 }
00178 for( i = 0; i < n; i++ ) {
00179 ipiv_i[i] = ipiv_save[i];
00180 }
00181 for( i = 0; i < lwork; i++ ) {
00182 work_i[i] = work[i];
00183 }
00184
00185 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00186 info_i = LAPACKE_csytrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00187 ipiv_i, work_i, lwork_i );
00188
00189 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00190
00191 failed = compare_csytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00192 if( failed == 0 ) {
00193 printf( "PASSED: row-major middle-level interface to csytrf\n" );
00194 } else {
00195 printf( "FAILED: row-major middle-level interface to csytrf\n" );
00196 }
00197
00198
00199
00200 for( i = 0; i < lda*n; i++ ) {
00201 a_i[i] = a_save[i];
00202 }
00203 for( i = 0; i < n; i++ ) {
00204 ipiv_i[i] = ipiv_save[i];
00205 }
00206 for( i = 0; i < lwork; i++ ) {
00207 work_i[i] = work[i];
00208 }
00209
00210
00211 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00212 info_i = LAPACKE_csytrf( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00213 ipiv_i );
00214
00215 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00216
00217 failed = compare_csytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00218 if( failed == 0 ) {
00219 printf( "PASSED: row-major high-level interface to csytrf\n" );
00220 } else {
00221 printf( "FAILED: row-major high-level interface to csytrf\n" );
00222 }
00223
00224
00225 if( a != NULL ) {
00226 LAPACKE_free( a );
00227 }
00228 if( a_i != NULL ) {
00229 LAPACKE_free( a_i );
00230 }
00231 if( a_r != NULL ) {
00232 LAPACKE_free( a_r );
00233 }
00234 if( a_save != NULL ) {
00235 LAPACKE_free( a_save );
00236 }
00237 if( ipiv != NULL ) {
00238 LAPACKE_free( ipiv );
00239 }
00240 if( ipiv_i != NULL ) {
00241 LAPACKE_free( ipiv_i );
00242 }
00243 if( ipiv_save != NULL ) {
00244 LAPACKE_free( ipiv_save );
00245 }
00246 if( work != NULL ) {
00247 LAPACKE_free( work );
00248 }
00249 if( work_i != NULL ) {
00250 LAPACKE_free( work_i );
00251 }
00252
00253 return 0;
00254 }
00255
00256
00257 static void init_scalars_csytrf( char *uplo, lapack_int *n, lapack_int *lda,
00258 lapack_int *lwork )
00259 {
00260 *uplo = 'L';
00261 *n = 4;
00262 *lda = 8;
00263 *lwork = 512;
00264
00265 return;
00266 }
00267
00268
00269 static void init_a( lapack_int size, lapack_complex_float *a ) {
00270 lapack_int i;
00271 for( i = 0; i < size; i++ ) {
00272 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00273 }
00274 a[0] = lapack_make_complex_float( -3.899999857e-001, -7.099999785e-001 );
00275 a[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00276 a[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00277 a[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00278 a[1] = lapack_make_complex_float( 5.139999866e+000, -6.399999857e-001 );
00279 a[9] = lapack_make_complex_float( 8.859999657e+000, 1.809999943e+000 );
00280 a[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00281 a[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00282 a[2] = lapack_make_complex_float( -7.860000134e+000, -2.960000038e+000 );
00283 a[10] = lapack_make_complex_float( -3.519999981e+000, 5.799999833e-001 );
00284 a[18] = lapack_make_complex_float( -2.829999924e+000, -2.999999933e-002 );
00285 a[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00286 a[3] = lapack_make_complex_float( 3.799999952e+000, 9.200000167e-001 );
00287 a[11] = lapack_make_complex_float( 5.320000172e+000, -1.590000033e+000 );
00288 a[19] = lapack_make_complex_float( -1.539999962e+000, -2.859999895e+000 );
00289 a[27] = lapack_make_complex_float( -5.600000024e-001, 1.199999973e-001 );
00290 }
00291 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00292 lapack_int i;
00293 for( i = 0; i < size; i++ ) {
00294 ipiv[i] = 0;
00295 }
00296 }
00297 static void init_work( lapack_int size, lapack_complex_float *work ) {
00298 lapack_int i;
00299 for( i = 0; i < size; i++ ) {
00300 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00301 }
00302 }
00303
00304
00305
00306 static int compare_csytrf( lapack_complex_float *a, lapack_complex_float *a_i,
00307 lapack_int *ipiv, lapack_int *ipiv_i,
00308 lapack_int info, lapack_int info_i, lapack_int lda,
00309 lapack_int n )
00310 {
00311 lapack_int i;
00312 int failed = 0;
00313 for( i = 0; i < lda*n; i++ ) {
00314 failed += compare_complex_floats(a[i],a_i[i]);
00315 }
00316 for( i = 0; i < n; i++ ) {
00317 failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00318 }
00319 failed += (info == info_i) ? 0 : 1;
00320 if( info != 0 || info_i != 0 ) {
00321 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00322 }
00323
00324 return failed;
00325 }