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