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_sormbr( char *vect, char *side, char *trans,
00055 lapack_int *m, lapack_int *n, lapack_int *k,
00056 lapack_int *lda, lapack_int *ldc,
00057 lapack_int *lwork );
00058 static void init_a( lapack_int size, float *a );
00059 static void init_tau( lapack_int size, float *tau );
00060 static void init_c( lapack_int size, float *c );
00061 static void init_work( lapack_int size, float *work );
00062 static int compare_sormbr( float *c, float *c_i, lapack_int info,
00063 lapack_int info_i, lapack_int ldc, lapack_int n );
00064
00065 int main(void)
00066 {
00067
00068 char vect, vect_i;
00069 char side, side_i;
00070 char trans, trans_i;
00071 lapack_int m, m_i;
00072 lapack_int n, n_i;
00073 lapack_int k, k_i;
00074 lapack_int lda, lda_i;
00075 lapack_int lda_r;
00076 lapack_int ldc, ldc_i;
00077 lapack_int ldc_r;
00078 lapack_int lwork, lwork_i;
00079 lapack_int info, info_i;
00080
00081 lapack_int nq;
00082 lapack_int r;
00083 lapack_int i;
00084 int failed;
00085
00086
00087 float *a = NULL, *a_i = NULL;
00088 float *tau = NULL, *tau_i = NULL;
00089 float *c = NULL, *c_i = NULL;
00090 float *work = NULL, *work_i = NULL;
00091 float *c_save = NULL;
00092 float *a_r = NULL;
00093 float *c_r = NULL;
00094
00095
00096 init_scalars_sormbr( &vect, &side, &trans, &m, &n, &k, &lda, &ldc, &lwork );
00097 nq = LAPACKE_lsame( side, 'l' ) ? m : n;
00098 r = LAPACKE_lsame( vect, 'q' ) ? nq : MIN(nq,k);
00099 lda_r = MIN(nq,k)+2;
00100 ldc_r = n+2;
00101 vect_i = vect;
00102 side_i = side;
00103 trans_i = trans;
00104 m_i = m;
00105 n_i = n;
00106 k_i = k;
00107 lda_i = lda;
00108 ldc_i = ldc;
00109 lwork_i = lwork;
00110
00111
00112 a = (float *)LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(float) );
00113 tau = (float *)LAPACKE_malloc( MIN(nq,k) * sizeof(float) );
00114 c = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00115 work = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00116
00117
00118 a_i = (float *)LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(float) );
00119 tau_i = (float *)LAPACKE_malloc( MIN(nq,k) * sizeof(float) );
00120 c_i = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00121 work_i = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00122
00123
00124 c_save = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00125
00126
00127 a_r = (float *)LAPACKE_malloc( (r*(MIN(nq,k)+2)) * sizeof(float) );
00128 c_r = (float *)LAPACKE_malloc( m*(n+2) * sizeof(float) );
00129
00130
00131 init_a( lda*(MIN(nq,k)), a );
00132 init_tau( (MIN(nq,k)), tau );
00133 init_c( ldc*n, c );
00134 init_work( lwork, work );
00135
00136
00137 for( i = 0; i < ldc*n; i++ ) {
00138 c_save[i] = c[i];
00139 }
00140
00141
00142 sormbr_( &vect, &side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, work,
00143 &lwork, &info );
00144
00145
00146
00147 for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00148 a_i[i] = a[i];
00149 }
00150 for( i = 0; i < (MIN(nq,k)); i++ ) {
00151 tau_i[i] = tau[i];
00152 }
00153 for( i = 0; i < ldc*n; i++ ) {
00154 c_i[i] = c_save[i];
00155 }
00156 for( i = 0; i < lwork; i++ ) {
00157 work_i[i] = work[i];
00158 }
00159 info_i = LAPACKE_sormbr_work( LAPACK_COL_MAJOR, vect_i, side_i, trans_i,
00160 m_i, n_i, k_i, a_i, lda_i, tau_i, c_i, ldc_i,
00161 work_i, lwork_i );
00162
00163 failed = compare_sormbr( c, c_i, info, info_i, ldc, n );
00164 if( failed == 0 ) {
00165 printf( "PASSED: column-major middle-level interface to sormbr\n" );
00166 } else {
00167 printf( "FAILED: column-major middle-level interface to sormbr\n" );
00168 }
00169
00170
00171
00172 for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00173 a_i[i] = a[i];
00174 }
00175 for( i = 0; i < (MIN(nq,k)); i++ ) {
00176 tau_i[i] = tau[i];
00177 }
00178 for( i = 0; i < ldc*n; i++ ) {
00179 c_i[i] = c_save[i];
00180 }
00181 for( i = 0; i < lwork; i++ ) {
00182 work_i[i] = work[i];
00183 }
00184 info_i = LAPACKE_sormbr( LAPACK_COL_MAJOR, vect_i, side_i, trans_i, m_i,
00185 n_i, k_i, a_i, lda_i, tau_i, c_i, ldc_i );
00186
00187 failed = compare_sormbr( c, c_i, info, info_i, ldc, n );
00188 if( failed == 0 ) {
00189 printf( "PASSED: column-major high-level interface to sormbr\n" );
00190 } else {
00191 printf( "FAILED: column-major high-level interface to sormbr\n" );
00192 }
00193
00194
00195
00196 for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00197 a_i[i] = a[i];
00198 }
00199 for( i = 0; i < (MIN(nq,k)); i++ ) {
00200 tau_i[i] = tau[i];
00201 }
00202 for( i = 0; i < ldc*n; i++ ) {
00203 c_i[i] = c_save[i];
00204 }
00205 for( i = 0; i < lwork; i++ ) {
00206 work_i[i] = work[i];
00207 }
00208
00209 LAPACKE_sge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00210 k)+2);
00211 LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00212 info_i = LAPACKE_sormbr_work( LAPACK_ROW_MAJOR, vect_i, side_i, trans_i,
00213 m_i, n_i, k_i, a_r, lda_r, tau_i, c_r, ldc_r,
00214 work_i, lwork_i );
00215
00216 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00217
00218 failed = compare_sormbr( c, c_i, info, info_i, ldc, n );
00219 if( failed == 0 ) {
00220 printf( "PASSED: row-major middle-level interface to sormbr\n" );
00221 } else {
00222 printf( "FAILED: row-major middle-level interface to sormbr\n" );
00223 }
00224
00225
00226
00227 for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00228 a_i[i] = a[i];
00229 }
00230 for( i = 0; i < (MIN(nq,k)); i++ ) {
00231 tau_i[i] = tau[i];
00232 }
00233 for( i = 0; i < ldc*n; i++ ) {
00234 c_i[i] = c_save[i];
00235 }
00236 for( i = 0; i < lwork; i++ ) {
00237 work_i[i] = work[i];
00238 }
00239
00240
00241 LAPACKE_sge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00242 k)+2);
00243 LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00244 info_i = LAPACKE_sormbr( LAPACK_ROW_MAJOR, vect_i, side_i, trans_i, m_i,
00245 n_i, k_i, a_r, lda_r, tau_i, c_r, ldc_r );
00246
00247 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00248
00249 failed = compare_sormbr( c, c_i, info, info_i, ldc, n );
00250 if( failed == 0 ) {
00251 printf( "PASSED: row-major high-level interface to sormbr\n" );
00252 } else {
00253 printf( "FAILED: row-major high-level interface to sormbr\n" );
00254 }
00255
00256
00257 if( a != NULL ) {
00258 LAPACKE_free( a );
00259 }
00260 if( a_i != NULL ) {
00261 LAPACKE_free( a_i );
00262 }
00263 if( a_r != NULL ) {
00264 LAPACKE_free( a_r );
00265 }
00266 if( tau != NULL ) {
00267 LAPACKE_free( tau );
00268 }
00269 if( tau_i != NULL ) {
00270 LAPACKE_free( tau_i );
00271 }
00272 if( c != NULL ) {
00273 LAPACKE_free( c );
00274 }
00275 if( c_i != NULL ) {
00276 LAPACKE_free( c_i );
00277 }
00278 if( c_r != NULL ) {
00279 LAPACKE_free( c_r );
00280 }
00281 if( c_save != NULL ) {
00282 LAPACKE_free( c_save );
00283 }
00284 if( work != NULL ) {
00285 LAPACKE_free( work );
00286 }
00287 if( work_i != NULL ) {
00288 LAPACKE_free( work_i );
00289 }
00290
00291 return 0;
00292 }
00293
00294
00295 static void init_scalars_sormbr( char *vect, char *side, char *trans,
00296 lapack_int *m, lapack_int *n, lapack_int *k,
00297 lapack_int *lda, lapack_int *ldc,
00298 lapack_int *lwork )
00299 {
00300 *vect = 'Q';
00301 *side = 'R';
00302 *trans = 'N';
00303 *m = 6;
00304 *n = 4;
00305 *k = 4;
00306 *lda = 8;
00307 *ldc = 8;
00308 *lwork = 1024;
00309
00310 return;
00311 }
00312
00313
00314 static void init_a( lapack_int size, float *a ) {
00315 lapack_int i;
00316 for( i = 0; i < size; i++ ) {
00317 a[i] = 0;
00318 }
00319 a[0] = 3.617678881e+000;
00320 a[8] = 1.258711457e+000;
00321 a[16] = -4.667885602e-001;
00322 a[24] = -4.109506011e-001;
00323 a[1] = 0.000000000e+000;
00324 a[9] = -2.416055441e+000;
00325 a[17] = -1.526155114e+000;
00326 a[25] = -2.094555795e-001;
00327 a[2] = 0.000000000e+000;
00328 a[10] = 2.040916309e-002;
00329 a[18] = 1.921310782e+000;
00330 a[26] = 1.189466834e+000;
00331 a[3] = 0.000000000e+000;
00332 a[11] = -3.216264248e-001;
00333 a[19] = 1.342281103e-001;
00334 a[27] = -1.426501751e+000;
00335 }
00336 static void init_tau( lapack_int size, float *tau ) {
00337 lapack_int i;
00338 for( i = 0; i < size; i++ ) {
00339 tau[i] = 0;
00340 }
00341 tau[0] = 0.000000000e+000;
00342 tau[1] = 1.811823726e+000;
00343 tau[2] = 1.964603305e+000;
00344 tau[3] = 0.000000000e+000;
00345 }
00346 static void init_c( lapack_int size, float *c ) {
00347 lapack_int i;
00348 for( i = 0; i < size; i++ ) {
00349 c[i] = 0;
00350 }
00351 c[0] = -1.575596333e-001;
00352 c[8] = 6.743814945e-001;
00353 c[16] = -4.571500421e-001;
00354 c[24] = 4.488516748e-001;
00355 c[1] = -5.334912539e-001;
00356 c[9] = -3.861090243e-001;
00357 c[17] = 2.582527399e-001;
00358 c[25] = 3.898173869e-001;
00359 c[2] = 6.357668042e-001;
00360 c[10] = -2.928230762e-001;
00361 c[18] = 1.653843932e-002;
00362 c[26] = 1.929529309e-001;
00363 c[3] = -5.334912539e-001;
00364 c[11] = -1.691546589e-001;
00365 c[19] = -8.342742920e-002;
00366 c[27] = -2.349872589e-001;
00367 c[4] = 4.146305099e-002;
00368 c[12] = -1.593027860e-001;
00369 c[20] = 1.474783123e-001;
00370 c[28] = 7.436407804e-001;
00371 c[5] = -5.528406706e-003;
00372 c[13] = -5.063529611e-001;
00373 c[21] = -8.338680863e-001;
00374 c[29] = 3.351286054e-002;
00375 }
00376 static void init_work( lapack_int size, float *work ) {
00377 lapack_int i;
00378 for( i = 0; i < size; i++ ) {
00379 work[i] = 0;
00380 }
00381 }
00382
00383
00384
00385 static int compare_sormbr( float *c, float *c_i, lapack_int info,
00386 lapack_int info_i, lapack_int ldc, lapack_int n )
00387 {
00388 lapack_int i;
00389 int failed = 0;
00390 for( i = 0; i < ldc*n; i++ ) {
00391 failed += compare_floats(c[i],c_i[i]);
00392 }
00393 failed += (info == info_i) ? 0 : 1;
00394 if( info != 0 || info_i != 0 ) {
00395 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00396 }
00397
00398 return failed;
00399 }