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_dsptrd( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, double *ap );
00056 static void init_d( lapack_int size, double *d );
00057 static void init_e( lapack_int size, double *e );
00058 static void init_tau( lapack_int size, double *tau );
00059 static int compare_dsptrd( double *ap, double *ap_i, double *d, double *d_i,
00060 double *e, double *e_i, double *tau, double *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 double *ap = NULL, *ap_i = NULL;
00074 double *d = NULL, *d_i = NULL;
00075 double *e = NULL, *e_i = NULL;
00076 double *tau = NULL, *tau_i = NULL;
00077 double *ap_save = NULL;
00078 double *d_save = NULL;
00079 double *e_save = NULL;
00080 double *tau_save = NULL;
00081 double *ap_r = NULL;
00082
00083
00084 init_scalars_dsptrd( &uplo, &n );
00085 uplo_i = uplo;
00086 n_i = n;
00087
00088
00089 ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00090 d = (double *)LAPACKE_malloc( n * sizeof(double) );
00091 e = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00092 tau = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00093
00094
00095 ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00096 d_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00097 e_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00098 tau_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00099
00100
00101 ap_save = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00102 d_save = (double *)LAPACKE_malloc( n * sizeof(double) );
00103 e_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00104 tau_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00105
00106
00107 ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
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 dsptrd_( &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_dsptrd_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00147 tau_i );
00148
00149 failed = compare_dsptrd( 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 dsptrd\n" );
00153 } else {
00154 printf( "FAILED: column-major middle-level interface to dsptrd\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_dsptrd( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00172 tau_i );
00173
00174 failed = compare_dsptrd( 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 dsptrd\n" );
00178 } else {
00179 printf( "FAILED: column-major high-level interface to dsptrd\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_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198 info_i = LAPACKE_dsptrd_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00199 tau_i );
00200
00201 LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00202
00203 failed = compare_dsptrd( 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 dsptrd\n" );
00207 } else {
00208 printf( "FAILED: row-major middle-level interface to dsptrd\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_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00228 info_i = LAPACKE_dsptrd( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00229 tau_i );
00230
00231 LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00232
00233 failed = compare_dsptrd( 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 dsptrd\n" );
00237 } else {
00238 printf( "FAILED: row-major high-level interface to dsptrd\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_dsptrd( 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, double *ap ) {
00296 lapack_int i;
00297 for( i = 0; i < size; i++ ) {
00298 ap[i] = 0;
00299 }
00300 ap[0] = 5.76923076923076890e-002;
00301 ap[1] = 1.70393118107254630e-001;
00302 ap[2] = 2.94994937709884000e-001;
00303 ap[3] = -6.02408803967131700e-001;
00304 ap[4] = 2.26765799256505530e-001;
00305 ap[5] = 8.66732278893501460e-001;
00306 ap[6] = -6.15902621315513990e-001;
00307 ap[7] = -5.00011600337520040e-002;
00308 ap[8] = 3.97218700415568730e-001;
00309 ap[9] = -1.68754520903792620e+000;
00310 }
00311 static void init_d( lapack_int size, double *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, double *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, double *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_dsptrd( double *ap, double *ap_i, double *d, double *d_i,
00333 double *e, double *e_i, double *tau, double *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_doubles(ap[i],ap_i[i]);
00340 }
00341 for( i = 0; i < n; i++ ) {
00342 failed += compare_doubles(d[i],d_i[i]);
00343 }
00344 for( i = 0; i < (n-1); i++ ) {
00345 failed += compare_doubles(e[i],e_i[i]);
00346 }
00347 for( i = 0; i < (n-1); i++ ) {
00348 failed += compare_doubles(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 }