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_dtrtrs( char *uplo, char *trans, char *diag,
00055 lapack_int *n, lapack_int *nrhs,
00056 lapack_int *lda, lapack_int *ldb );
00057 static void init_a( lapack_int size, double *a );
00058 static void init_b( lapack_int size, double *b );
00059 static int compare_dtrtrs( double *b, double *b_i, lapack_int info,
00060 lapack_int info_i, lapack_int ldb, lapack_int nrhs );
00061
00062 int main(void)
00063 {
00064
00065 char uplo, uplo_i;
00066 char trans, trans_i;
00067 char diag, diag_i;
00068 lapack_int n, n_i;
00069 lapack_int nrhs, nrhs_i;
00070 lapack_int lda, lda_i;
00071 lapack_int lda_r;
00072 lapack_int ldb, ldb_i;
00073 lapack_int ldb_r;
00074 lapack_int info, info_i;
00075 lapack_int i;
00076 int failed;
00077
00078
00079 double *a = NULL, *a_i = NULL;
00080 double *b = NULL, *b_i = NULL;
00081 double *b_save = NULL;
00082 double *a_r = NULL;
00083 double *b_r = NULL;
00084
00085
00086 init_scalars_dtrtrs( &uplo, &trans, &diag, &n, &nrhs, &lda, &ldb );
00087 lda_r = n+2;
00088 ldb_r = nrhs+2;
00089 uplo_i = uplo;
00090 trans_i = trans;
00091 diag_i = diag;
00092 n_i = n;
00093 nrhs_i = nrhs;
00094 lda_i = lda;
00095 ldb_i = ldb;
00096
00097
00098 a = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00099 b = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00100
00101
00102 a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00103 b_i = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00104
00105
00106 b_save = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00107
00108
00109 a_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) );
00110 b_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00111
00112
00113 init_a( lda*n, a );
00114 init_b( ldb*nrhs, b );
00115
00116
00117 for( i = 0; i < ldb*nrhs; i++ ) {
00118 b_save[i] = b[i];
00119 }
00120
00121
00122 dtrtrs_( &uplo, &trans, &diag, &n, &nrhs, a, &lda, b, &ldb, &info );
00123
00124
00125
00126 for( i = 0; i < lda*n; i++ ) {
00127 a_i[i] = a[i];
00128 }
00129 for( i = 0; i < ldb*nrhs; i++ ) {
00130 b_i[i] = b_save[i];
00131 }
00132 info_i = LAPACKE_dtrtrs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00133 n_i, nrhs_i, a_i, lda_i, b_i, ldb_i );
00134
00135 failed = compare_dtrtrs( b, b_i, info, info_i, ldb, nrhs );
00136 if( failed == 0 ) {
00137 printf( "PASSED: column-major middle-level interface to dtrtrs\n" );
00138 } else {
00139 printf( "FAILED: column-major middle-level interface to dtrtrs\n" );
00140 }
00141
00142
00143
00144 for( i = 0; i < lda*n; i++ ) {
00145 a_i[i] = a[i];
00146 }
00147 for( i = 0; i < ldb*nrhs; i++ ) {
00148 b_i[i] = b_save[i];
00149 }
00150 info_i = LAPACKE_dtrtrs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00151 nrhs_i, a_i, lda_i, b_i, ldb_i );
00152
00153 failed = compare_dtrtrs( b, b_i, info, info_i, ldb, nrhs );
00154 if( failed == 0 ) {
00155 printf( "PASSED: column-major high-level interface to dtrtrs\n" );
00156 } else {
00157 printf( "FAILED: column-major high-level interface to dtrtrs\n" );
00158 }
00159
00160
00161
00162 for( i = 0; i < lda*n; i++ ) {
00163 a_i[i] = a[i];
00164 }
00165 for( i = 0; i < ldb*nrhs; i++ ) {
00166 b_i[i] = b_save[i];
00167 }
00168
00169 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00170 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00171 info_i = LAPACKE_dtrtrs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00172 n_i, nrhs_i, a_r, lda_r, b_r, ldb_r );
00173
00174 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00175
00176 failed = compare_dtrtrs( b, b_i, info, info_i, ldb, nrhs );
00177 if( failed == 0 ) {
00178 printf( "PASSED: row-major middle-level interface to dtrtrs\n" );
00179 } else {
00180 printf( "FAILED: row-major middle-level interface to dtrtrs\n" );
00181 }
00182
00183
00184
00185 for( i = 0; i < lda*n; i++ ) {
00186 a_i[i] = a[i];
00187 }
00188 for( i = 0; i < ldb*nrhs; i++ ) {
00189 b_i[i] = b_save[i];
00190 }
00191
00192
00193 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00194 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00195 info_i = LAPACKE_dtrtrs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00196 nrhs_i, a_r, lda_r, b_r, ldb_r );
00197
00198 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00199
00200 failed = compare_dtrtrs( b, b_i, info, info_i, ldb, nrhs );
00201 if( failed == 0 ) {
00202 printf( "PASSED: row-major high-level interface to dtrtrs\n" );
00203 } else {
00204 printf( "FAILED: row-major high-level interface to dtrtrs\n" );
00205 }
00206
00207
00208 if( a != NULL ) {
00209 LAPACKE_free( a );
00210 }
00211 if( a_i != NULL ) {
00212 LAPACKE_free( a_i );
00213 }
00214 if( a_r != NULL ) {
00215 LAPACKE_free( a_r );
00216 }
00217 if( b != NULL ) {
00218 LAPACKE_free( b );
00219 }
00220 if( b_i != NULL ) {
00221 LAPACKE_free( b_i );
00222 }
00223 if( b_r != NULL ) {
00224 LAPACKE_free( b_r );
00225 }
00226 if( b_save != NULL ) {
00227 LAPACKE_free( b_save );
00228 }
00229
00230 return 0;
00231 }
00232
00233
00234 static void init_scalars_dtrtrs( char *uplo, char *trans, char *diag,
00235 lapack_int *n, lapack_int *nrhs,
00236 lapack_int *lda, lapack_int *ldb )
00237 {
00238 *uplo = 'L';
00239 *trans = 'N';
00240 *diag = 'N';
00241 *n = 4;
00242 *nrhs = 2;
00243 *lda = 8;
00244 *ldb = 8;
00245
00246 return;
00247 }
00248
00249
00250 static void init_a( lapack_int size, double *a ) {
00251 lapack_int i;
00252 for( i = 0; i < size; i++ ) {
00253 a[i] = 0;
00254 }
00255 a[0] = 4.29999999999999980e+000;
00256 a[8] = 0.00000000000000000e+000;
00257 a[16] = 0.00000000000000000e+000;
00258 a[24] = 0.00000000000000000e+000;
00259 a[1] = -3.96000000000000000e+000;
00260 a[9] = -4.87000000000000010e+000;
00261 a[17] = 0.00000000000000000e+000;
00262 a[25] = 0.00000000000000000e+000;
00263 a[2] = 4.00000000000000020e-001;
00264 a[10] = 3.10000000000000000e-001;
00265 a[18] = -8.01999999999999960e+000;
00266 a[26] = 0.00000000000000000e+000;
00267 a[3] = -2.70000000000000020e-001;
00268 a[11] = 7.00000000000000070e-002;
00269 a[19] = -5.95000000000000020e+000;
00270 a[27] = 1.20000000000000000e-001;
00271 }
00272 static void init_b( lapack_int size, double *b ) {
00273 lapack_int i;
00274 for( i = 0; i < size; i++ ) {
00275 b[i] = 0;
00276 }
00277 b[0] = -1.29000000000000000e+001;
00278 b[8] = -2.15000000000000000e+001;
00279 b[1] = 1.67500000000000000e+001;
00280 b[9] = 1.49300000000000000e+001;
00281 b[2] = -1.75500000000000010e+001;
00282 b[10] = 6.33000000000000010e+000;
00283 b[3] = -1.10399999999999990e+001;
00284 b[11] = 8.08999999999999990e+000;
00285 }
00286
00287
00288
00289 static int compare_dtrtrs( double *b, double *b_i, lapack_int info,
00290 lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00291 {
00292 lapack_int i;
00293 int failed = 0;
00294 for( i = 0; i < ldb*nrhs; i++ ) {
00295 failed += compare_doubles(b[i],b_i[i]);
00296 }
00297 failed += (info == info_i) ? 0 : 1;
00298 if( info != 0 || info_i != 0 ) {
00299 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00300 }
00301
00302 return failed;
00303 }