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