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_csptri( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, lapack_complex_float *ap );
00056 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00057 static void init_work( lapack_int size, lapack_complex_float *work );
00058 static int compare_csptri( lapack_complex_float *ap, lapack_complex_float *ap_i,
00059 lapack_int info, lapack_int info_i, lapack_int n );
00060
00061 int main(void)
00062 {
00063
00064 char uplo, uplo_i;
00065 lapack_int n, n_i;
00066 lapack_int info, info_i;
00067 lapack_int i;
00068 int failed;
00069
00070
00071 lapack_complex_float *ap = NULL, *ap_i = NULL;
00072 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00073 lapack_complex_float *work = NULL, *work_i = NULL;
00074 lapack_complex_float *ap_save = NULL;
00075 lapack_complex_float *ap_r = NULL;
00076
00077
00078 init_scalars_csptri( &uplo, &n );
00079 uplo_i = uplo;
00080 n_i = n;
00081
00082
00083 ap = (lapack_complex_float *)
00084 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00085 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00086 work = (lapack_complex_float *)
00087 LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00088
00089
00090 ap_i = (lapack_complex_float *)
00091 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00092 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00093 work_i = (lapack_complex_float *)
00094 LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00095
00096
00097 ap_save = (lapack_complex_float *)
00098 LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00099
00100
00101 ap_r = (lapack_complex_float *)
00102 LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00103
00104
00105 init_ap( (n*(n+1)/2), ap );
00106 init_ipiv( n, ipiv );
00107 init_work( n, work );
00108
00109
00110 for( i = 0; i < (n*(n+1)/2); i++ ) {
00111 ap_save[i] = ap[i];
00112 }
00113
00114
00115 csptri_( &uplo, &n, ap, ipiv, work, &info );
00116
00117
00118
00119 for( i = 0; i < (n*(n+1)/2); i++ ) {
00120 ap_i[i] = ap_save[i];
00121 }
00122 for( i = 0; i < n; i++ ) {
00123 ipiv_i[i] = ipiv[i];
00124 }
00125 for( i = 0; i < n; i++ ) {
00126 work_i[i] = work[i];
00127 }
00128 info_i = LAPACKE_csptri_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i,
00129 work_i );
00130
00131 failed = compare_csptri( ap, ap_i, info, info_i, n );
00132 if( failed == 0 ) {
00133 printf( "PASSED: column-major middle-level interface to csptri\n" );
00134 } else {
00135 printf( "FAILED: column-major middle-level interface to csptri\n" );
00136 }
00137
00138
00139
00140 for( i = 0; i < (n*(n+1)/2); i++ ) {
00141 ap_i[i] = ap_save[i];
00142 }
00143 for( i = 0; i < n; i++ ) {
00144 ipiv_i[i] = ipiv[i];
00145 }
00146 for( i = 0; i < n; i++ ) {
00147 work_i[i] = work[i];
00148 }
00149 info_i = LAPACKE_csptri( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00150
00151 failed = compare_csptri( ap, ap_i, info, info_i, n );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major high-level interface to csptri\n" );
00154 } else {
00155 printf( "FAILED: column-major high-level interface to csptri\n" );
00156 }
00157
00158
00159
00160 for( i = 0; i < (n*(n+1)/2); i++ ) {
00161 ap_i[i] = ap_save[i];
00162 }
00163 for( i = 0; i < n; i++ ) {
00164 ipiv_i[i] = ipiv[i];
00165 }
00166 for( i = 0; i < n; i++ ) {
00167 work_i[i] = work[i];
00168 }
00169
00170 LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00171 info_i = LAPACKE_csptri_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i,
00172 work_i );
00173
00174 LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00175
00176 failed = compare_csptri( ap, ap_i, info, info_i, n );
00177 if( failed == 0 ) {
00178 printf( "PASSED: row-major middle-level interface to csptri\n" );
00179 } else {
00180 printf( "FAILED: row-major middle-level interface to csptri\n" );
00181 }
00182
00183
00184
00185 for( i = 0; i < (n*(n+1)/2); i++ ) {
00186 ap_i[i] = ap_save[i];
00187 }
00188 for( i = 0; i < n; i++ ) {
00189 ipiv_i[i] = ipiv[i];
00190 }
00191 for( i = 0; i < n; i++ ) {
00192 work_i[i] = work[i];
00193 }
00194
00195
00196 LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00197 info_i = LAPACKE_csptri( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00198
00199 LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00200
00201 failed = compare_csptri( ap, ap_i, info, info_i, n );
00202 if( failed == 0 ) {
00203 printf( "PASSED: row-major high-level interface to csptri\n" );
00204 } else {
00205 printf( "FAILED: row-major high-level interface to csptri\n" );
00206 }
00207
00208
00209 if( ap != NULL ) {
00210 LAPACKE_free( ap );
00211 }
00212 if( ap_i != NULL ) {
00213 LAPACKE_free( ap_i );
00214 }
00215 if( ap_r != NULL ) {
00216 LAPACKE_free( ap_r );
00217 }
00218 if( ap_save != NULL ) {
00219 LAPACKE_free( ap_save );
00220 }
00221 if( ipiv != NULL ) {
00222 LAPACKE_free( ipiv );
00223 }
00224 if( ipiv_i != NULL ) {
00225 LAPACKE_free( ipiv_i );
00226 }
00227 if( work != NULL ) {
00228 LAPACKE_free( work );
00229 }
00230 if( work_i != NULL ) {
00231 LAPACKE_free( work_i );
00232 }
00233
00234 return 0;
00235 }
00236
00237
00238 static void init_scalars_csptri( char *uplo, lapack_int *n )
00239 {
00240 *uplo = 'L';
00241 *n = 4;
00242
00243 return;
00244 }
00245
00246
00247 static void init_ap( lapack_int size, lapack_complex_float *ap ) {
00248 lapack_int i;
00249 for( i = 0; i < size; i++ ) {
00250 ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00251 }
00252 ap[0] = lapack_make_complex_float( -3.899999857e-001, -7.099999785e-001 );
00253 ap[1] = lapack_make_complex_float( -7.860000134e+000, -2.960000038e+000 );
00254 ap[2] = lapack_make_complex_float( 5.278724432e-001, -3.714659810e-001 );
00255 ap[3] = lapack_make_complex_float( 4.425582290e-001, 1.936483681e-001 );
00256 ap[4] = lapack_make_complex_float( -2.829999924e+000, -2.999999933e-002 );
00257 ap[5] = lapack_make_complex_float( -6.078390479e-001, 2.810796499e-001 );
00258 ap[6] = lapack_make_complex_float( -4.822822809e-001, 1.498936117e-002 );
00259 ap[7] = lapack_make_complex_float( 4.407906532e+000, 5.399120808e+000 );
00260 ap[8] = lapack_make_complex_float( -1.070821285e-001, -3.156781197e-001 );
00261 ap[9] = lapack_make_complex_float( -2.095414639e+000, -2.201138735e+000 );
00262 }
00263 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00264 lapack_int i;
00265 for( i = 0; i < size; i++ ) {
00266 ipiv[i] = 0;
00267 }
00268 ipiv[0] = -3;
00269 ipiv[1] = -3;
00270 ipiv[2] = 3;
00271 ipiv[3] = 4;
00272 }
00273 static void init_work( lapack_int size, lapack_complex_float *work ) {
00274 lapack_int i;
00275 for( i = 0; i < size; i++ ) {
00276 work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00277 }
00278 }
00279
00280
00281
00282 static int compare_csptri( lapack_complex_float *ap, lapack_complex_float *ap_i,
00283 lapack_int info, lapack_int info_i, lapack_int n )
00284 {
00285 lapack_int i;
00286 int failed = 0;
00287 for( i = 0; i < (n*(n+1)/2); i++ ) {
00288 failed += compare_complex_floats(ap[i],ap_i[i]);
00289 }
00290 failed += (info == info_i) ? 0 : 1;
00291 if( info != 0 || info_i != 0 ) {
00292 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00293 }
00294
00295 return failed;
00296 }