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