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_cupgtr( char *uplo, lapack_int *n, lapack_int *ldq );
00055 static void init_ap( lapack_int size, lapack_complex_float *ap );
00056 static void init_tau( lapack_int size, lapack_complex_float *tau );
00057 static void init_q( lapack_int size, lapack_complex_float *q );
00058 static void init_work( lapack_int size, lapack_complex_float *work );
00059 static int compare_cupgtr( lapack_complex_float *q, lapack_complex_float *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_float *ap = NULL, *ap_i = NULL;
00076 lapack_complex_float *tau = NULL, *tau_i = NULL;
00077 lapack_complex_float *q = NULL, *q_i = NULL;
00078 lapack_complex_float *work = NULL, *work_i = NULL;
00079 lapack_complex_float *q_save = NULL;
00080 lapack_complex_float *ap_r = NULL;
00081 lapack_complex_float *q_r = NULL;
00082
00083
00084 init_scalars_cupgtr( &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_float *)
00092 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00093 tau = (lapack_complex_float *)
00094 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00095 q = (lapack_complex_float *)
00096 LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00097 work = (lapack_complex_float *)
00098 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00099
00100
00101 ap_i = (lapack_complex_float *)
00102 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00103 tau_i = (lapack_complex_float *)
00104 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00105 q_i = (lapack_complex_float *)
00106 LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00107 work_i = (lapack_complex_float *)
00108 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00109
00110
00111 q_save = (lapack_complex_float *)
00112 LAPACKE_malloc( ldq*n * sizeof(lapack_complex_float) );
00113
00114
00115 ap_r = (lapack_complex_float *)
00116 LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00117 q_r = (lapack_complex_float *)
00118 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
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 cupgtr_( &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_cupgtr_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, tau_i,
00149 q_i, ldq_i, work_i );
00150
00151 failed = compare_cupgtr( q, q_i, info, info_i, ldq, n );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major middle-level interface to cupgtr\n" );
00154 } else {
00155 printf( "FAILED: column-major middle-level interface to cupgtr\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_cupgtr( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, tau_i, q_i,
00173 ldq_i );
00174
00175 failed = compare_cupgtr( q, q_i, info, info_i, ldq, n );
00176 if( failed == 0 ) {
00177 printf( "PASSED: column-major high-level interface to cupgtr\n" );
00178 } else {
00179 printf( "FAILED: column-major high-level interface to cupgtr\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_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00199 info_i = LAPACKE_cupgtr_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, tau_i,
00200 q_r, ldq_r, work_i );
00201
00202 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00203
00204 failed = compare_cupgtr( q, q_i, info, info_i, ldq, n );
00205 if( failed == 0 ) {
00206 printf( "PASSED: row-major middle-level interface to cupgtr\n" );
00207 } else {
00208 printf( "FAILED: row-major middle-level interface to cupgtr\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_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00228 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00229 info_i = LAPACKE_cupgtr( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, tau_i, q_r,
00230 ldq_r );
00231
00232 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00233
00234 failed = compare_cupgtr( q, q_i, info, info_i, ldq, n );
00235 if( failed == 0 ) {
00236 printf( "PASSED: row-major high-level interface to cupgtr\n" );
00237 } else {
00238 printf( "FAILED: row-major high-level interface to cupgtr\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_cupgtr( 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_float *ap ) {
00291 lapack_int i;
00292 for( i = 0; i < size; i++ ) {
00293 ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00294 }
00295 ap[0] = lapack_make_complex_float( -2.279999971e+000, 0.000000000e+000 );
00296 ap[1] = lapack_make_complex_float( -4.338455677e+000, 0.000000000e+000 );
00297 ap[2] = lapack_make_complex_float( 3.278606534e-001, -1.251226068e-001 );
00298 ap[3] = lapack_make_complex_float( -1.412565559e-001, -3.666364849e-001 );
00299 ap[4] = lapack_make_complex_float( -1.284568310e-001, 0.000000000e+000 );
00300 ap[5] = lapack_make_complex_float( -2.022594690e+000, 0.000000000e+000 );
00301 ap[6] = lapack_make_complex_float( -3.083218634e-001, 1.763225943e-001 );
00302 ap[7] = lapack_make_complex_float( -1.665935516e-001, 0.000000000e+000 );
00303 ap[8] = lapack_make_complex_float( -1.802322745e+000, 0.000000000e+000 );
00304 ap[9] = lapack_make_complex_float( -1.924949646e+000, 0.000000000e+000 );
00305 }
00306 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00307 lapack_int i;
00308 for( i = 0; i < size; i++ ) {
00309 tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00310 }
00311 tau[0] = lapack_make_complex_float( 1.410284281e+000, 4.679084122e-001 );
00312 tau[1] = lapack_make_complex_float( 1.302420378e+000, 7.853320837e-001 );
00313 tau[2] = lapack_make_complex_float( 1.093973756e+000, -9.955747128e-001 );
00314 }
00315 static void init_q( lapack_int size, lapack_complex_float *q ) {
00316 lapack_int i;
00317 for( i = 0; i < size; i++ ) {
00318 q[i] = lapack_make_complex_float( 0.0f, 0.0f );
00319 }
00320 }
00321 static void init_work( lapack_int size, lapack_complex_float *work ) {
00322 lapack_int i;
00323 for( i = 0; i < size; i++ ) {
00324 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00325 }
00326 }
00327
00328
00329
00330 static int compare_cupgtr( lapack_complex_float *q, lapack_complex_float *q_i,
00331 lapack_int info, lapack_int info_i, lapack_int ldq,
00332 lapack_int n )
00333 {
00334 lapack_int i;
00335 int failed = 0;
00336 for( i = 0; i < ldq*n; i++ ) {
00337 failed += compare_complex_floats(q[i],q_i[i]);
00338 }
00339 failed += (info == info_i) ? 0 : 1;
00340 if( info != 0 || info_i != 0 ) {
00341 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00342 }
00343
00344 return failed;
00345 }