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_ssytrd( char *uplo, lapack_int *n, lapack_int *lda,
00055 lapack_int *lwork );
00056 static void init_a( lapack_int size, float *a );
00057 static void init_d( lapack_int size, float *d );
00058 static void init_e( lapack_int size, float *e );
00059 static void init_tau( lapack_int size, float *tau );
00060 static void init_work( lapack_int size, float *work );
00061 static int compare_ssytrd( float *a, float *a_i, float *d, float *d_i, float *e,
00062 float *e_i, float *tau, float *tau_i,
00063 lapack_int info, lapack_int info_i, lapack_int lda,
00064 lapack_int n );
00065
00066 int main(void)
00067 {
00068
00069 char uplo, uplo_i;
00070 lapack_int n, n_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 float *a = NULL, *a_i = NULL;
00080 float *d = NULL, *d_i = NULL;
00081 float *e = NULL, *e_i = NULL;
00082 float *tau = NULL, *tau_i = NULL;
00083 float *work = NULL, *work_i = NULL;
00084 float *a_save = NULL;
00085 float *d_save = NULL;
00086 float *e_save = NULL;
00087 float *tau_save = NULL;
00088 float *a_r = NULL;
00089
00090
00091 init_scalars_ssytrd( &uplo, &n, &lda, &lwork );
00092 lda_r = n+2;
00093 uplo_i = uplo;
00094 n_i = n;
00095 lda_i = lda;
00096 lwork_i = lwork;
00097
00098
00099 a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00100 d = (float *)LAPACKE_malloc( n * sizeof(float) );
00101 e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00102 tau = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00103 work = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00104
00105
00106 a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00107 d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00108 e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00109 tau_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00110 work_i = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00111
00112
00113 a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00114 d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00115 e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00116 tau_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00117
00118
00119 a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00120
00121
00122 init_a( lda*n, a );
00123 init_d( n, d );
00124 init_e( (n-1), e );
00125 init_tau( (n-1), tau );
00126 init_work( lwork, work );
00127
00128
00129 for( i = 0; i < lda*n; i++ ) {
00130 a_save[i] = a[i];
00131 }
00132 for( i = 0; i < n; i++ ) {
00133 d_save[i] = d[i];
00134 }
00135 for( i = 0; i < (n-1); i++ ) {
00136 e_save[i] = e[i];
00137 }
00138 for( i = 0; i < (n-1); i++ ) {
00139 tau_save[i] = tau[i];
00140 }
00141
00142
00143 ssytrd_( &uplo, &n, a, &lda, d, e, tau, work, &lwork, &info );
00144
00145
00146
00147 for( i = 0; i < lda*n; i++ ) {
00148 a_i[i] = a_save[i];
00149 }
00150 for( i = 0; i < n; i++ ) {
00151 d_i[i] = d_save[i];
00152 }
00153 for( i = 0; i < (n-1); i++ ) {
00154 e_i[i] = e_save[i];
00155 }
00156 for( i = 0; i < (n-1); i++ ) {
00157 tau_i[i] = tau_save[i];
00158 }
00159 for( i = 0; i < lwork; i++ ) {
00160 work_i[i] = work[i];
00161 }
00162 info_i = LAPACKE_ssytrd_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00163 d_i, e_i, tau_i, work_i, lwork_i );
00164
00165 failed = compare_ssytrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00166 lda, n );
00167 if( failed == 0 ) {
00168 printf( "PASSED: column-major middle-level interface to ssytrd\n" );
00169 } else {
00170 printf( "FAILED: column-major middle-level interface to ssytrd\n" );
00171 }
00172
00173
00174
00175 for( i = 0; i < lda*n; i++ ) {
00176 a_i[i] = a_save[i];
00177 }
00178 for( i = 0; i < n; i++ ) {
00179 d_i[i] = d_save[i];
00180 }
00181 for( i = 0; i < (n-1); i++ ) {
00182 e_i[i] = e_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 info_i = LAPACKE_ssytrd( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i, d_i,
00191 e_i, tau_i );
00192
00193 failed = compare_ssytrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00194 lda, n );
00195 if( failed == 0 ) {
00196 printf( "PASSED: column-major high-level interface to ssytrd\n" );
00197 } else {
00198 printf( "FAILED: column-major high-level interface to ssytrd\n" );
00199 }
00200
00201
00202
00203 for( i = 0; i < lda*n; i++ ) {
00204 a_i[i] = a_save[i];
00205 }
00206 for( i = 0; i < n; i++ ) {
00207 d_i[i] = d_save[i];
00208 }
00209 for( i = 0; i < (n-1); i++ ) {
00210 e_i[i] = e_save[i];
00211 }
00212 for( i = 0; i < (n-1); i++ ) {
00213 tau_i[i] = tau_save[i];
00214 }
00215 for( i = 0; i < lwork; i++ ) {
00216 work_i[i] = work[i];
00217 }
00218
00219 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00220 info_i = LAPACKE_ssytrd_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00221 d_i, e_i, tau_i, work_i, lwork_i );
00222
00223 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00224
00225 failed = compare_ssytrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00226 lda, n );
00227 if( failed == 0 ) {
00228 printf( "PASSED: row-major middle-level interface to ssytrd\n" );
00229 } else {
00230 printf( "FAILED: row-major middle-level interface to ssytrd\n" );
00231 }
00232
00233
00234
00235 for( i = 0; i < lda*n; i++ ) {
00236 a_i[i] = a_save[i];
00237 }
00238 for( i = 0; i < n; i++ ) {
00239 d_i[i] = d_save[i];
00240 }
00241 for( i = 0; i < (n-1); i++ ) {
00242 e_i[i] = e_save[i];
00243 }
00244 for( i = 0; i < (n-1); i++ ) {
00245 tau_i[i] = tau_save[i];
00246 }
00247 for( i = 0; i < lwork; i++ ) {
00248 work_i[i] = work[i];
00249 }
00250
00251
00252 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00253 info_i = LAPACKE_ssytrd( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r, d_i,
00254 e_i, tau_i );
00255
00256 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00257
00258 failed = compare_ssytrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00259 lda, n );
00260 if( failed == 0 ) {
00261 printf( "PASSED: row-major high-level interface to ssytrd\n" );
00262 } else {
00263 printf( "FAILED: row-major high-level interface to ssytrd\n" );
00264 }
00265
00266
00267 if( a != NULL ) {
00268 LAPACKE_free( a );
00269 }
00270 if( a_i != NULL ) {
00271 LAPACKE_free( a_i );
00272 }
00273 if( a_r != NULL ) {
00274 LAPACKE_free( a_r );
00275 }
00276 if( a_save != NULL ) {
00277 LAPACKE_free( a_save );
00278 }
00279 if( d != NULL ) {
00280 LAPACKE_free( d );
00281 }
00282 if( d_i != NULL ) {
00283 LAPACKE_free( d_i );
00284 }
00285 if( d_save != NULL ) {
00286 LAPACKE_free( d_save );
00287 }
00288 if( e != NULL ) {
00289 LAPACKE_free( e );
00290 }
00291 if( e_i != NULL ) {
00292 LAPACKE_free( e_i );
00293 }
00294 if( e_save != NULL ) {
00295 LAPACKE_free( e_save );
00296 }
00297 if( tau != NULL ) {
00298 LAPACKE_free( tau );
00299 }
00300 if( tau_i != NULL ) {
00301 LAPACKE_free( tau_i );
00302 }
00303 if( tau_save != NULL ) {
00304 LAPACKE_free( tau_save );
00305 }
00306 if( work != NULL ) {
00307 LAPACKE_free( work );
00308 }
00309 if( work_i != NULL ) {
00310 LAPACKE_free( work_i );
00311 }
00312
00313 return 0;
00314 }
00315
00316
00317 static void init_scalars_ssytrd( char *uplo, lapack_int *n, lapack_int *lda,
00318 lapack_int *lwork )
00319 {
00320 *uplo = 'L';
00321 *n = 4;
00322 *lda = 8;
00323 *lwork = 512;
00324
00325 return;
00326 }
00327
00328
00329 static void init_a( lapack_int size, float *a ) {
00330 lapack_int i;
00331 for( i = 0; i < size; i++ ) {
00332 a[i] = 0;
00333 }
00334 a[0] = 2.069999933e+000;
00335 a[8] = 0.000000000e+000;
00336 a[16] = 0.000000000e+000;
00337 a[24] = 0.000000000e+000;
00338 a[1] = 3.869999886e+000;
00339 a[9] = -2.099999934e-001;
00340 a[17] = 0.000000000e+000;
00341 a[25] = 0.000000000e+000;
00342 a[2] = 4.199999809e+000;
00343 a[10] = 1.870000005e+000;
00344 a[18] = 1.149999976e+000;
00345 a[26] = 0.000000000e+000;
00346 a[3] = -1.149999976e+000;
00347 a[11] = 6.299999952e-001;
00348 a[19] = 2.059999943e+000;
00349 a[27] = -1.809999943e+000;
00350 }
00351 static void init_d( lapack_int size, float *d ) {
00352 lapack_int i;
00353 for( i = 0; i < size; i++ ) {
00354 d[i] = 0;
00355 }
00356 }
00357 static void init_e( lapack_int size, float *e ) {
00358 lapack_int i;
00359 for( i = 0; i < size; i++ ) {
00360 e[i] = 0;
00361 }
00362 }
00363 static void init_tau( lapack_int size, float *tau ) {
00364 lapack_int i;
00365 for( i = 0; i < size; i++ ) {
00366 tau[i] = 0;
00367 }
00368 }
00369 static void init_work( lapack_int size, float *work ) {
00370 lapack_int i;
00371 for( i = 0; i < size; i++ ) {
00372 work[i] = 0;
00373 }
00374 }
00375
00376
00377
00378 static int compare_ssytrd( float *a, float *a_i, float *d, float *d_i, float *e,
00379 float *e_i, float *tau, float *tau_i,
00380 lapack_int info, lapack_int info_i, lapack_int lda,
00381 lapack_int n )
00382 {
00383 lapack_int i;
00384 int failed = 0;
00385 for( i = 0; i < lda*n; i++ ) {
00386 failed += compare_floats(a[i],a_i[i]);
00387 }
00388 for( i = 0; i < n; i++ ) {
00389 failed += compare_floats(d[i],d_i[i]);
00390 }
00391 for( i = 0; i < (n-1); i++ ) {
00392 failed += compare_floats(e[i],e_i[i]);
00393 }
00394 for( i = 0; i < (n-1); i++ ) {
00395 failed += compare_floats(tau[i],tau_i[i]);
00396 }
00397 failed += (info == info_i) ? 0 : 1;
00398 if( info != 0 || info_i != 0 ) {
00399 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00400 }
00401
00402 return failed;
00403 }