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_chegst( lapack_int *itype, char *uplo, lapack_int *n,
00055 lapack_int *lda, lapack_int *ldb );
00056 static void init_a( lapack_int size, lapack_complex_float *a );
00057 static void init_b( lapack_int size, lapack_complex_float *b );
00058 static int compare_chegst( lapack_complex_float *a, lapack_complex_float *a_i,
00059 lapack_int info, lapack_int info_i, lapack_int lda,
00060 lapack_int n );
00061
00062 int main(void)
00063 {
00064
00065 lapack_int itype, itype_i;
00066 char uplo, uplo_i;
00067 lapack_int n, n_i;
00068 lapack_int lda, lda_i;
00069 lapack_int lda_r;
00070 lapack_int ldb, ldb_i;
00071 lapack_int ldb_r;
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 *b = NULL, *b_i = NULL;
00079 lapack_complex_float *a_save = NULL;
00080 lapack_complex_float *a_r = NULL;
00081 lapack_complex_float *b_r = NULL;
00082
00083
00084 init_scalars_chegst( &itype, &uplo, &n, &lda, &ldb );
00085 lda_r = n+2;
00086 ldb_r = n+2;
00087 itype_i = itype;
00088 uplo_i = uplo;
00089 n_i = n;
00090 lda_i = lda;
00091 ldb_i = ldb;
00092
00093
00094 a = (lapack_complex_float *)
00095 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00096 b = (lapack_complex_float *)
00097 LAPACKE_malloc( ldb*n * sizeof(lapack_complex_float) );
00098
00099
00100 a_i = (lapack_complex_float *)
00101 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00102 b_i = (lapack_complex_float *)
00103 LAPACKE_malloc( ldb*n * sizeof(lapack_complex_float) );
00104
00105
00106 a_save = (lapack_complex_float *)
00107 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00108
00109
00110 a_r = (lapack_complex_float *)
00111 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00112 b_r = (lapack_complex_float *)
00113 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00114
00115
00116 init_a( lda*n, a );
00117 init_b( ldb*n, b );
00118
00119
00120 for( i = 0; i < lda*n; i++ ) {
00121 a_save[i] = a[i];
00122 }
00123
00124
00125 chegst_( &itype, &uplo, &n, a, &lda, b, &ldb, &info );
00126
00127
00128
00129 for( i = 0; i < lda*n; i++ ) {
00130 a_i[i] = a_save[i];
00131 }
00132 for( i = 0; i < ldb*n; i++ ) {
00133 b_i[i] = b[i];
00134 }
00135 info_i = LAPACKE_chegst_work( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, a_i,
00136 lda_i, b_i, ldb_i );
00137
00138 failed = compare_chegst( a, a_i, info, info_i, lda, n );
00139 if( failed == 0 ) {
00140 printf( "PASSED: column-major middle-level interface to chegst\n" );
00141 } else {
00142 printf( "FAILED: column-major middle-level interface to chegst\n" );
00143 }
00144
00145
00146
00147 for( i = 0; i < lda*n; i++ ) {
00148 a_i[i] = a_save[i];
00149 }
00150 for( i = 0; i < ldb*n; i++ ) {
00151 b_i[i] = b[i];
00152 }
00153 info_i = LAPACKE_chegst( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, a_i, lda_i,
00154 b_i, ldb_i );
00155
00156 failed = compare_chegst( a, a_i, info, info_i, lda, n );
00157 if( failed == 0 ) {
00158 printf( "PASSED: column-major high-level interface to chegst\n" );
00159 } else {
00160 printf( "FAILED: column-major high-level interface to chegst\n" );
00161 }
00162
00163
00164
00165 for( i = 0; i < lda*n; i++ ) {
00166 a_i[i] = a_save[i];
00167 }
00168 for( i = 0; i < ldb*n; i++ ) {
00169 b_i[i] = b[i];
00170 }
00171
00172 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00173 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00174 info_i = LAPACKE_chegst_work( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, a_r,
00175 lda_r, b_r, ldb_r );
00176
00177 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00178
00179 failed = compare_chegst( a, a_i, info, info_i, lda, n );
00180 if( failed == 0 ) {
00181 printf( "PASSED: row-major middle-level interface to chegst\n" );
00182 } else {
00183 printf( "FAILED: row-major middle-level interface to chegst\n" );
00184 }
00185
00186
00187
00188 for( i = 0; i < lda*n; i++ ) {
00189 a_i[i] = a_save[i];
00190 }
00191 for( i = 0; i < ldb*n; i++ ) {
00192 b_i[i] = b[i];
00193 }
00194
00195
00196 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00197 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00198 info_i = LAPACKE_chegst( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, a_r, lda_r,
00199 b_r, ldb_r );
00200
00201 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00202
00203 failed = compare_chegst( a, a_i, info, info_i, lda, n );
00204 if( failed == 0 ) {
00205 printf( "PASSED: row-major high-level interface to chegst\n" );
00206 } else {
00207 printf( "FAILED: row-major high-level interface to chegst\n" );
00208 }
00209
00210
00211 if( a != NULL ) {
00212 LAPACKE_free( a );
00213 }
00214 if( a_i != NULL ) {
00215 LAPACKE_free( a_i );
00216 }
00217 if( a_r != NULL ) {
00218 LAPACKE_free( a_r );
00219 }
00220 if( a_save != NULL ) {
00221 LAPACKE_free( a_save );
00222 }
00223 if( b != NULL ) {
00224 LAPACKE_free( b );
00225 }
00226 if( b_i != NULL ) {
00227 LAPACKE_free( b_i );
00228 }
00229 if( b_r != NULL ) {
00230 LAPACKE_free( b_r );
00231 }
00232
00233 return 0;
00234 }
00235
00236
00237 static void init_scalars_chegst( lapack_int *itype, char *uplo, lapack_int *n,
00238 lapack_int *lda, lapack_int *ldb )
00239 {
00240 *itype = 1;
00241 *uplo = 'L';
00242 *n = 4;
00243 *lda = 8;
00244 *ldb = 8;
00245
00246 return;
00247 }
00248
00249
00250 static void init_a( lapack_int size, lapack_complex_float *a ) {
00251 lapack_int i;
00252 for( i = 0; i < size; i++ ) {
00253 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00254 }
00255 a[0] = lapack_make_complex_float( -7.360000134e+000, 0.000000000e+000 );
00256 a[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00257 a[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00258 a[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00259 a[1] = lapack_make_complex_float( 7.699999809e-001, 4.300000072e-001 );
00260 a[9] = lapack_make_complex_float( 3.490000010e+000, 0.000000000e+000 );
00261 a[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00262 a[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00263 a[2] = lapack_make_complex_float( -6.399999857e-001, 9.200000167e-001 );
00264 a[10] = lapack_make_complex_float( 2.190000057e+000, -4.449999809e+000 );
00265 a[18] = lapack_make_complex_float( 1.199999973e-001, 0.000000000e+000 );
00266 a[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00267 a[3] = lapack_make_complex_float( 3.009999990e+000, 6.969999790e+000 );
00268 a[11] = lapack_make_complex_float( 1.899999976e+000, -3.730000019e+000 );
00269 a[19] = lapack_make_complex_float( 2.880000114e+000, 3.170000076e+000 );
00270 a[27] = lapack_make_complex_float( -2.539999962e+000, 0.000000000e+000 );
00271 }
00272 static void init_b( lapack_int size, lapack_complex_float *b ) {
00273 lapack_int i;
00274 for( i = 0; i < size; i++ ) {
00275 b[i] = lapack_make_complex_float( 0.0f, 0.0f );
00276 }
00277 b[0] = lapack_make_complex_float( 1.797220111e+000, 0.000000000e+000 );
00278 b[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00279 b[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00280 b[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00281 b[1] = lapack_make_complex_float( 8.401864767e-001, 1.068316579e+000 );
00282 b[9] = lapack_make_complex_float( 1.316353440e+000, 0.000000000e+000 );
00283 b[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00284 b[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00285 b[2] = lapack_make_complex_float( 1.057188272e+000, -4.673885107e-001 );
00286 b[10] = lapack_make_complex_float( -4.701749086e-001, 3.130658567e-001 );
00287 b[18] = lapack_make_complex_float( 1.560392976e+000, 0.000000000e+000 );
00288 b[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00289 b[3] = lapack_make_complex_float( 2.336942554e-001, -1.391037226e+000 );
00290 b[11] = lapack_make_complex_float( 8.335255086e-002, 3.676066548e-002 );
00291 b[19] = lapack_make_complex_float( 9.359616637e-001, 9.899691939e-001 );
00292 b[27] = lapack_make_complex_float( 6.603333950e-001, 0.000000000e+000 );
00293 }
00294
00295
00296
00297 static int compare_chegst( lapack_complex_float *a, lapack_complex_float *a_i,
00298 lapack_int info, lapack_int info_i, lapack_int lda,
00299 lapack_int n )
00300 {
00301 lapack_int i;
00302 int failed = 0;
00303 for( i = 0; i < lda*n; i++ ) {
00304 failed += compare_complex_floats(a[i],a_i[i]);
00305 }
00306 failed += (info == info_i) ? 0 : 1;
00307 if( info != 0 || info_i != 0 ) {
00308 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00309 }
00310
00311 return failed;
00312 }