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_zgetri( lapack_int *n, lapack_int *lda,
00055 lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_double *a );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_work( lapack_int size, lapack_complex_double *work );
00059 static int compare_zgetri( lapack_complex_double *a, lapack_complex_double *a_i,
00060 lapack_int info, lapack_int info_i, lapack_int lda,
00061 lapack_int n );
00062
00063 int main(void)
00064 {
00065
00066 lapack_int n, n_i;
00067 lapack_int lda, lda_i;
00068 lapack_int lda_r;
00069 lapack_int lwork, lwork_i;
00070 lapack_int info, info_i;
00071 lapack_int i;
00072 int failed;
00073
00074
00075 lapack_complex_double *a = NULL, *a_i = NULL;
00076 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00077 lapack_complex_double *work = NULL, *work_i = NULL;
00078 lapack_complex_double *a_save = NULL;
00079 lapack_complex_double *a_r = NULL;
00080
00081
00082 init_scalars_zgetri( &n, &lda, &lwork );
00083 lda_r = n+2;
00084 n_i = n;
00085 lda_i = lda;
00086 lwork_i = lwork;
00087
00088
00089 a = (lapack_complex_double *)
00090 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00091 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00092 work = (lapack_complex_double *)
00093 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00094
00095
00096 a_i = (lapack_complex_double *)
00097 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00098 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00099 work_i = (lapack_complex_double *)
00100 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00101
00102
00103 a_save = (lapack_complex_double *)
00104 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00105
00106
00107 a_r = (lapack_complex_double *)
00108 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00109
00110
00111 init_a( lda*n, a );
00112 init_ipiv( n, ipiv );
00113 init_work( lwork, work );
00114
00115
00116 for( i = 0; i < lda*n; i++ ) {
00117 a_save[i] = a[i];
00118 }
00119
00120
00121 zgetri_( &n, a, &lda, ipiv, work, &lwork, &info );
00122
00123
00124
00125 for( i = 0; i < lda*n; i++ ) {
00126 a_i[i] = a_save[i];
00127 }
00128 for( i = 0; i < n; i++ ) {
00129 ipiv_i[i] = ipiv[i];
00130 }
00131 for( i = 0; i < lwork; i++ ) {
00132 work_i[i] = work[i];
00133 }
00134 info_i = LAPACKE_zgetri_work( LAPACK_COL_MAJOR, n_i, a_i, lda_i, ipiv_i,
00135 work_i, lwork_i );
00136
00137 failed = compare_zgetri( a, a_i, info, info_i, lda, n );
00138 if( failed == 0 ) {
00139 printf( "PASSED: column-major middle-level interface to zgetri\n" );
00140 } else {
00141 printf( "FAILED: column-major middle-level interface to zgetri\n" );
00142 }
00143
00144
00145
00146 for( i = 0; i < lda*n; i++ ) {
00147 a_i[i] = a_save[i];
00148 }
00149 for( i = 0; i < n; i++ ) {
00150 ipiv_i[i] = ipiv[i];
00151 }
00152 for( i = 0; i < lwork; i++ ) {
00153 work_i[i] = work[i];
00154 }
00155 info_i = LAPACKE_zgetri( LAPACK_COL_MAJOR, n_i, a_i, lda_i, ipiv_i );
00156
00157 failed = compare_zgetri( a, a_i, info, info_i, lda, n );
00158 if( failed == 0 ) {
00159 printf( "PASSED: column-major high-level interface to zgetri\n" );
00160 } else {
00161 printf( "FAILED: column-major high-level interface to zgetri\n" );
00162 }
00163
00164
00165
00166 for( i = 0; i < lda*n; i++ ) {
00167 a_i[i] = a_save[i];
00168 }
00169 for( i = 0; i < n; i++ ) {
00170 ipiv_i[i] = ipiv[i];
00171 }
00172 for( i = 0; i < lwork; i++ ) {
00173 work_i[i] = work[i];
00174 }
00175
00176 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00177 info_i = LAPACKE_zgetri_work( LAPACK_ROW_MAJOR, n_i, a_r, lda_r, ipiv_i,
00178 work_i, lwork_i );
00179
00180 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00181
00182 failed = compare_zgetri( a, a_i, info, info_i, lda, n );
00183 if( failed == 0 ) {
00184 printf( "PASSED: row-major middle-level interface to zgetri\n" );
00185 } else {
00186 printf( "FAILED: row-major middle-level interface to zgetri\n" );
00187 }
00188
00189
00190
00191 for( i = 0; i < lda*n; i++ ) {
00192 a_i[i] = a_save[i];
00193 }
00194 for( i = 0; i < n; i++ ) {
00195 ipiv_i[i] = ipiv[i];
00196 }
00197 for( i = 0; i < lwork; i++ ) {
00198 work_i[i] = work[i];
00199 }
00200
00201
00202 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00203 info_i = LAPACKE_zgetri( LAPACK_ROW_MAJOR, n_i, a_r, lda_r, ipiv_i );
00204
00205 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00206
00207 failed = compare_zgetri( a, a_i, info, info_i, lda, n );
00208 if( failed == 0 ) {
00209 printf( "PASSED: row-major high-level interface to zgetri\n" );
00210 } else {
00211 printf( "FAILED: row-major high-level interface to zgetri\n" );
00212 }
00213
00214
00215 if( a != NULL ) {
00216 LAPACKE_free( a );
00217 }
00218 if( a_i != NULL ) {
00219 LAPACKE_free( a_i );
00220 }
00221 if( a_r != NULL ) {
00222 LAPACKE_free( a_r );
00223 }
00224 if( a_save != NULL ) {
00225 LAPACKE_free( a_save );
00226 }
00227 if( ipiv != NULL ) {
00228 LAPACKE_free( ipiv );
00229 }
00230 if( ipiv_i != NULL ) {
00231 LAPACKE_free( ipiv_i );
00232 }
00233 if( work != NULL ) {
00234 LAPACKE_free( work );
00235 }
00236 if( work_i != NULL ) {
00237 LAPACKE_free( work_i );
00238 }
00239
00240 return 0;
00241 }
00242
00243
00244 static void init_scalars_zgetri( lapack_int *n, lapack_int *lda,
00245 lapack_int *lwork )
00246 {
00247 *n = 4;
00248 *lda = 8;
00249 *lwork = 512;
00250
00251 return;
00252 }
00253
00254
00255 static void init_a( lapack_int size, lapack_complex_double *a ) {
00256 lapack_int i;
00257 for( i = 0; i < size; i++ ) {
00258 a[i] = lapack_make_complex_double( 0.0, 0.0 );
00259 }
00260 a[0] = lapack_make_complex_double( -3.29000000000000000e+000,
00261 -2.39000000000000010e+000 );
00262 a[8] = lapack_make_complex_double( -1.90999999999999990e+000,
00263 4.41999999999999990e+000 );
00264 a[16] = lapack_make_complex_double( -1.40000000000000010e-001,
00265 -1.35000000000000010e+000 );
00266 a[24] = lapack_make_complex_double( 1.72000000000000000e+000,
00267 1.35000000000000010e+000 );
00268 a[1] = lapack_make_complex_double( 2.37612026946940610e-001,
00269 2.55959652157085600e-001 );
00270 a[9] = lapack_make_complex_double( 4.89518063400297530e+000,
00271 -7.11362223485444090e-001 );
00272 a[17] = lapack_make_complex_double( -4.62279846639493950e-001,
00273 1.69661058768036190e+000 );
00274 a[25] = lapack_make_complex_double( 1.22685284406332770e+000,
00275 6.18973161911442920e-001 );
00276 a[2] = lapack_make_complex_double( -1.01952080889200600e-001,
00277 -7.01013533943711350e-001 );
00278 a[10] = lapack_make_complex_double( -6.69149643194321130e-001,
00279 3.68869854797165500e-001 );
00280 a[18] = lapack_make_complex_double( -5.14141091381023150e+000,
00281 -1.12996973466095300e+000 );
00282 a[26] = lapack_make_complex_double( 9.98257991519944880e-001,
00283 3.85015227576377740e-001 );
00284 a[3] = lapack_make_complex_double( -5.35854670359574790e-001,
00285 2.70727252935982880e-001 );
00286 a[11] = lapack_make_complex_double( -2.04021779458707920e-001,
00287 8.60118067998404510e-001 );
00288 a[19] = lapack_make_complex_double( 8.23304706394011040e-003,
00289 1.21063681991063470e-001 );
00290 a[27] = lapack_make_complex_double( 1.48239181074841820e-001,
00291 -1.25223998607584600e-001 );
00292 }
00293 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00294 lapack_int i;
00295 for( i = 0; i < size; i++ ) {
00296 ipiv[i] = 0;
00297 }
00298 ipiv[0] = 3;
00299 ipiv[1] = 2;
00300 ipiv[2] = 3;
00301 ipiv[3] = 4;
00302 }
00303 static void init_work( lapack_int size, lapack_complex_double *work ) {
00304 lapack_int i;
00305 for( i = 0; i < size; i++ ) {
00306 work[i] = lapack_make_complex_double( 0.0, 0.0 );
00307 }
00308 }
00309
00310
00311
00312 static int compare_zgetri( lapack_complex_double *a, lapack_complex_double *a_i,
00313 lapack_int info, lapack_int info_i, lapack_int lda,
00314 lapack_int n )
00315 {
00316 lapack_int i;
00317 int failed = 0;
00318 for( i = 0; i < lda*n; i++ ) {
00319 failed += compare_complex_doubles(a[i],a_i[i]);
00320 }
00321 failed += (info == info_i) ? 0 : 1;
00322 if( info != 0 || info_i != 0 ) {
00323 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00324 }
00325
00326 return failed;
00327 }