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_cgbtrf( lapack_int *m, lapack_int *n, lapack_int *kl,
00055 lapack_int *ku, lapack_int *ldab );
00056 static void init_ab( lapack_int size, lapack_complex_float *ab );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static int compare_cgbtrf( lapack_complex_float *ab, lapack_complex_float *ab_i,
00059 lapack_int *ipiv, lapack_int *ipiv_i,
00060 lapack_int info, lapack_int info_i, lapack_int ldab,
00061 lapack_int m, lapack_int n );
00062
00063 int main(void)
00064 {
00065
00066 lapack_int m, m_i;
00067 lapack_int n, n_i;
00068 lapack_int kl, kl_i;
00069 lapack_int ku, ku_i;
00070 lapack_int ldab, ldab_i;
00071 lapack_int ldab_r;
00072 lapack_int info, info_i;
00073 lapack_int i;
00074 int failed;
00075
00076
00077 lapack_complex_float *ab = NULL, *ab_i = NULL;
00078 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00079 lapack_complex_float *ab_save = NULL;
00080 lapack_int *ipiv_save = NULL;
00081 lapack_complex_float *ab_r = NULL;
00082
00083
00084 init_scalars_cgbtrf( &m, &n, &kl, &ku, &ldab );
00085 ldab_r = n+2;
00086 m_i = m;
00087 n_i = n;
00088 kl_i = kl;
00089 ku_i = ku;
00090 ldab_i = ldab;
00091
00092
00093 ab = (lapack_complex_float *)
00094 LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00095 ipiv = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00096
00097
00098 ab_i = (lapack_complex_float *)
00099 LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00100 ipiv_i = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00101
00102
00103 ab_save = (lapack_complex_float *)
00104 LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00105 ipiv_save = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00106
00107
00108 ab_r = (lapack_complex_float *)
00109 LAPACKE_malloc( ((2*kl+ku+1)*(n+2)) * sizeof(lapack_complex_float) );
00110
00111
00112 init_ab( ldab*n, ab );
00113 init_ipiv( (MIN(m,n)), ipiv );
00114
00115
00116 for( i = 0; i < ldab*n; i++ ) {
00117 ab_save[i] = ab[i];
00118 }
00119 for( i = 0; i < (MIN(m,n)); i++ ) {
00120 ipiv_save[i] = ipiv[i];
00121 }
00122
00123
00124 cgbtrf_( &m, &n, &kl, &ku, ab, &ldab, ipiv, &info );
00125
00126
00127
00128 for( i = 0; i < ldab*n; i++ ) {
00129 ab_i[i] = ab_save[i];
00130 }
00131 for( i = 0; i < (MIN(m,n)); i++ ) {
00132 ipiv_i[i] = ipiv_save[i];
00133 }
00134 info_i = LAPACKE_cgbtrf_work( LAPACK_COL_MAJOR, m_i, n_i, kl_i, ku_i, ab_i,
00135 ldab_i, ipiv_i );
00136
00137 failed = compare_cgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00138 if( failed == 0 ) {
00139 printf( "PASSED: column-major middle-level interface to cgbtrf\n" );
00140 } else {
00141 printf( "FAILED: column-major middle-level interface to cgbtrf\n" );
00142 }
00143
00144
00145
00146 for( i = 0; i < ldab*n; i++ ) {
00147 ab_i[i] = ab_save[i];
00148 }
00149 for( i = 0; i < (MIN(m,n)); i++ ) {
00150 ipiv_i[i] = ipiv_save[i];
00151 }
00152 info_i = LAPACKE_cgbtrf( LAPACK_COL_MAJOR, m_i, n_i, kl_i, ku_i, ab_i,
00153 ldab_i, ipiv_i );
00154
00155 failed = compare_cgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00156 if( failed == 0 ) {
00157 printf( "PASSED: column-major high-level interface to cgbtrf\n" );
00158 } else {
00159 printf( "FAILED: column-major high-level interface to cgbtrf\n" );
00160 }
00161
00162
00163
00164 for( i = 0; i < ldab*n; i++ ) {
00165 ab_i[i] = ab_save[i];
00166 }
00167 for( i = 0; i < (MIN(m,n)); i++ ) {
00168 ipiv_i[i] = ipiv_save[i];
00169 }
00170
00171 LAPACKE_cge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00172 info_i = LAPACKE_cgbtrf_work( LAPACK_ROW_MAJOR, m_i, n_i, kl_i, ku_i, ab_r,
00173 ldab_r, ipiv_i );
00174
00175 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, 2*kl+ku+1, n, ab_r, n+2, ab_i, ldab );
00176
00177 failed = compare_cgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00178 if( failed == 0 ) {
00179 printf( "PASSED: row-major middle-level interface to cgbtrf\n" );
00180 } else {
00181 printf( "FAILED: row-major middle-level interface to cgbtrf\n" );
00182 }
00183
00184
00185
00186 for( i = 0; i < ldab*n; i++ ) {
00187 ab_i[i] = ab_save[i];
00188 }
00189 for( i = 0; i < (MIN(m,n)); i++ ) {
00190 ipiv_i[i] = ipiv_save[i];
00191 }
00192
00193
00194 LAPACKE_cge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00195 info_i = LAPACKE_cgbtrf( LAPACK_ROW_MAJOR, m_i, n_i, kl_i, ku_i, ab_r,
00196 ldab_r, ipiv_i );
00197
00198 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, 2*kl+ku+1, n, ab_r, n+2, ab_i, ldab );
00199
00200 failed = compare_cgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00201 if( failed == 0 ) {
00202 printf( "PASSED: row-major high-level interface to cgbtrf\n" );
00203 } else {
00204 printf( "FAILED: row-major high-level interface to cgbtrf\n" );
00205 }
00206
00207
00208 if( ab != NULL ) {
00209 LAPACKE_free( ab );
00210 }
00211 if( ab_i != NULL ) {
00212 LAPACKE_free( ab_i );
00213 }
00214 if( ab_r != NULL ) {
00215 LAPACKE_free( ab_r );
00216 }
00217 if( ab_save != NULL ) {
00218 LAPACKE_free( ab_save );
00219 }
00220 if( ipiv != NULL ) {
00221 LAPACKE_free( ipiv );
00222 }
00223 if( ipiv_i != NULL ) {
00224 LAPACKE_free( ipiv_i );
00225 }
00226 if( ipiv_save != NULL ) {
00227 LAPACKE_free( ipiv_save );
00228 }
00229
00230 return 0;
00231 }
00232
00233
00234 static void init_scalars_cgbtrf( lapack_int *m, lapack_int *n, lapack_int *kl,
00235 lapack_int *ku, lapack_int *ldab )
00236 {
00237 *m = 4;
00238 *n = 4;
00239 *kl = 1;
00240 *ku = 2;
00241 *ldab = 25;
00242
00243 return;
00244 }
00245
00246
00247 static void init_ab( lapack_int size, lapack_complex_float *ab ) {
00248 lapack_int i;
00249 for( i = 0; i < size; i++ ) {
00250 ab[i] = lapack_make_complex_float( 0.0f, 0.0f );
00251 }
00252 ab[0] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00253 ab[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00254 ab[50] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00255 ab[75] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00256 ab[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00257 ab[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00258 ab[51] = lapack_make_complex_float( 9.700000286e-001, -2.839999914e+000 );
00259 ab[76] = lapack_make_complex_float( 5.899999738e-001, -4.799999893e-001 );
00260 ab[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00261 ab[27] = lapack_make_complex_float( -2.049999952e+000, -8.500000238e-001 );
00262 ab[52] = lapack_make_complex_float( -3.990000010e+000, 4.010000229e+000 );
00263 ab[77] = lapack_make_complex_float( 3.329999924e+000, -1.039999962e+000 );
00264 ab[3] = lapack_make_complex_float( -1.649999976e+000, 2.259999990e+000 );
00265 ab[28] = lapack_make_complex_float( -1.480000019e+000, -1.750000000e+000 );
00266 ab[53] = lapack_make_complex_float( -1.059999943e+000, 1.940000057e+000 );
00267 ab[78] = lapack_make_complex_float( -4.600000083e-001, -1.720000029e+000 );
00268 ab[4] = lapack_make_complex_float( 0.000000000e+000, 6.300000191e+000 );
00269 ab[29] = lapack_make_complex_float( -7.699999809e-001, 2.829999924e+000 );
00270 ab[54] = lapack_make_complex_float( 4.480000019e+000, -1.090000033e+000 );
00271 ab[79] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00272 }
00273 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00274 lapack_int i;
00275 for( i = 0; i < size; i++ ) {
00276 ipiv[i] = 0;
00277 }
00278 }
00279
00280
00281
00282 static int compare_cgbtrf( lapack_complex_float *ab, lapack_complex_float *ab_i,
00283 lapack_int *ipiv, lapack_int *ipiv_i,
00284 lapack_int info, lapack_int info_i, lapack_int ldab,
00285 lapack_int m, lapack_int n )
00286 {
00287 lapack_int i;
00288 int failed = 0;
00289 for( i = 0; i < ldab*n; i++ ) {
00290 failed += compare_complex_floats(ab[i],ab_i[i]);
00291 }
00292 for( i = 0; i < (MIN(m,n)); i++ ) {
00293 failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00294 }
00295 failed += (info == info_i) ? 0 : 1;
00296 if( info != 0 || info_i != 0 ) {
00297 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00298 }
00299
00300 return failed;
00301 }