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