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_zunghr( 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_double *a );
00058 static void init_tau( lapack_int size, lapack_complex_double *tau );
00059 static void init_work( lapack_int size, lapack_complex_double *work );
00060 static int compare_zunghr( lapack_complex_double *a, lapack_complex_double *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_double *a = NULL, *a_i = NULL;
00079 lapack_complex_double *tau = NULL, *tau_i = NULL;
00080 lapack_complex_double *work = NULL, *work_i = NULL;
00081 lapack_complex_double *a_save = NULL;
00082 lapack_complex_double *a_r = NULL;
00083
00084
00085 init_scalars_zunghr( &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_double *)
00095 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00096 tau = (lapack_complex_double *)
00097 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00098 work = (lapack_complex_double *)
00099 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00100
00101
00102 a_i = (lapack_complex_double *)
00103 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00104 tau_i = (lapack_complex_double *)
00105 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00106 work_i = (lapack_complex_double *)
00107 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00108
00109
00110 a_save = (lapack_complex_double *)
00111 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00112
00113
00114 a_r = (lapack_complex_double *)
00115 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
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 zunghr_( &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_zunghr_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_zunghr( a, a_i, info, info_i, lda, n );
00145 if( failed == 0 ) {
00146 printf( "PASSED: column-major middle-level interface to zunghr\n" );
00147 } else {
00148 printf( "FAILED: column-major middle-level interface to zunghr\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_zunghr( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i, lda_i,
00163 tau_i );
00164
00165 failed = compare_zunghr( a, a_i, info, info_i, lda, n );
00166 if( failed == 0 ) {
00167 printf( "PASSED: column-major high-level interface to zunghr\n" );
00168 } else {
00169 printf( "FAILED: column-major high-level interface to zunghr\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_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00185 info_i = LAPACKE_zunghr_work( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r,
00186 lda_r, tau_i, work_i, lwork_i );
00187
00188 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00189
00190 failed = compare_zunghr( a, a_i, info, info_i, lda, n );
00191 if( failed == 0 ) {
00192 printf( "PASSED: row-major middle-level interface to zunghr\n" );
00193 } else {
00194 printf( "FAILED: row-major middle-level interface to zunghr\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_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00211 info_i = LAPACKE_zunghr( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r, lda_r,
00212 tau_i );
00213
00214 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00215
00216 failed = compare_zunghr( a, a_i, info, info_i, lda, n );
00217 if( failed == 0 ) {
00218 printf( "PASSED: row-major high-level interface to zunghr\n" );
00219 } else {
00220 printf( "FAILED: row-major high-level interface to zunghr\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_zunghr( 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 = 448;
00262
00263 return;
00264 }
00265
00266
00267 static void init_a( lapack_int size, lapack_complex_double *a ) {
00268 lapack_int i;
00269 for( i = 0; i < size; i++ ) {
00270 a[i] = lapack_make_complex_double( 0.0, 0.0 );
00271 }
00272 a[0] = lapack_make_complex_double( -3.97000000000000020e+000,
00273 -5.04000000000000000e+000 );
00274 a[8] = lapack_make_complex_double( -1.13180518733977030e+000,
00275 -2.56930489882743900e+000 );
00276 a[16] = lapack_make_complex_double( -4.60274243753355350e+000,
00277 -1.42631904083292180e-001 );
00278 a[24] = lapack_make_complex_double( -1.42491228936652710e+000,
00279 1.73298370334218620e+000 );
00280 a[1] = lapack_make_complex_double( -5.47965327370263560e+000,
00281 0.00000000000000000e+000 );
00282 a[9] = lapack_make_complex_double( 1.85847282076558700e+000,
00283 -1.55018070644028950e+000 );
00284 a[17] = lapack_make_complex_double( 4.41446552691701300e+000,
00285 -7.63823711555098320e-001 );
00286 a[25] = lapack_make_complex_double( -4.80526133699015420e-001,
00287 -1.19759999733274710e+000 );
00288 a[2] = lapack_make_complex_double( 6.93222211814628180e-001,
00289 -4.82875276260254950e-001 );
00290 a[10] = lapack_make_complex_double( 6.26727681806422240e+000,
00291 0.00000000000000000e+000 );
00292 a[18] = lapack_make_complex_double( -4.50380940334500930e-001,
00293 -2.89818325981801020e-002 );
00294 a[26] = lapack_make_complex_double( -1.34668445007873290e+000,
00295 1.65792489538873020e+000 );
00296 a[3] = lapack_make_complex_double( -2.11294690792069330e-001,
00297 8.64412259893682090e-002 );
00298 a[11] = lapack_make_complex_double( 1.24214618876649560e-001,
00299 -2.28927604979682810e-001 );
00300 a[19] = lapack_make_complex_double( -3.49998583739325890e+000,
00301 0.00000000000000000e+000 );
00302 a[27] = lapack_make_complex_double( 2.56190811956891370e+000,
00303 -3.37083746096152880e+000 );
00304 }
00305 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00306 lapack_int i;
00307 for( i = 0; i < size; i++ ) {
00308 tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00309 }
00310 tau[0] = lapack_make_complex_double( 1.06204772145560590e+000,
00311 -2.73739947598261200e-001 );
00312 tau[1] = lapack_make_complex_double( 1.80592137164058510e+000,
00313 3.47906702984828510e-001 );
00314 tau[2] = lapack_make_complex_double( 1.18182347104100290e+000,
00315 9.83331188043276350e-001 );
00316 }
00317 static void init_work( lapack_int size, lapack_complex_double *work ) {
00318 lapack_int i;
00319 for( i = 0; i < size; i++ ) {
00320 work[i] = lapack_make_complex_double( 0.0, 0.0 );
00321 }
00322 }
00323
00324
00325
00326 static int compare_zunghr( lapack_complex_double *a, lapack_complex_double *a_i,
00327 lapack_int info, lapack_int info_i, lapack_int lda,
00328 lapack_int n )
00329 {
00330 lapack_int i;
00331 int failed = 0;
00332 for( i = 0; i < lda*n; i++ ) {
00333 failed += compare_complex_doubles(a[i],a_i[i]);
00334 }
00335 failed += (info == info_i) ? 0 : 1;
00336 if( info != 0 || info_i != 0 ) {
00337 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00338 }
00339
00340 return failed;
00341 }