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_cgelqf( lapack_int *m, lapack_int *n, lapack_int *lda,
00055 lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_float *a );
00057 static void init_tau( lapack_int size, lapack_complex_float *tau );
00058 static void init_work( lapack_int size, lapack_complex_float *work );
00059 static int compare_cgelqf( lapack_complex_float *a, lapack_complex_float *a_i,
00060 lapack_complex_float *tau,
00061 lapack_complex_float *tau_i, lapack_int info,
00062 lapack_int info_i, lapack_int lda, lapack_int m,
00063 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 lwork, lwork_i;
00073 lapack_int info, info_i;
00074 lapack_int i;
00075 int failed;
00076
00077
00078 lapack_complex_float *a = NULL, *a_i = NULL;
00079 lapack_complex_float *tau = NULL, *tau_i = NULL;
00080 lapack_complex_float *work = NULL, *work_i = NULL;
00081 lapack_complex_float *a_save = NULL;
00082 lapack_complex_float *tau_save = NULL;
00083 lapack_complex_float *a_r = NULL;
00084
00085
00086 init_scalars_cgelqf( &m, &n, &lda, &lwork );
00087 lda_r = n+2;
00088 m_i = m;
00089 n_i = n;
00090 lda_i = lda;
00091 lwork_i = lwork;
00092
00093
00094 a = (lapack_complex_float *)
00095 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00096 tau = (lapack_complex_float *)
00097 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00098 work = (lapack_complex_float *)
00099 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00100
00101
00102 a_i = (lapack_complex_float *)
00103 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00104 tau_i = (lapack_complex_float *)
00105 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00106 work_i = (lapack_complex_float *)
00107 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00108
00109
00110 a_save = (lapack_complex_float *)
00111 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00112 tau_save = (lapack_complex_float *)
00113 LAPACKE_malloc( MIN(m,n) * sizeof(lapack_complex_float) );
00114
00115
00116 a_r = (lapack_complex_float *)
00117 LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) );
00118
00119
00120 init_a( lda*n, a );
00121 init_tau( (MIN(m,n)), tau );
00122 init_work( lwork, work );
00123
00124
00125 for( i = 0; i < lda*n; i++ ) {
00126 a_save[i] = a[i];
00127 }
00128 for( i = 0; i < (MIN(m,n)); i++ ) {
00129 tau_save[i] = tau[i];
00130 }
00131
00132
00133 cgelqf_( &m, &n, a, &lda, tau, work, &lwork, &info );
00134
00135
00136
00137 for( i = 0; i < lda*n; i++ ) {
00138 a_i[i] = a_save[i];
00139 }
00140 for( i = 0; i < (MIN(m,n)); i++ ) {
00141 tau_i[i] = tau_save[i];
00142 }
00143 for( i = 0; i < lwork; i++ ) {
00144 work_i[i] = work[i];
00145 }
00146 info_i = LAPACKE_cgelqf_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, tau_i,
00147 work_i, lwork_i );
00148
00149 failed = compare_cgelqf( a, a_i, tau, tau_i, info, info_i, lda, m, n );
00150 if( failed == 0 ) {
00151 printf( "PASSED: column-major middle-level interface to cgelqf\n" );
00152 } else {
00153 printf( "FAILED: column-major middle-level interface to cgelqf\n" );
00154 }
00155
00156
00157
00158 for( i = 0; i < lda*n; i++ ) {
00159 a_i[i] = a_save[i];
00160 }
00161 for( i = 0; i < (MIN(m,n)); i++ ) {
00162 tau_i[i] = tau_save[i];
00163 }
00164 for( i = 0; i < lwork; i++ ) {
00165 work_i[i] = work[i];
00166 }
00167 info_i = LAPACKE_cgelqf( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, tau_i );
00168
00169 failed = compare_cgelqf( a, a_i, tau, tau_i, info, info_i, lda, m, n );
00170 if( failed == 0 ) {
00171 printf( "PASSED: column-major high-level interface to cgelqf\n" );
00172 } else {
00173 printf( "FAILED: column-major high-level interface to cgelqf\n" );
00174 }
00175
00176
00177
00178 for( i = 0; i < lda*n; i++ ) {
00179 a_i[i] = a_save[i];
00180 }
00181 for( i = 0; i < (MIN(m,n)); i++ ) {
00182 tau_i[i] = tau_save[i];
00183 }
00184 for( i = 0; i < lwork; i++ ) {
00185 work_i[i] = work[i];
00186 }
00187
00188 LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00189 info_i = LAPACKE_cgelqf_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, tau_i,
00190 work_i, lwork_i );
00191
00192 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00193
00194 failed = compare_cgelqf( a, a_i, tau, tau_i, info, info_i, lda, m, n );
00195 if( failed == 0 ) {
00196 printf( "PASSED: row-major middle-level interface to cgelqf\n" );
00197 } else {
00198 printf( "FAILED: row-major middle-level interface to cgelqf\n" );
00199 }
00200
00201
00202
00203 for( i = 0; i < lda*n; i++ ) {
00204 a_i[i] = a_save[i];
00205 }
00206 for( i = 0; i < (MIN(m,n)); i++ ) {
00207 tau_i[i] = tau_save[i];
00208 }
00209 for( i = 0; i < lwork; i++ ) {
00210 work_i[i] = work[i];
00211 }
00212
00213
00214 LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00215 info_i = LAPACKE_cgelqf( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, tau_i );
00216
00217 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00218
00219 failed = compare_cgelqf( a, a_i, tau, tau_i, info, info_i, lda, m, n );
00220 if( failed == 0 ) {
00221 printf( "PASSED: row-major high-level interface to cgelqf\n" );
00222 } else {
00223 printf( "FAILED: row-major high-level interface to cgelqf\n" );
00224 }
00225
00226
00227 if( a != NULL ) {
00228 LAPACKE_free( a );
00229 }
00230 if( a_i != NULL ) {
00231 LAPACKE_free( a_i );
00232 }
00233 if( a_r != NULL ) {
00234 LAPACKE_free( a_r );
00235 }
00236 if( a_save != NULL ) {
00237 LAPACKE_free( a_save );
00238 }
00239 if( tau != NULL ) {
00240 LAPACKE_free( tau );
00241 }
00242 if( tau_i != NULL ) {
00243 LAPACKE_free( tau_i );
00244 }
00245 if( tau_save != NULL ) {
00246 LAPACKE_free( tau_save );
00247 }
00248 if( work != NULL ) {
00249 LAPACKE_free( work );
00250 }
00251 if( work_i != NULL ) {
00252 LAPACKE_free( work_i );
00253 }
00254
00255 return 0;
00256 }
00257
00258
00259 static void init_scalars_cgelqf( lapack_int *m, lapack_int *n, lapack_int *lda,
00260 lapack_int *lwork )
00261 {
00262 *m = 3;
00263 *n = 4;
00264 *lda = 8;
00265 *lwork = 512;
00266
00267 return;
00268 }
00269
00270
00271 static void init_a( lapack_int size, lapack_complex_float *a ) {
00272 lapack_int i;
00273 for( i = 0; i < size; i++ ) {
00274 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00275 }
00276 a[0] = lapack_make_complex_float( 2.800000012e-001, -3.600000143e-001 );
00277 a[8] = lapack_make_complex_float( 5.000000000e-001, -8.600000143e-001 );
00278 a[16] = lapack_make_complex_float( -7.699999809e-001, -4.799999893e-001 );
00279 a[24] = lapack_make_complex_float( 1.580000043e+000, 6.600000262e-001 );
00280 a[1] = lapack_make_complex_float( -5.000000000e-001, -1.100000024e+000 );
00281 a[9] = lapack_make_complex_float( -1.210000038e+000, 7.599999905e-001 );
00282 a[17] = lapack_make_complex_float( -3.199999928e-001, -2.399999946e-001 );
00283 a[25] = lapack_make_complex_float( -2.700000107e-001, -1.149999976e+000 );
00284 a[2] = lapack_make_complex_float( 3.600000143e-001, -5.099999905e-001 );
00285 a[10] = lapack_make_complex_float( -7.000000030e-002, 1.330000043e+000 );
00286 a[18] = lapack_make_complex_float( -7.500000000e-001, 4.699999988e-001 );
00287 a[26] = lapack_make_complex_float( -7.999999821e-002, 1.009999990e+000 );
00288 }
00289 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00290 lapack_int i;
00291 for( i = 0; i < size; i++ ) {
00292 tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00293 }
00294 }
00295 static void init_work( lapack_int size, lapack_complex_float *work ) {
00296 lapack_int i;
00297 for( i = 0; i < size; i++ ) {
00298 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00299 }
00300 }
00301
00302
00303
00304 static int compare_cgelqf( lapack_complex_float *a, lapack_complex_float *a_i,
00305 lapack_complex_float *tau,
00306 lapack_complex_float *tau_i, lapack_int info,
00307 lapack_int info_i, lapack_int lda, lapack_int m,
00308 lapack_int n )
00309 {
00310 lapack_int i;
00311 int failed = 0;
00312 for( i = 0; i < lda*n; i++ ) {
00313 failed += compare_complex_floats(a[i],a_i[i]);
00314 }
00315 for( i = 0; i < (MIN(m,n)); i++ ) {
00316 failed += compare_complex_floats(tau[i],tau_i[i]);
00317 }
00318 failed += (info == info_i) ? 0 : 1;
00319 if( info != 0 || info_i != 0 ) {
00320 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00321 }
00322
00323 return failed;
00324 }