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_dgeqpf( lapack_int *m, lapack_int *n,
00055 lapack_int *lda );
00056 static void init_a( lapack_int size, double *a );
00057 static void init_jpvt( lapack_int size, lapack_int *jpvt );
00058 static void init_tau( lapack_int size, double *tau );
00059 static void init_work( lapack_int size, double *work );
00060 static int compare_dgeqpf( double *a, double *a_i, lapack_int *jpvt,
00061 lapack_int *jpvt_i, double *tau, double *tau_i,
00062 lapack_int info, lapack_int info_i, lapack_int lda,
00063 lapack_int m, lapack_int n );
00064
00065 int main(void)
00066 {
00067
00068 lapack_int m, m_i;
00069 lapack_int n, n_i;
00070 lapack_int lda, lda_i;
00071 lapack_int lda_r;
00072 lapack_int info, info_i;
00073 lapack_int i;
00074 int failed;
00075
00076
00077 double *a = NULL, *a_i = NULL;
00078 lapack_int *jpvt = NULL, *jpvt_i = NULL;
00079 double *tau = NULL, *tau_i = NULL;
00080 double *work = NULL, *work_i = NULL;
00081 double *a_save = NULL;
00082 lapack_int *jpvt_save = NULL;
00083 double *tau_save = NULL;
00084 double *a_r = NULL;
00085
00086
00087 init_scalars_dgeqpf( &m, &n, &lda );
00088 lda_r = n+2;
00089 m_i = m;
00090 n_i = n;
00091 lda_i = lda;
00092
00093
00094 a = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00095 jpvt = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00096 tau = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00097 work = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00098
00099
00100 a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00101 jpvt_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00102 tau_i = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00103 work_i = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00104
00105
00106 a_save = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00107 jpvt_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00108 tau_save = (double *)LAPACKE_malloc( MIN(m,n) * sizeof(double) );
00109
00110
00111 a_r = (double *)LAPACKE_malloc( m*(n+2) * sizeof(double) );
00112
00113
00114 init_a( lda*n, a );
00115 init_jpvt( n, jpvt );
00116 init_tau( (MIN(m,n)), tau );
00117 init_work( 3*n, work );
00118
00119
00120 for( i = 0; i < lda*n; i++ ) {
00121 a_save[i] = a[i];
00122 }
00123 for( i = 0; i < n; i++ ) {
00124 jpvt_save[i] = jpvt[i];
00125 }
00126 for( i = 0; i < (MIN(m,n)); i++ ) {
00127 tau_save[i] = tau[i];
00128 }
00129
00130
00131 dgeqpf_( &m, &n, a, &lda, jpvt, tau, work, &info );
00132
00133
00134
00135 for( i = 0; i < lda*n; i++ ) {
00136 a_i[i] = a_save[i];
00137 }
00138 for( i = 0; i < n; i++ ) {
00139 jpvt_i[i] = jpvt_save[i];
00140 }
00141 for( i = 0; i < (MIN(m,n)); i++ ) {
00142 tau_i[i] = tau_save[i];
00143 }
00144 for( i = 0; i < 3*n; i++ ) {
00145 work_i[i] = work[i];
00146 }
00147 info_i = LAPACKE_dgeqpf_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i,
00148 jpvt_i, tau_i, work_i );
00149
00150 failed = compare_dgeqpf( a, a_i, jpvt, jpvt_i, tau, tau_i, info, info_i,
00151 lda, m, n );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major middle-level interface to dgeqpf\n" );
00154 } else {
00155 printf( "FAILED: column-major middle-level interface to dgeqpf\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 jpvt_i[i] = jpvt_save[i];
00165 }
00166 for( i = 0; i < (MIN(m,n)); i++ ) {
00167 tau_i[i] = tau_save[i];
00168 }
00169 for( i = 0; i < 3*n; i++ ) {
00170 work_i[i] = work[i];
00171 }
00172 info_i = LAPACKE_dgeqpf( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, jpvt_i,
00173 tau_i );
00174
00175 failed = compare_dgeqpf( a, a_i, jpvt, jpvt_i, tau, tau_i, info, info_i,
00176 lda, m, n );
00177 if( failed == 0 ) {
00178 printf( "PASSED: column-major high-level interface to dgeqpf\n" );
00179 } else {
00180 printf( "FAILED: column-major high-level interface to dgeqpf\n" );
00181 }
00182
00183
00184
00185 for( i = 0; i < lda*n; i++ ) {
00186 a_i[i] = a_save[i];
00187 }
00188 for( i = 0; i < n; i++ ) {
00189 jpvt_i[i] = jpvt_save[i];
00190 }
00191 for( i = 0; i < (MIN(m,n)); i++ ) {
00192 tau_i[i] = tau_save[i];
00193 }
00194 for( i = 0; i < 3*n; i++ ) {
00195 work_i[i] = work[i];
00196 }
00197
00198 LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00199 info_i = LAPACKE_dgeqpf_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r,
00200 jpvt_i, tau_i, work_i );
00201
00202 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00203
00204 failed = compare_dgeqpf( a, a_i, jpvt, jpvt_i, tau, tau_i, info, info_i,
00205 lda, m, n );
00206 if( failed == 0 ) {
00207 printf( "PASSED: row-major middle-level interface to dgeqpf\n" );
00208 } else {
00209 printf( "FAILED: row-major middle-level interface to dgeqpf\n" );
00210 }
00211
00212
00213
00214 for( i = 0; i < lda*n; i++ ) {
00215 a_i[i] = a_save[i];
00216 }
00217 for( i = 0; i < n; i++ ) {
00218 jpvt_i[i] = jpvt_save[i];
00219 }
00220 for( i = 0; i < (MIN(m,n)); i++ ) {
00221 tau_i[i] = tau_save[i];
00222 }
00223 for( i = 0; i < 3*n; i++ ) {
00224 work_i[i] = work[i];
00225 }
00226
00227
00228 LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00229 info_i = LAPACKE_dgeqpf( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, jpvt_i,
00230 tau_i );
00231
00232 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00233
00234 failed = compare_dgeqpf( a, a_i, jpvt, jpvt_i, tau, tau_i, info, info_i,
00235 lda, m, n );
00236 if( failed == 0 ) {
00237 printf( "PASSED: row-major high-level interface to dgeqpf\n" );
00238 } else {
00239 printf( "FAILED: row-major high-level interface to dgeqpf\n" );
00240 }
00241
00242
00243 if( a != NULL ) {
00244 LAPACKE_free( a );
00245 }
00246 if( a_i != NULL ) {
00247 LAPACKE_free( a_i );
00248 }
00249 if( a_r != NULL ) {
00250 LAPACKE_free( a_r );
00251 }
00252 if( a_save != NULL ) {
00253 LAPACKE_free( a_save );
00254 }
00255 if( jpvt != NULL ) {
00256 LAPACKE_free( jpvt );
00257 }
00258 if( jpvt_i != NULL ) {
00259 LAPACKE_free( jpvt_i );
00260 }
00261 if( jpvt_save != NULL ) {
00262 LAPACKE_free( jpvt_save );
00263 }
00264 if( tau != NULL ) {
00265 LAPACKE_free( tau );
00266 }
00267 if( tau_i != NULL ) {
00268 LAPACKE_free( tau_i );
00269 }
00270 if( tau_save != NULL ) {
00271 LAPACKE_free( tau_save );
00272 }
00273 if( work != NULL ) {
00274 LAPACKE_free( work );
00275 }
00276 if( work_i != NULL ) {
00277 LAPACKE_free( work_i );
00278 }
00279
00280 return 0;
00281 }
00282
00283
00284 static void init_scalars_dgeqpf( lapack_int *m, lapack_int *n, lapack_int *lda )
00285 {
00286 *m = 6;
00287 *n = 5;
00288 *lda = 8;
00289
00290 return;
00291 }
00292
00293
00294 static void init_a( lapack_int size, double *a ) {
00295 lapack_int i;
00296 for( i = 0; i < size; i++ ) {
00297 a[i] = 0;
00298 }
00299 a[0] = -8.99999999999999970e-002;
00300 a[8] = 1.40000000000000010e-001;
00301 a[16] = -4.60000000000000020e-001;
00302 a[24] = 6.80000000000000050e-001;
00303 a[32] = 1.29000000000000000e+000;
00304 a[1] = -1.56000000000000010e+000;
00305 a[9] = 2.00000000000000010e-001;
00306 a[17] = 2.89999999999999980e-001;
00307 a[25] = 1.09000000000000010e+000;
00308 a[33] = 5.10000000000000010e-001;
00309 a[2] = -1.48000000000000000e+000;
00310 a[10] = -4.29999999999999990e-001;
00311 a[18] = 8.90000000000000010e-001;
00312 a[26] = -7.09999999999999960e-001;
00313 a[34] = -9.59999999999999960e-001;
00314 a[3] = -1.09000000000000010e+000;
00315 a[11] = 8.39999999999999970e-001;
00316 a[19] = 7.70000000000000020e-001;
00317 a[27] = 2.10999999999999990e+000;
00318 a[35] = -1.27000000000000000e+000;
00319 a[4] = 8.00000000000000020e-002;
00320 a[12] = 5.50000000000000040e-001;
00321 a[20] = -1.12999999999999990e+000;
00322 a[28] = 1.40000000000000010e-001;
00323 a[36] = 1.74000000000000000e+000;
00324 a[5] = -1.59000000000000010e+000;
00325 a[13] = -7.19999999999999970e-001;
00326 a[21] = 1.06000000000000010e+000;
00327 a[29] = 1.24000000000000000e+000;
00328 a[37] = 3.40000000000000020e-001;
00329 }
00330 static void init_jpvt( lapack_int size, lapack_int *jpvt ) {
00331 lapack_int i;
00332 for( i = 0; i < size; i++ ) {
00333 jpvt[i] = 0;
00334 }
00335 jpvt[0] = 0;
00336 jpvt[1] = 0;
00337 jpvt[2] = 0;
00338 jpvt[3] = 0;
00339 jpvt[4] = 0;
00340 }
00341 static void init_tau( lapack_int size, double *tau ) {
00342 lapack_int i;
00343 for( i = 0; i < size; i++ ) {
00344 tau[i] = 0;
00345 }
00346 }
00347 static void init_work( lapack_int size, double *work ) {
00348 lapack_int i;
00349 for( i = 0; i < size; i++ ) {
00350 work[i] = 0;
00351 }
00352 }
00353
00354
00355
00356 static int compare_dgeqpf( double *a, double *a_i, lapack_int *jpvt,
00357 lapack_int *jpvt_i, double *tau, double *tau_i,
00358 lapack_int info, lapack_int info_i, lapack_int lda,
00359 lapack_int m, lapack_int n )
00360 {
00361 lapack_int i;
00362 int failed = 0;
00363 for( i = 0; i < lda*n; i++ ) {
00364 failed += compare_doubles(a[i],a_i[i]);
00365 }
00366 for( i = 0; i < n; i++ ) {
00367 failed += (jpvt[i] == jpvt_i[i]) ? 0 : 1;
00368 }
00369 for( i = 0; i < (MIN(m,n)); i++ ) {
00370 failed += compare_doubles(tau[i],tau_i[i]);
00371 }
00372 failed += (info == info_i) ? 0 : 1;
00373 if( info != 0 || info_i != 0 ) {
00374 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00375 }
00376
00377 return failed;
00378 }