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_cgeqpf( lapack_int *m, lapack_int *n,
00055 lapack_int *lda );
00056 static void init_a( lapack_int size, lapack_complex_float *a );
00057 static void init_jpvt( lapack_int size, lapack_int *jpvt );
00058 static void init_tau( lapack_int size, lapack_complex_float *tau );
00059 static void init_work( lapack_int size, lapack_complex_float *work );
00060 static void init_rwork( lapack_int size, float *rwork );
00061 static int compare_cgeqpf( lapack_complex_float *a, lapack_complex_float *a_i,
00062 lapack_int *jpvt, lapack_int *jpvt_i,
00063 lapack_complex_float *tau,
00064 lapack_complex_float *tau_i, lapack_int info,
00065 lapack_int info_i, lapack_int lda, lapack_int m,
00066 lapack_int n );
00067
00068 int main(void)
00069 {
00070
00071 lapack_int m, m_i;
00072 lapack_int n, n_i;
00073 lapack_int lda, lda_i;
00074 lapack_int lda_r;
00075 lapack_int info, info_i;
00076 lapack_int i;
00077 int failed;
00078
00079
00080 lapack_complex_float *a = NULL, *a_i = NULL;
00081 lapack_int *jpvt = NULL, *jpvt_i = NULL;
00082 lapack_complex_float *tau = NULL, *tau_i = NULL;
00083 lapack_complex_float *work = NULL, *work_i = NULL;
00084 float *rwork = NULL, *rwork_i = NULL;
00085 lapack_complex_float *a_save = NULL;
00086 lapack_int *jpvt_save = NULL;
00087 lapack_complex_float *tau_save = NULL;
00088 lapack_complex_float *a_r = NULL;
00089
00090
00091 init_scalars_cgeqpf( &m, &n, &lda );
00092 lda_r = n+2;
00093 m_i = m;
00094 n_i = n;
00095 lda_i = lda;
00096
00097
00098 a = (lapack_complex_float *)
00099 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00100 jpvt = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00101 tau = (lapack_complex_float *)
00102 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00103 work = (lapack_complex_float *)
00104 LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00105 rwork = (float *)LAPACKE_malloc( 2*n * sizeof(float) );
00106
00107
00108 a_i = (lapack_complex_float *)
00109 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00110 jpvt_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00111 tau_i = (lapack_complex_float *)
00112 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00113 work_i = (lapack_complex_float *)
00114 LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00115 rwork_i = (float *)LAPACKE_malloc( 2*n * sizeof(float) );
00116
00117
00118 a_save = (lapack_complex_float *)
00119 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00120 jpvt_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00121 tau_save = (lapack_complex_float *)
00122 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00123
00124
00125 a_r = (lapack_complex_float *)
00126 LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) );
00127
00128
00129 init_a( lda*n, a );
00130 init_jpvt( n, jpvt );
00131 init_tau( (MIN(m,n)), tau );
00132 init_work( n, work );
00133 init_rwork( 2*n, rwork );
00134
00135
00136 for( i = 0; i < lda*n; i++ ) {
00137 a_save[i] = a[i];
00138 }
00139 for( i = 0; i < n; i++ ) {
00140 jpvt_save[i] = jpvt[i];
00141 }
00142 for( i = 0; i < (MIN(m,n)); i++ ) {
00143 tau_save[i] = tau[i];
00144 }
00145
00146
00147 cgeqpf_( &m, &n, a, &lda, jpvt, tau, work, rwork, &info );
00148
00149
00150
00151 for( i = 0; i < lda*n; i++ ) {
00152 a_i[i] = a_save[i];
00153 }
00154 for( i = 0; i < n; i++ ) {
00155 jpvt_i[i] = jpvt_save[i];
00156 }
00157 for( i = 0; i < (MIN(m,n)); i++ ) {
00158 tau_i[i] = tau_save[i];
00159 }
00160 for( i = 0; i < n; i++ ) {
00161 work_i[i] = work[i];
00162 }
00163 for( i = 0; i < 2*n; i++ ) {
00164 rwork_i[i] = rwork[i];
00165 }
00166 info_i = LAPACKE_cgeqpf_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i,
00167 jpvt_i, tau_i, work_i, rwork_i );
00168
00169 failed = compare_cgeqpf( a, a_i, jpvt, jpvt_i, tau, tau_i, info, info_i,
00170 lda, m, n );
00171 if( failed == 0 ) {
00172 printf( "PASSED: column-major middle-level interface to cgeqpf\n" );
00173 } else {
00174 printf( "FAILED: column-major middle-level interface to cgeqpf\n" );
00175 }
00176
00177
00178
00179 for( i = 0; i < lda*n; i++ ) {
00180 a_i[i] = a_save[i];
00181 }
00182 for( i = 0; i < n; i++ ) {
00183 jpvt_i[i] = jpvt_save[i];
00184 }
00185 for( i = 0; i < (MIN(m,n)); i++ ) {
00186 tau_i[i] = tau_save[i];
00187 }
00188 for( i = 0; i < n; i++ ) {
00189 work_i[i] = work[i];
00190 }
00191 for( i = 0; i < 2*n; i++ ) {
00192 rwork_i[i] = rwork[i];
00193 }
00194 info_i = LAPACKE_cgeqpf( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, jpvt_i,
00195 tau_i );
00196
00197 failed = compare_cgeqpf( a, a_i, jpvt, jpvt_i, tau, tau_i, info, info_i,
00198 lda, m, n );
00199 if( failed == 0 ) {
00200 printf( "PASSED: column-major high-level interface to cgeqpf\n" );
00201 } else {
00202 printf( "FAILED: column-major high-level interface to cgeqpf\n" );
00203 }
00204
00205
00206
00207 for( i = 0; i < lda*n; i++ ) {
00208 a_i[i] = a_save[i];
00209 }
00210 for( i = 0; i < n; i++ ) {
00211 jpvt_i[i] = jpvt_save[i];
00212 }
00213 for( i = 0; i < (MIN(m,n)); i++ ) {
00214 tau_i[i] = tau_save[i];
00215 }
00216 for( i = 0; i < n; i++ ) {
00217 work_i[i] = work[i];
00218 }
00219 for( i = 0; i < 2*n; i++ ) {
00220 rwork_i[i] = rwork[i];
00221 }
00222
00223 LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00224 info_i = LAPACKE_cgeqpf_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r,
00225 jpvt_i, tau_i, work_i, rwork_i );
00226
00227 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00228
00229 failed = compare_cgeqpf( a, a_i, jpvt, jpvt_i, tau, tau_i, info, info_i,
00230 lda, m, n );
00231 if( failed == 0 ) {
00232 printf( "PASSED: row-major middle-level interface to cgeqpf\n" );
00233 } else {
00234 printf( "FAILED: row-major middle-level interface to cgeqpf\n" );
00235 }
00236
00237
00238
00239 for( i = 0; i < lda*n; i++ ) {
00240 a_i[i] = a_save[i];
00241 }
00242 for( i = 0; i < n; i++ ) {
00243 jpvt_i[i] = jpvt_save[i];
00244 }
00245 for( i = 0; i < (MIN(m,n)); i++ ) {
00246 tau_i[i] = tau_save[i];
00247 }
00248 for( i = 0; i < n; i++ ) {
00249 work_i[i] = work[i];
00250 }
00251 for( i = 0; i < 2*n; i++ ) {
00252 rwork_i[i] = rwork[i];
00253 }
00254
00255
00256 LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00257 info_i = LAPACKE_cgeqpf( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, jpvt_i,
00258 tau_i );
00259
00260 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00261
00262 failed = compare_cgeqpf( a, a_i, jpvt, jpvt_i, tau, tau_i, info, info_i,
00263 lda, m, n );
00264 if( failed == 0 ) {
00265 printf( "PASSED: row-major high-level interface to cgeqpf\n" );
00266 } else {
00267 printf( "FAILED: row-major high-level interface to cgeqpf\n" );
00268 }
00269
00270
00271 if( a != NULL ) {
00272 LAPACKE_free( a );
00273 }
00274 if( a_i != NULL ) {
00275 LAPACKE_free( a_i );
00276 }
00277 if( a_r != NULL ) {
00278 LAPACKE_free( a_r );
00279 }
00280 if( a_save != NULL ) {
00281 LAPACKE_free( a_save );
00282 }
00283 if( jpvt != NULL ) {
00284 LAPACKE_free( jpvt );
00285 }
00286 if( jpvt_i != NULL ) {
00287 LAPACKE_free( jpvt_i );
00288 }
00289 if( jpvt_save != NULL ) {
00290 LAPACKE_free( jpvt_save );
00291 }
00292 if( tau != NULL ) {
00293 LAPACKE_free( tau );
00294 }
00295 if( tau_i != NULL ) {
00296 LAPACKE_free( tau_i );
00297 }
00298 if( tau_save != NULL ) {
00299 LAPACKE_free( tau_save );
00300 }
00301 if( work != NULL ) {
00302 LAPACKE_free( work );
00303 }
00304 if( work_i != NULL ) {
00305 LAPACKE_free( work_i );
00306 }
00307 if( rwork != NULL ) {
00308 LAPACKE_free( rwork );
00309 }
00310 if( rwork_i != NULL ) {
00311 LAPACKE_free( rwork_i );
00312 }
00313
00314 return 0;
00315 }
00316
00317
00318 static void init_scalars_cgeqpf( lapack_int *m, lapack_int *n, lapack_int *lda )
00319 {
00320 *m = 5;
00321 *n = 4;
00322 *lda = 8;
00323
00324 return;
00325 }
00326
00327
00328 static void init_a( lapack_int size, lapack_complex_float *a ) {
00329 lapack_int i;
00330 for( i = 0; i < size; i++ ) {
00331 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00332 }
00333 a[0] = lapack_make_complex_float( 4.699999988e-001, -3.400000036e-001 );
00334 a[8] = lapack_make_complex_float( -4.000000060e-001, 5.400000215e-001 );
00335 a[16] = lapack_make_complex_float( 6.000000238e-001, 9.999999776e-003 );
00336 a[24] = lapack_make_complex_float( 8.000000119e-001, -1.019999981e+000 );
00337 a[1] = lapack_make_complex_float( -3.199999928e-001, -2.300000042e-001 );
00338 a[9] = lapack_make_complex_float( -5.000000075e-002, 2.000000030e-001 );
00339 a[17] = lapack_make_complex_float( -2.599999905e-001, -4.399999976e-001 );
00340 a[25] = lapack_make_complex_float( -4.300000072e-001, 1.700000018e-001 );
00341 a[2] = lapack_make_complex_float( 3.499999940e-001, -6.000000238e-001 );
00342 a[10] = lapack_make_complex_float( -5.199999809e-001, -3.400000036e-001 );
00343 a[18] = lapack_make_complex_float( 8.700000048e-001, -1.099999994e-001 );
00344 a[26] = lapack_make_complex_float( -3.400000036e-001, -9.000000358e-002 );
00345 a[3] = lapack_make_complex_float( 8.899999857e-001, 7.099999785e-001 );
00346 a[11] = lapack_make_complex_float( -4.499999881e-001, -4.499999881e-001 );
00347 a[19] = lapack_make_complex_float( -1.999999955e-002, -5.699999928e-001 );
00348 a[27] = lapack_make_complex_float( 1.139999986e+000, -7.799999714e-001 );
00349 a[4] = lapack_make_complex_float( -1.899999976e-001, 5.999999866e-002 );
00350 a[12] = lapack_make_complex_float( 1.099999994e-001, -8.500000238e-001 );
00351 a[20] = lapack_make_complex_float( 1.440000057e+000, 8.000000119e-001 );
00352 a[28] = lapack_make_complex_float( 7.000000030e-002, 1.139999986e+000 );
00353 }
00354 static void init_jpvt( lapack_int size, lapack_int *jpvt ) {
00355 lapack_int i;
00356 for( i = 0; i < size; i++ ) {
00357 jpvt[i] = 0;
00358 }
00359 jpvt[0] = 0;
00360 jpvt[1] = 0;
00361 jpvt[2] = 0;
00362 jpvt[3] = 0;
00363 }
00364 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00365 lapack_int i;
00366 for( i = 0; i < size; i++ ) {
00367 tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00368 }
00369 }
00370 static void init_work( lapack_int size, lapack_complex_float *work ) {
00371 lapack_int i;
00372 for( i = 0; i < size; i++ ) {
00373 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00374 }
00375 }
00376 static void init_rwork( lapack_int size, float *rwork ) {
00377 lapack_int i;
00378 for( i = 0; i < size; i++ ) {
00379 rwork[i] = 0;
00380 }
00381 }
00382
00383
00384
00385 static int compare_cgeqpf( lapack_complex_float *a, lapack_complex_float *a_i,
00386 lapack_int *jpvt, lapack_int *jpvt_i,
00387 lapack_complex_float *tau,
00388 lapack_complex_float *tau_i, lapack_int info,
00389 lapack_int info_i, lapack_int lda, lapack_int m,
00390 lapack_int n )
00391 {
00392 lapack_int i;
00393 int failed = 0;
00394 for( i = 0; i < lda*n; i++ ) {
00395 failed += compare_complex_floats(a[i],a_i[i]);
00396 }
00397 for( i = 0; i < n; i++ ) {
00398 failed += (jpvt[i] == jpvt_i[i]) ? 0 : 1;
00399 }
00400 for( i = 0; i < (MIN(m,n)); i++ ) {
00401 failed += compare_complex_floats(tau[i],tau_i[i]);
00402 }
00403 failed += (info == info_i) ? 0 : 1;
00404 if( info != 0 || info_i != 0 ) {
00405 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00406 }
00407
00408 return failed;
00409 }