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_sgebal( char *job, lapack_int *n, lapack_int *lda );
00055 static void init_a( lapack_int size, float *a );
00056 static void init_scale( lapack_int size, float *scale );
00057 static int compare_sgebal( float *a, float *a_i, lapack_int ilo,
00058 lapack_int ilo_i, lapack_int ihi, lapack_int ihi_i,
00059 float *scale, float *scale_i, lapack_int info,
00060 lapack_int info_i, char job, lapack_int lda,
00061 lapack_int n );
00062
00063 int main(void)
00064 {
00065
00066 char job, job_i;
00067 lapack_int n, n_i;
00068 lapack_int lda, lda_i;
00069 lapack_int lda_r;
00070 lapack_int ilo, ilo_i;
00071 lapack_int ihi, ihi_i;
00072 lapack_int info, info_i;
00073 lapack_int i;
00074 int failed;
00075
00076
00077 float *a = NULL, *a_i = NULL;
00078 float *scale = NULL, *scale_i = NULL;
00079 float *a_save = NULL;
00080 float *scale_save = NULL;
00081 float *a_r = NULL;
00082
00083
00084 init_scalars_sgebal( &job, &n, &lda );
00085 lda_r = n+2;
00086 job_i = job;
00087 n_i = n;
00088 lda_i = lda;
00089
00090
00091 a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00092 scale = (float *)LAPACKE_malloc( n * sizeof(float) );
00093
00094
00095 a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00096 scale_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00097
00098
00099 a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00100 scale_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00101
00102
00103 a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00104
00105
00106 init_a( lda*n, a );
00107 init_scale( n, scale );
00108
00109
00110 for( i = 0; i < lda*n; i++ ) {
00111 a_save[i] = a[i];
00112 }
00113 for( i = 0; i < n; i++ ) {
00114 scale_save[i] = scale[i];
00115 }
00116
00117
00118 sgebal_( &job, &n, a, &lda, &ilo, &ihi, scale, &info );
00119
00120
00121
00122 for( i = 0; i < lda*n; i++ ) {
00123 a_i[i] = a_save[i];
00124 }
00125 for( i = 0; i < n; i++ ) {
00126 scale_i[i] = scale_save[i];
00127 }
00128 info_i = LAPACKE_sgebal_work( LAPACK_COL_MAJOR, job_i, n_i, a_i, lda_i,
00129 &ilo_i, &ihi_i, scale_i );
00130
00131 failed = compare_sgebal( a, a_i, ilo, ilo_i, ihi, ihi_i, scale, scale_i,
00132 info, info_i, job, lda, n );
00133 if( failed == 0 ) {
00134 printf( "PASSED: column-major middle-level interface to sgebal\n" );
00135 } else {
00136 printf( "FAILED: column-major middle-level interface to sgebal\n" );
00137 }
00138
00139
00140
00141 for( i = 0; i < lda*n; i++ ) {
00142 a_i[i] = a_save[i];
00143 }
00144 for( i = 0; i < n; i++ ) {
00145 scale_i[i] = scale_save[i];
00146 }
00147 info_i = LAPACKE_sgebal( LAPACK_COL_MAJOR, job_i, n_i, a_i, lda_i, &ilo_i,
00148 &ihi_i, scale_i );
00149
00150 failed = compare_sgebal( a, a_i, ilo, ilo_i, ihi, ihi_i, scale, scale_i,
00151 info, info_i, job, lda, n );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major high-level interface to sgebal\n" );
00154 } else {
00155 printf( "FAILED: column-major high-level interface to sgebal\n" );
00156 }
00157
00158
00159
00160 for( i = 0; i < lda*n; i++ ) {
00161 a_i[i] = a_save[i];
00162 }
00163 for( i = 0; i < n; i++ ) {
00164 scale_i[i] = scale_save[i];
00165 }
00166
00167 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'p' ) ||
00168 LAPACKE_lsame( job, 's' ) ) {
00169 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00170 }
00171 info_i = LAPACKE_sgebal_work( LAPACK_ROW_MAJOR, job_i, n_i, a_r, lda_r,
00172 &ilo_i, &ihi_i, scale_i );
00173
00174 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'p' ) ||
00175 LAPACKE_lsame( job, 's' ) ) {
00176 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00177 }
00178
00179 failed = compare_sgebal( a, a_i, ilo, ilo_i, ihi, ihi_i, scale, scale_i,
00180 info, info_i, job, lda, n );
00181 if( failed == 0 ) {
00182 printf( "PASSED: row-major middle-level interface to sgebal\n" );
00183 } else {
00184 printf( "FAILED: row-major middle-level interface to sgebal\n" );
00185 }
00186
00187
00188
00189 for( i = 0; i < lda*n; i++ ) {
00190 a_i[i] = a_save[i];
00191 }
00192 for( i = 0; i < n; i++ ) {
00193 scale_i[i] = scale_save[i];
00194 }
00195
00196
00197 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'p' ) ||
00198 LAPACKE_lsame( job, 's' ) ) {
00199 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00200 }
00201 info_i = LAPACKE_sgebal( LAPACK_ROW_MAJOR, job_i, n_i, a_r, lda_r, &ilo_i,
00202 &ihi_i, scale_i );
00203
00204 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'p' ) ||
00205 LAPACKE_lsame( job, 's' ) ) {
00206 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00207 }
00208
00209 failed = compare_sgebal( a, a_i, ilo, ilo_i, ihi, ihi_i, scale, scale_i,
00210 info, info_i, job, lda, n );
00211 if( failed == 0 ) {
00212 printf( "PASSED: row-major high-level interface to sgebal\n" );
00213 } else {
00214 printf( "FAILED: row-major high-level interface to sgebal\n" );
00215 }
00216
00217
00218 if( a != NULL ) {
00219 LAPACKE_free( a );
00220 }
00221 if( a_i != NULL ) {
00222 LAPACKE_free( a_i );
00223 }
00224 if( a_r != NULL ) {
00225 LAPACKE_free( a_r );
00226 }
00227 if( a_save != NULL ) {
00228 LAPACKE_free( a_save );
00229 }
00230 if( scale != NULL ) {
00231 LAPACKE_free( scale );
00232 }
00233 if( scale_i != NULL ) {
00234 LAPACKE_free( scale_i );
00235 }
00236 if( scale_save != NULL ) {
00237 LAPACKE_free( scale_save );
00238 }
00239
00240 return 0;
00241 }
00242
00243
00244 static void init_scalars_sgebal( char *job, lapack_int *n, lapack_int *lda )
00245 {
00246 *job = 'B';
00247 *n = 4;
00248 *lda = 8;
00249
00250 return;
00251 }
00252
00253
00254 static void init_a( lapack_int size, float *a ) {
00255 lapack_int i;
00256 for( i = 0; i < size; i++ ) {
00257 a[i] = 0;
00258 }
00259 a[0] = 5.139999866e+000;
00260 a[8] = 9.100000262e-001;
00261 a[16] = 0.000000000e+000;
00262 a[24] = -3.279999924e+001;
00263 a[1] = 9.100000262e-001;
00264 a[9] = 2.000000030e-001;
00265 a[17] = 0.000000000e+000;
00266 a[25] = 3.450000000e+001;
00267 a[2] = 1.899999976e+000;
00268 a[10] = 8.000000119e-001;
00269 a[18] = -4.000000060e-001;
00270 a[26] = -3.000000000e+000;
00271 a[3] = -3.300000131e-001;
00272 a[11] = 3.499999940e-001;
00273 a[19] = 0.000000000e+000;
00274 a[27] = 6.600000262e-001;
00275 }
00276 static void init_scale( lapack_int size, float *scale ) {
00277 lapack_int i;
00278 for( i = 0; i < size; i++ ) {
00279 scale[i] = 0;
00280 }
00281 }
00282
00283
00284
00285 static int compare_sgebal( float *a, float *a_i, lapack_int ilo,
00286 lapack_int ilo_i, lapack_int ihi, lapack_int ihi_i,
00287 float *scale, float *scale_i, lapack_int info,
00288 lapack_int info_i, char job, lapack_int lda,
00289 lapack_int n )
00290 {
00291 lapack_int i;
00292 int failed = 0;
00293 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'p' ) ||
00294 LAPACKE_lsame( job, 's' ) ) {
00295 for( i = 0; i < lda*n; i++ ) {
00296 failed += compare_floats(a[i],a_i[i]);
00297 }
00298 }
00299 failed += (ilo == ilo_i) ? 0 : 1;
00300 failed += (ihi == ihi_i) ? 0 : 1;
00301 for( i = 0; i < n; i++ ) {
00302 failed += compare_floats(scale[i],scale_i[i]);
00303 }
00304 failed += (info == info_i) ? 0 : 1;
00305 if( info != 0 || info_i != 0 ) {
00306 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00307 }
00308
00309 return failed;
00310 }