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_sgetrf( lapack_int *m, lapack_int *n,
00055 lapack_int *lda );
00056 static void init_a( lapack_int size, float *a );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static int compare_sgetrf( float *a, float *a_i, lapack_int *ipiv,
00059 lapack_int *ipiv_i, lapack_int info,
00060 lapack_int info_i, lapack_int lda, lapack_int m,
00061 lapack_int n );
00062
00063 int main(void)
00064 {
00065
00066 lapack_int m, m_i;
00067 lapack_int n, n_i;
00068 lapack_int lda, lda_i;
00069 lapack_int lda_r;
00070 lapack_int info, info_i;
00071 lapack_int i;
00072 int failed;
00073
00074
00075 float *a = NULL, *a_i = NULL;
00076 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00077 float *a_save = NULL;
00078 lapack_int *ipiv_save = NULL;
00079 float *a_r = NULL;
00080
00081
00082 init_scalars_sgetrf( &m, &n, &lda );
00083 lda_r = n+2;
00084 m_i = m;
00085 n_i = n;
00086 lda_i = lda;
00087
00088
00089 a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00090 ipiv = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00091
00092
00093 a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00094 ipiv_i = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00095
00096
00097 a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00098 ipiv_save = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00099
00100
00101 a_r = (float *)LAPACKE_malloc( m*(n+2) * sizeof(float) );
00102
00103
00104 init_a( lda*n, a );
00105 init_ipiv( (MIN(m,n)), ipiv );
00106
00107
00108 for( i = 0; i < lda*n; i++ ) {
00109 a_save[i] = a[i];
00110 }
00111 for( i = 0; i < (MIN(m,n)); i++ ) {
00112 ipiv_save[i] = ipiv[i];
00113 }
00114
00115
00116 sgetrf_( &m, &n, a, &lda, ipiv, &info );
00117
00118
00119
00120 for( i = 0; i < lda*n; i++ ) {
00121 a_i[i] = a_save[i];
00122 }
00123 for( i = 0; i < (MIN(m,n)); i++ ) {
00124 ipiv_i[i] = ipiv_save[i];
00125 }
00126 info_i = LAPACKE_sgetrf_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i,
00127 ipiv_i );
00128
00129 failed = compare_sgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00130 if( failed == 0 ) {
00131 printf( "PASSED: column-major middle-level interface to sgetrf\n" );
00132 } else {
00133 printf( "FAILED: column-major middle-level interface to sgetrf\n" );
00134 }
00135
00136
00137
00138 for( i = 0; i < lda*n; i++ ) {
00139 a_i[i] = a_save[i];
00140 }
00141 for( i = 0; i < (MIN(m,n)); i++ ) {
00142 ipiv_i[i] = ipiv_save[i];
00143 }
00144 info_i = LAPACKE_sgetrf( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, ipiv_i );
00145
00146 failed = compare_sgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00147 if( failed == 0 ) {
00148 printf( "PASSED: column-major high-level interface to sgetrf\n" );
00149 } else {
00150 printf( "FAILED: column-major high-level interface to sgetrf\n" );
00151 }
00152
00153
00154
00155 for( i = 0; i < lda*n; i++ ) {
00156 a_i[i] = a_save[i];
00157 }
00158 for( i = 0; i < (MIN(m,n)); i++ ) {
00159 ipiv_i[i] = ipiv_save[i];
00160 }
00161
00162 LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00163 info_i = LAPACKE_sgetrf_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r,
00164 ipiv_i );
00165
00166 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00167
00168 failed = compare_sgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00169 if( failed == 0 ) {
00170 printf( "PASSED: row-major middle-level interface to sgetrf\n" );
00171 } else {
00172 printf( "FAILED: row-major middle-level interface to sgetrf\n" );
00173 }
00174
00175
00176
00177 for( i = 0; i < lda*n; i++ ) {
00178 a_i[i] = a_save[i];
00179 }
00180 for( i = 0; i < (MIN(m,n)); i++ ) {
00181 ipiv_i[i] = ipiv_save[i];
00182 }
00183
00184
00185 LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00186 info_i = LAPACKE_sgetrf( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, ipiv_i );
00187
00188 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00189
00190 failed = compare_sgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00191 if( failed == 0 ) {
00192 printf( "PASSED: row-major high-level interface to sgetrf\n" );
00193 } else {
00194 printf( "FAILED: row-major high-level interface to sgetrf\n" );
00195 }
00196
00197
00198 if( a != NULL ) {
00199 LAPACKE_free( a );
00200 }
00201 if( a_i != NULL ) {
00202 LAPACKE_free( a_i );
00203 }
00204 if( a_r != NULL ) {
00205 LAPACKE_free( a_r );
00206 }
00207 if( a_save != NULL ) {
00208 LAPACKE_free( a_save );
00209 }
00210 if( ipiv != NULL ) {
00211 LAPACKE_free( ipiv );
00212 }
00213 if( ipiv_i != NULL ) {
00214 LAPACKE_free( ipiv_i );
00215 }
00216 if( ipiv_save != NULL ) {
00217 LAPACKE_free( ipiv_save );
00218 }
00219
00220 return 0;
00221 }
00222
00223
00224 static void init_scalars_sgetrf( lapack_int *m, lapack_int *n, lapack_int *lda )
00225 {
00226 *m = 4;
00227 *n = 4;
00228 *lda = 8;
00229
00230 return;
00231 }
00232
00233
00234 static void init_a( lapack_int size, float *a ) {
00235 lapack_int i;
00236 for( i = 0; i < size; i++ ) {
00237 a[i] = 0;
00238 }
00239 a[0] = 1.799999952e+000;
00240 a[8] = 2.880000114e+000;
00241 a[16] = 2.049999952e+000;
00242 a[24] = -8.899999857e-001;
00243 a[1] = 5.250000000e+000;
00244 a[9] = -2.950000048e+000;
00245 a[17] = -9.499999881e-001;
00246 a[25] = -3.799999952e+000;
00247 a[2] = 1.580000043e+000;
00248 a[10] = -2.690000057e+000;
00249 a[18] = -2.900000095e+000;
00250 a[26] = -1.039999962e+000;
00251 a[3] = -1.110000014e+000;
00252 a[11] = -6.600000262e-001;
00253 a[19] = -5.899999738e-001;
00254 a[27] = 8.000000119e-001;
00255 }
00256 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00257 lapack_int i;
00258 for( i = 0; i < size; i++ ) {
00259 ipiv[i] = 0;
00260 }
00261 }
00262
00263
00264
00265 static int compare_sgetrf( float *a, float *a_i, lapack_int *ipiv,
00266 lapack_int *ipiv_i, lapack_int info,
00267 lapack_int info_i, lapack_int lda, lapack_int m,
00268 lapack_int n )
00269 {
00270 lapack_int i;
00271 int failed = 0;
00272 for( i = 0; i < lda*n; i++ ) {
00273 failed += compare_floats(a[i],a_i[i]);
00274 }
00275 for( i = 0; i < (MIN(m,n)); i++ ) {
00276 failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00277 }
00278 failed += (info == info_i) ? 0 : 1;
00279 if( info != 0 || info_i != 0 ) {
00280 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00281 }
00282
00283 return failed;
00284 }