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_cgehrd( 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_cgehrd( lapack_complex_float *a, lapack_complex_float *a_i,
00061 lapack_complex_float *tau,
00062 lapack_complex_float *tau_i, lapack_int info,
00063 lapack_int info_i, lapack_int lda, lapack_int n );
00064
00065 int main(void)
00066 {
00067
00068 lapack_int n, n_i;
00069 lapack_int ilo, ilo_i;
00070 lapack_int ihi, ihi_i;
00071 lapack_int lda, lda_i;
00072 lapack_int lda_r;
00073 lapack_int lwork, lwork_i;
00074 lapack_int info, info_i;
00075 lapack_int i;
00076 int failed;
00077
00078
00079 lapack_complex_float *a = NULL, *a_i = NULL;
00080 lapack_complex_float *tau = NULL, *tau_i = NULL;
00081 lapack_complex_float *work = NULL, *work_i = NULL;
00082 lapack_complex_float *a_save = NULL;
00083 lapack_complex_float *tau_save = NULL;
00084 lapack_complex_float *a_r = NULL;
00085
00086
00087 init_scalars_cgehrd( &n, &ilo, &ihi, &lda, &lwork );
00088 lda_r = n+2;
00089 n_i = n;
00090 ilo_i = ilo;
00091 ihi_i = ihi;
00092 lda_i = lda;
00093 lwork_i = lwork;
00094
00095
00096 a = (lapack_complex_float *)
00097 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00098 tau = (lapack_complex_float *)
00099 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00100 work = (lapack_complex_float *)
00101 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00102
00103
00104 a_i = (lapack_complex_float *)
00105 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00106 tau_i = (lapack_complex_float *)
00107 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00108 work_i = (lapack_complex_float *)
00109 LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00110
00111
00112 a_save = (lapack_complex_float *)
00113 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00114 tau_save = (lapack_complex_float *)
00115 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00116
00117
00118 a_r = (lapack_complex_float *)
00119 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00120
00121
00122 init_a( lda*n, a );
00123 init_tau( (n-1), tau );
00124 init_work( lwork, work );
00125
00126
00127 for( i = 0; i < lda*n; i++ ) {
00128 a_save[i] = a[i];
00129 }
00130 for( i = 0; i < (n-1); i++ ) {
00131 tau_save[i] = tau[i];
00132 }
00133
00134
00135 cgehrd_( &n, &ilo, &ihi, a, &lda, tau, work, &lwork, &info );
00136
00137
00138
00139 for( i = 0; i < lda*n; i++ ) {
00140 a_i[i] = a_save[i];
00141 }
00142 for( i = 0; i < (n-1); i++ ) {
00143 tau_i[i] = tau_save[i];
00144 }
00145 for( i = 0; i < lwork; i++ ) {
00146 work_i[i] = work[i];
00147 }
00148 info_i = LAPACKE_cgehrd_work( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i,
00149 lda_i, tau_i, work_i, lwork_i );
00150
00151 failed = compare_cgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major middle-level interface to cgehrd\n" );
00154 } else {
00155 printf( "FAILED: column-major middle-level interface to cgehrd\n" );
00156 }
00157
00158
00159
00160 for( i = 0; i < lda*n; i++ ) {
00161 a_i[i] = a_save[i];
00162 }
00163 for( i = 0; i < (n-1); i++ ) {
00164 tau_i[i] = tau_save[i];
00165 }
00166 for( i = 0; i < lwork; i++ ) {
00167 work_i[i] = work[i];
00168 }
00169 info_i = LAPACKE_cgehrd( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i, lda_i,
00170 tau_i );
00171
00172 failed = compare_cgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00173 if( failed == 0 ) {
00174 printf( "PASSED: column-major high-level interface to cgehrd\n" );
00175 } else {
00176 printf( "FAILED: column-major high-level interface to cgehrd\n" );
00177 }
00178
00179
00180
00181 for( i = 0; i < lda*n; i++ ) {
00182 a_i[i] = a_save[i];
00183 }
00184 for( i = 0; i < (n-1); i++ ) {
00185 tau_i[i] = tau_save[i];
00186 }
00187 for( i = 0; i < lwork; i++ ) {
00188 work_i[i] = work[i];
00189 }
00190
00191 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00192 info_i = LAPACKE_cgehrd_work( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r,
00193 lda_r, tau_i, work_i, lwork_i );
00194
00195 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00196
00197 failed = compare_cgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00198 if( failed == 0 ) {
00199 printf( "PASSED: row-major middle-level interface to cgehrd\n" );
00200 } else {
00201 printf( "FAILED: row-major middle-level interface to cgehrd\n" );
00202 }
00203
00204
00205
00206 for( i = 0; i < lda*n; i++ ) {
00207 a_i[i] = a_save[i];
00208 }
00209 for( i = 0; i < (n-1); i++ ) {
00210 tau_i[i] = tau_save[i];
00211 }
00212 for( i = 0; i < lwork; i++ ) {
00213 work_i[i] = work[i];
00214 }
00215
00216
00217 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00218 info_i = LAPACKE_cgehrd( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r, lda_r,
00219 tau_i );
00220
00221 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00222
00223 failed = compare_cgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00224 if( failed == 0 ) {
00225 printf( "PASSED: row-major high-level interface to cgehrd\n" );
00226 } else {
00227 printf( "FAILED: row-major high-level interface to cgehrd\n" );
00228 }
00229
00230
00231 if( a != NULL ) {
00232 LAPACKE_free( a );
00233 }
00234 if( a_i != NULL ) {
00235 LAPACKE_free( a_i );
00236 }
00237 if( a_r != NULL ) {
00238 LAPACKE_free( a_r );
00239 }
00240 if( a_save != NULL ) {
00241 LAPACKE_free( a_save );
00242 }
00243 if( tau != NULL ) {
00244 LAPACKE_free( tau );
00245 }
00246 if( tau_i != NULL ) {
00247 LAPACKE_free( tau_i );
00248 }
00249 if( tau_save != NULL ) {
00250 LAPACKE_free( tau_save );
00251 }
00252 if( work != NULL ) {
00253 LAPACKE_free( work );
00254 }
00255 if( work_i != NULL ) {
00256 LAPACKE_free( work_i );
00257 }
00258
00259 return 0;
00260 }
00261
00262
00263 static void init_scalars_cgehrd( lapack_int *n, lapack_int *ilo,
00264 lapack_int *ihi, lapack_int *lda,
00265 lapack_int *lwork )
00266 {
00267 *n = 4;
00268 *ilo = 1;
00269 *ihi = 4;
00270 *lda = 8;
00271 *lwork = 512;
00272
00273 return;
00274 }
00275
00276
00277 static void init_a( lapack_int size, lapack_complex_float *a ) {
00278 lapack_int i;
00279 for( i = 0; i < size; i++ ) {
00280 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00281 }
00282 a[0] = lapack_make_complex_float( -3.970000029e+000, -5.039999962e+000 );
00283 a[8] = lapack_make_complex_float( -4.110000134e+000, 3.700000048e+000 );
00284 a[16] = lapack_make_complex_float( -3.400000036e-001, 1.009999990e+000 );
00285 a[24] = lapack_make_complex_float( 1.289999962e+000, -8.600000143e-001 );
00286 a[1] = lapack_make_complex_float( 3.400000036e-001, -1.500000000e+000 );
00287 a[9] = lapack_make_complex_float( 1.519999981e+000, -4.300000072e-001 );
00288 a[17] = lapack_make_complex_float( 1.879999995e+000, -5.380000114e+000 );
00289 a[25] = lapack_make_complex_float( 3.359999895e+000, 6.499999762e-001 );
00290 a[2] = lapack_make_complex_float( 3.309999943e+000, -3.849999905e+000 );
00291 a[10] = lapack_make_complex_float( 2.500000000e+000, 3.450000048e+000 );
00292 a[18] = lapack_make_complex_float( 8.799999952e-001, -1.080000043e+000 );
00293 a[26] = lapack_make_complex_float( 6.399999857e-001, -1.480000019e+000 );
00294 a[3] = lapack_make_complex_float( -1.100000024e+000, 8.199999928e-001 );
00295 a[11] = lapack_make_complex_float( 1.809999943e+000, -1.590000033e+000 );
00296 a[19] = lapack_make_complex_float( 3.250000000e+000, 1.330000043e+000 );
00297 a[27] = lapack_make_complex_float( 1.570000052e+000, -3.440000057e+000 );
00298 }
00299 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00300 lapack_int i;
00301 for( i = 0; i < size; i++ ) {
00302 tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00303 }
00304 }
00305 static void init_work( lapack_int size, lapack_complex_float *work ) {
00306 lapack_int i;
00307 for( i = 0; i < size; i++ ) {
00308 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00309 }
00310 }
00311
00312
00313
00314 static int compare_cgehrd( lapack_complex_float *a, lapack_complex_float *a_i,
00315 lapack_complex_float *tau,
00316 lapack_complex_float *tau_i, lapack_int info,
00317 lapack_int info_i, lapack_int lda, lapack_int n )
00318 {
00319 lapack_int i;
00320 int failed = 0;
00321 for( i = 0; i < lda*n; i++ ) {
00322 failed += compare_complex_floats(a[i],a_i[i]);
00323 }
00324 for( i = 0; i < (n-1); i++ ) {
00325 failed += compare_complex_floats(tau[i],tau_i[i]);
00326 }
00327 failed += (info == info_i) ? 0 : 1;
00328 if( info != 0 || info_i != 0 ) {
00329 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00330 }
00331
00332 return failed;
00333 }