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_cunghr( lapack_int *n, lapack_int *ilo,
00055 lapack_int *ihi, lapack_int *lda,
00056 lapack_int *lwork );
00057 static void init_a( lapack_int size, lapack_complex_float *a );
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 int compare_cunghr( lapack_complex_float *a, lapack_complex_float *a_i,
00061 lapack_int info, lapack_int info_i, lapack_int lda,
00062 lapack_int n );
00063
00064 int main(void)
00065 {
00066
00067 lapack_int n, n_i;
00068 lapack_int ilo, ilo_i;
00069 lapack_int ihi, ihi_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 *a_r = NULL;
00083
00084
00085 init_scalars_cunghr( &n, &ilo, &ihi, &lda, &lwork );
00086 lda_r = n+2;
00087 n_i = n;
00088 ilo_i = ilo;
00089 ihi_i = ihi;
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( (n-1) * 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( (n-1) * 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
00113
00114 a_r = (lapack_complex_float *)
00115 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00116
00117
00118 init_a( lda*n, a );
00119 init_tau( (n-1), tau );
00120 init_work( lwork, work );
00121
00122
00123 for( i = 0; i < lda*n; i++ ) {
00124 a_save[i] = a[i];
00125 }
00126
00127
00128 cunghr_( &n, &ilo, &ihi, a, &lda, tau, work, &lwork, &info );
00129
00130
00131
00132 for( i = 0; i < lda*n; i++ ) {
00133 a_i[i] = a_save[i];
00134 }
00135 for( i = 0; i < (n-1); i++ ) {
00136 tau_i[i] = tau[i];
00137 }
00138 for( i = 0; i < lwork; i++ ) {
00139 work_i[i] = work[i];
00140 }
00141 info_i = LAPACKE_cunghr_work( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i,
00142 lda_i, tau_i, work_i, lwork_i );
00143
00144 failed = compare_cunghr( a, a_i, info, info_i, lda, n );
00145 if( failed == 0 ) {
00146 printf( "PASSED: column-major middle-level interface to cunghr\n" );
00147 } else {
00148 printf( "FAILED: column-major middle-level interface to cunghr\n" );
00149 }
00150
00151
00152
00153 for( i = 0; i < lda*n; i++ ) {
00154 a_i[i] = a_save[i];
00155 }
00156 for( i = 0; i < (n-1); i++ ) {
00157 tau_i[i] = tau[i];
00158 }
00159 for( i = 0; i < lwork; i++ ) {
00160 work_i[i] = work[i];
00161 }
00162 info_i = LAPACKE_cunghr( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i, lda_i,
00163 tau_i );
00164
00165 failed = compare_cunghr( a, a_i, info, info_i, lda, n );
00166 if( failed == 0 ) {
00167 printf( "PASSED: column-major high-level interface to cunghr\n" );
00168 } else {
00169 printf( "FAILED: column-major high-level interface to cunghr\n" );
00170 }
00171
00172
00173
00174 for( i = 0; i < lda*n; i++ ) {
00175 a_i[i] = a_save[i];
00176 }
00177 for( i = 0; i < (n-1); i++ ) {
00178 tau_i[i] = tau[i];
00179 }
00180 for( i = 0; i < lwork; i++ ) {
00181 work_i[i] = work[i];
00182 }
00183
00184 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00185 info_i = LAPACKE_cunghr_work( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r,
00186 lda_r, tau_i, work_i, lwork_i );
00187
00188 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00189
00190 failed = compare_cunghr( a, a_i, info, info_i, lda, n );
00191 if( failed == 0 ) {
00192 printf( "PASSED: row-major middle-level interface to cunghr\n" );
00193 } else {
00194 printf( "FAILED: row-major middle-level interface to cunghr\n" );
00195 }
00196
00197
00198
00199 for( i = 0; i < lda*n; i++ ) {
00200 a_i[i] = a_save[i];
00201 }
00202 for( i = 0; i < (n-1); i++ ) {
00203 tau_i[i] = tau[i];
00204 }
00205 for( i = 0; i < lwork; i++ ) {
00206 work_i[i] = work[i];
00207 }
00208
00209
00210 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00211 info_i = LAPACKE_cunghr( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r, lda_r,
00212 tau_i );
00213
00214 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00215
00216 failed = compare_cunghr( a, a_i, info, info_i, lda, n );
00217 if( failed == 0 ) {
00218 printf( "PASSED: row-major high-level interface to cunghr\n" );
00219 } else {
00220 printf( "FAILED: row-major high-level interface to cunghr\n" );
00221 }
00222
00223
00224 if( a != NULL ) {
00225 LAPACKE_free( a );
00226 }
00227 if( a_i != NULL ) {
00228 LAPACKE_free( a_i );
00229 }
00230 if( a_r != NULL ) {
00231 LAPACKE_free( a_r );
00232 }
00233 if( a_save != NULL ) {
00234 LAPACKE_free( a_save );
00235 }
00236 if( tau != NULL ) {
00237 LAPACKE_free( tau );
00238 }
00239 if( tau_i != NULL ) {
00240 LAPACKE_free( tau_i );
00241 }
00242 if( work != NULL ) {
00243 LAPACKE_free( work );
00244 }
00245 if( work_i != NULL ) {
00246 LAPACKE_free( work_i );
00247 }
00248
00249 return 0;
00250 }
00251
00252
00253 static void init_scalars_cunghr( lapack_int *n, lapack_int *ilo,
00254 lapack_int *ihi, lapack_int *lda,
00255 lapack_int *lwork )
00256 {
00257 *n = 4;
00258 *ilo = 1;
00259 *ihi = 4;
00260 *lda = 8;
00261 *lwork = 512;
00262
00263 return;
00264 }
00265
00266
00267 static void init_a( lapack_int size, lapack_complex_float *a ) {
00268 lapack_int i;
00269 for( i = 0; i < size; i++ ) {
00270 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00271 }
00272 a[0] = lapack_make_complex_float( -1.250000000e+000, 7.500000000e-001 );
00273 a[8] = lapack_make_complex_float( 1.389999986e+000, 3.970000029e+000 );
00274 a[16] = lapack_make_complex_float( 8.283648491e-001, 7.395614624e+000 );
00275 a[24] = lapack_make_complex_float( -2.089999914e+000, 7.559999943e+000 );
00276 a[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00277 a[9] = lapack_make_complex_float( -2.500000000e+000, -5.000000000e-001 );
00278 a[17] = lapack_make_complex_float( 9.013764858e-001, 4.506915808e-003 );
00279 a[25] = lapack_make_complex_float( -8.060000420e+000, -1.240000010e+000 );
00280 a[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00281 a[10] = lapack_make_complex_float( 1.109414220e+000, 0.000000000e+000 );
00282 a[18] = lapack_make_complex_float( -2.500000000e+000, -5.000000000e-001 );
00283 a[26] = lapack_make_complex_float( -1.059604073e+001, -4.664803505e+000 );
00284 a[3] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00285 a[11] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00286 a[19] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00287 a[27] = lapack_make_complex_float( 1.500000000e+000, -2.750000000e+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 tau[0] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00295 tau[1] = lapack_make_complex_float( 1.829266429e+000, 5.588535070e-001 );
00296 tau[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00297 }
00298 static void init_work( lapack_int size, lapack_complex_float *work ) {
00299 lapack_int i;
00300 for( i = 0; i < size; i++ ) {
00301 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00302 }
00303 }
00304
00305
00306
00307 static int compare_cunghr( lapack_complex_float *a, lapack_complex_float *a_i,
00308 lapack_int info, lapack_int info_i, lapack_int lda,
00309 lapack_int n )
00310 {
00311 lapack_int i;
00312 int failed = 0;
00313 for( i = 0; i < lda*n; i++ ) {
00314 failed += compare_complex_floats(a[i],a_i[i]);
00315 }
00316 failed += (info == info_i) ? 0 : 1;
00317 if( info != 0 || info_i != 0 ) {
00318 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00319 }
00320
00321 return failed;
00322 }