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_cpotri( char *uplo, lapack_int *n, lapack_int *lda );
00055 static void init_a( lapack_int size, lapack_complex_float *a );
00056 static int compare_cpotri( lapack_complex_float *a, lapack_complex_float *a_i,
00057 lapack_int info, lapack_int info_i, lapack_int lda,
00058 lapack_int n );
00059
00060 int main(void)
00061 {
00062
00063 char uplo, uplo_i;
00064 lapack_int n, n_i;
00065 lapack_int lda, lda_i;
00066 lapack_int lda_r;
00067 lapack_int info, info_i;
00068 lapack_int i;
00069 int failed;
00070
00071
00072 lapack_complex_float *a = NULL, *a_i = NULL;
00073 lapack_complex_float *a_save = NULL;
00074 lapack_complex_float *a_r = NULL;
00075
00076
00077 init_scalars_cpotri( &uplo, &n, &lda );
00078 lda_r = n+2;
00079 uplo_i = uplo;
00080 n_i = n;
00081 lda_i = lda;
00082
00083
00084 a = (lapack_complex_float *)
00085 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00086
00087
00088 a_i = (lapack_complex_float *)
00089 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00090
00091
00092 a_save = (lapack_complex_float *)
00093 LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00094
00095
00096 a_r = (lapack_complex_float *)
00097 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00098
00099
00100 init_a( lda*n, a );
00101
00102
00103 for( i = 0; i < lda*n; i++ ) {
00104 a_save[i] = a[i];
00105 }
00106
00107
00108 cpotri_( &uplo, &n, a, &lda, &info );
00109
00110
00111
00112 for( i = 0; i < lda*n; i++ ) {
00113 a_i[i] = a_save[i];
00114 }
00115 info_i = LAPACKE_cpotri_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i );
00116
00117 failed = compare_cpotri( a, a_i, info, info_i, lda, n );
00118 if( failed == 0 ) {
00119 printf( "PASSED: column-major middle-level interface to cpotri\n" );
00120 } else {
00121 printf( "FAILED: column-major middle-level interface to cpotri\n" );
00122 }
00123
00124
00125
00126 for( i = 0; i < lda*n; i++ ) {
00127 a_i[i] = a_save[i];
00128 }
00129 info_i = LAPACKE_cpotri( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i );
00130
00131 failed = compare_cpotri( a, a_i, info, info_i, lda, n );
00132 if( failed == 0 ) {
00133 printf( "PASSED: column-major high-level interface to cpotri\n" );
00134 } else {
00135 printf( "FAILED: column-major high-level interface to cpotri\n" );
00136 }
00137
00138
00139
00140 for( i = 0; i < lda*n; i++ ) {
00141 a_i[i] = a_save[i];
00142 }
00143
00144 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00145 info_i = LAPACKE_cpotri_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r );
00146
00147 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00148
00149 failed = compare_cpotri( a, a_i, info, info_i, lda, n );
00150 if( failed == 0 ) {
00151 printf( "PASSED: row-major middle-level interface to cpotri\n" );
00152 } else {
00153 printf( "FAILED: row-major middle-level interface to cpotri\n" );
00154 }
00155
00156
00157
00158 for( i = 0; i < lda*n; i++ ) {
00159 a_i[i] = a_save[i];
00160 }
00161
00162
00163 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00164 info_i = LAPACKE_cpotri( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r );
00165
00166 LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00167
00168 failed = compare_cpotri( a, a_i, info, info_i, lda, n );
00169 if( failed == 0 ) {
00170 printf( "PASSED: row-major high-level interface to cpotri\n" );
00171 } else {
00172 printf( "FAILED: row-major high-level interface to cpotri\n" );
00173 }
00174
00175
00176 if( a != NULL ) {
00177 LAPACKE_free( a );
00178 }
00179 if( a_i != NULL ) {
00180 LAPACKE_free( a_i );
00181 }
00182 if( a_r != NULL ) {
00183 LAPACKE_free( a_r );
00184 }
00185 if( a_save != NULL ) {
00186 LAPACKE_free( a_save );
00187 }
00188
00189 return 0;
00190 }
00191
00192
00193 static void init_scalars_cpotri( char *uplo, lapack_int *n, lapack_int *lda )
00194 {
00195 *uplo = 'L';
00196 *n = 4;
00197 *lda = 8;
00198
00199 return;
00200 }
00201
00202
00203 static void init_a( lapack_int size, lapack_complex_float *a ) {
00204 lapack_int i;
00205 for( i = 0; i < size; i++ ) {
00206 a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00207 }
00208 a[0] = lapack_make_complex_float( 1.797220111e+000, 0.000000000e+000 );
00209 a[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00210 a[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00211 a[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00212 a[1] = lapack_make_complex_float( 8.401864767e-001, 1.068316579e+000 );
00213 a[9] = lapack_make_complex_float( 1.316353440e+000, 0.000000000e+000 );
00214 a[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00215 a[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00216 a[2] = lapack_make_complex_float( 1.057188272e+000, -4.673885107e-001 );
00217 a[10] = lapack_make_complex_float( -4.701749086e-001, 3.130658567e-001 );
00218 a[18] = lapack_make_complex_float( 1.560392976e+000, 0.000000000e+000 );
00219 a[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00220 a[3] = lapack_make_complex_float( 2.336942554e-001, -1.391037226e+000 );
00221 a[11] = lapack_make_complex_float( 8.335255086e-002, 3.676066548e-002 );
00222 a[19] = lapack_make_complex_float( 9.359616637e-001, 9.899691939e-001 );
00223 a[27] = lapack_make_complex_float( 6.603333950e-001, 0.000000000e+000 );
00224 }
00225
00226
00227
00228 static int compare_cpotri( lapack_complex_float *a, lapack_complex_float *a_i,
00229 lapack_int info, lapack_int info_i, lapack_int lda,
00230 lapack_int n )
00231 {
00232 lapack_int i;
00233 int failed = 0;
00234 for( i = 0; i < lda*n; i++ ) {
00235 failed += compare_complex_floats(a[i],a_i[i]);
00236 }
00237 failed += (info == info_i) ? 0 : 1;
00238 if( info != 0 || info_i != 0 ) {
00239 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00240 }
00241
00242 return failed;
00243 }