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_ssptrd( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, float *ap );
00056 static void init_d( lapack_int size, float *d );
00057 static void init_e( lapack_int size, float *e );
00058 static void init_tau( lapack_int size, float *tau );
00059 static int compare_ssptrd( float *ap, float *ap_i, float *d, float *d_i,
00060 float *e, float *e_i, float *tau, float *tau_i,
00061 lapack_int info, lapack_int info_i, lapack_int n );
00062
00063 int main(void)
00064 {
00065
00066 char uplo, uplo_i;
00067 lapack_int n, n_i;
00068 lapack_int info, info_i;
00069 lapack_int i;
00070 int failed;
00071
00072
00073 float *ap = NULL, *ap_i = NULL;
00074 float *d = NULL, *d_i = NULL;
00075 float *e = NULL, *e_i = NULL;
00076 float *tau = NULL, *tau_i = NULL;
00077 float *ap_save = NULL;
00078 float *d_save = NULL;
00079 float *e_save = NULL;
00080 float *tau_save = NULL;
00081 float *ap_r = NULL;
00082
00083
00084 init_scalars_ssptrd( &uplo, &n );
00085 uplo_i = uplo;
00086 n_i = n;
00087
00088
00089 ap = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00090 d = (float *)LAPACKE_malloc( n * sizeof(float) );
00091 e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00092 tau = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00093
00094
00095 ap_i = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00096 d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00097 e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00098 tau_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00099
00100
00101 ap_save = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00102 d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00103 e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00104 tau_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00105
00106
00107 ap_r = (float *)LAPACKE_malloc( n*(n+1)/2 * sizeof(float) );
00108
00109
00110 init_ap( (n*(n+1)/2), ap );
00111 init_d( n, d );
00112 init_e( (n-1), e );
00113 init_tau( (n-1), tau );
00114
00115
00116 for( i = 0; i < (n*(n+1)/2); i++ ) {
00117 ap_save[i] = ap[i];
00118 }
00119 for( i = 0; i < n; i++ ) {
00120 d_save[i] = d[i];
00121 }
00122 for( i = 0; i < (n-1); i++ ) {
00123 e_save[i] = e[i];
00124 }
00125 for( i = 0; i < (n-1); i++ ) {
00126 tau_save[i] = tau[i];
00127 }
00128
00129
00130 ssptrd_( &uplo, &n, ap, d, e, tau, &info );
00131
00132
00133
00134 for( i = 0; i < (n*(n+1)/2); i++ ) {
00135 ap_i[i] = ap_save[i];
00136 }
00137 for( i = 0; i < n; i++ ) {
00138 d_i[i] = d_save[i];
00139 }
00140 for( i = 0; i < (n-1); i++ ) {
00141 e_i[i] = e_save[i];
00142 }
00143 for( i = 0; i < (n-1); i++ ) {
00144 tau_i[i] = tau_save[i];
00145 }
00146 info_i = LAPACKE_ssptrd_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00147 tau_i );
00148
00149 failed = compare_ssptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00150 n );
00151 if( failed == 0 ) {
00152 printf( "PASSED: column-major middle-level interface to ssptrd\n" );
00153 } else {
00154 printf( "FAILED: column-major middle-level interface to ssptrd\n" );
00155 }
00156
00157
00158
00159 for( i = 0; i < (n*(n+1)/2); i++ ) {
00160 ap_i[i] = ap_save[i];
00161 }
00162 for( i = 0; i < n; i++ ) {
00163 d_i[i] = d_save[i];
00164 }
00165 for( i = 0; i < (n-1); i++ ) {
00166 e_i[i] = e_save[i];
00167 }
00168 for( i = 0; i < (n-1); i++ ) {
00169 tau_i[i] = tau_save[i];
00170 }
00171 info_i = LAPACKE_ssptrd( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00172 tau_i );
00173
00174 failed = compare_ssptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00175 n );
00176 if( failed == 0 ) {
00177 printf( "PASSED: column-major high-level interface to ssptrd\n" );
00178 } else {
00179 printf( "FAILED: column-major high-level interface to ssptrd\n" );
00180 }
00181
00182
00183
00184 for( i = 0; i < (n*(n+1)/2); i++ ) {
00185 ap_i[i] = ap_save[i];
00186 }
00187 for( i = 0; i < n; i++ ) {
00188 d_i[i] = d_save[i];
00189 }
00190 for( i = 0; i < (n-1); i++ ) {
00191 e_i[i] = e_save[i];
00192 }
00193 for( i = 0; i < (n-1); i++ ) {
00194 tau_i[i] = tau_save[i];
00195 }
00196
00197 LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198 info_i = LAPACKE_ssptrd_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00199 tau_i );
00200
00201 LAPACKE_spp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00202
00203 failed = compare_ssptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00204 n );
00205 if( failed == 0 ) {
00206 printf( "PASSED: row-major middle-level interface to ssptrd\n" );
00207 } else {
00208 printf( "FAILED: row-major middle-level interface to ssptrd\n" );
00209 }
00210
00211
00212
00213 for( i = 0; i < (n*(n+1)/2); i++ ) {
00214 ap_i[i] = ap_save[i];
00215 }
00216 for( i = 0; i < n; i++ ) {
00217 d_i[i] = d_save[i];
00218 }
00219 for( i = 0; i < (n-1); i++ ) {
00220 e_i[i] = e_save[i];
00221 }
00222 for( i = 0; i < (n-1); i++ ) {
00223 tau_i[i] = tau_save[i];
00224 }
00225
00226
00227 LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00228 info_i = LAPACKE_ssptrd( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00229 tau_i );
00230
00231 LAPACKE_spp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00232
00233 failed = compare_ssptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00234 n );
00235 if( failed == 0 ) {
00236 printf( "PASSED: row-major high-level interface to ssptrd\n" );
00237 } else {
00238 printf( "FAILED: row-major high-level interface to ssptrd\n" );
00239 }
00240
00241
00242 if( ap != NULL ) {
00243 LAPACKE_free( ap );
00244 }
00245 if( ap_i != NULL ) {
00246 LAPACKE_free( ap_i );
00247 }
00248 if( ap_r != NULL ) {
00249 LAPACKE_free( ap_r );
00250 }
00251 if( ap_save != NULL ) {
00252 LAPACKE_free( ap_save );
00253 }
00254 if( d != NULL ) {
00255 LAPACKE_free( d );
00256 }
00257 if( d_i != NULL ) {
00258 LAPACKE_free( d_i );
00259 }
00260 if( d_save != NULL ) {
00261 LAPACKE_free( d_save );
00262 }
00263 if( e != NULL ) {
00264 LAPACKE_free( e );
00265 }
00266 if( e_i != NULL ) {
00267 LAPACKE_free( e_i );
00268 }
00269 if( e_save != NULL ) {
00270 LAPACKE_free( e_save );
00271 }
00272 if( tau != NULL ) {
00273 LAPACKE_free( tau );
00274 }
00275 if( tau_i != NULL ) {
00276 LAPACKE_free( tau_i );
00277 }
00278 if( tau_save != NULL ) {
00279 LAPACKE_free( tau_save );
00280 }
00281
00282 return 0;
00283 }
00284
00285
00286 static void init_scalars_ssptrd( char *uplo, lapack_int *n )
00287 {
00288 *uplo = 'L';
00289 *n = 4;
00290
00291 return;
00292 }
00293
00294
00295 static void init_ap( lapack_int size, float *ap ) {
00296 lapack_int i;
00297 for( i = 0; i < size; i++ ) {
00298 ap[i] = 0;
00299 }
00300 ap[0] = 5.769230798e-002;
00301 ap[1] = 1.703930944e-001;
00302 ap[2] = 2.949949205e-001;
00303 ap[3] = -6.024086475e-001;
00304 ap[4] = 2.267657369e-001;
00305 ap[5] = 8.667321205e-001;
00306 ap[6] = -6.159023643e-001;
00307 ap[7] = -5.000129342e-002;
00308 ap[8] = 3.972190619e-001;
00309 ap[9] = -1.687545180e+000;
00310 }
00311 static void init_d( lapack_int size, float *d ) {
00312 lapack_int i;
00313 for( i = 0; i < size; i++ ) {
00314 d[i] = 0;
00315 }
00316 }
00317 static void init_e( lapack_int size, float *e ) {
00318 lapack_int i;
00319 for( i = 0; i < size; i++ ) {
00320 e[i] = 0;
00321 }
00322 }
00323 static void init_tau( lapack_int size, float *tau ) {
00324 lapack_int i;
00325 for( i = 0; i < size; i++ ) {
00326 tau[i] = 0;
00327 }
00328 }
00329
00330
00331
00332 static int compare_ssptrd( float *ap, float *ap_i, float *d, float *d_i,
00333 float *e, float *e_i, float *tau, float *tau_i,
00334 lapack_int info, lapack_int info_i, lapack_int n )
00335 {
00336 lapack_int i;
00337 int failed = 0;
00338 for( i = 0; i < (n*(n+1)/2); i++ ) {
00339 failed += compare_floats(ap[i],ap_i[i]);
00340 }
00341 for( i = 0; i < n; i++ ) {
00342 failed += compare_floats(d[i],d_i[i]);
00343 }
00344 for( i = 0; i < (n-1); i++ ) {
00345 failed += compare_floats(e[i],e_i[i]);
00346 }
00347 for( i = 0; i < (n-1); i++ ) {
00348 failed += compare_floats(tau[i],tau_i[i]);
00349 }
00350 failed += (info == info_i) ? 0 : 1;
00351 if( info != 0 || info_i != 0 ) {
00352 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00353 }
00354
00355 return failed;
00356 }