ztbtrs_1.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002   Copyright (c) 2010, Intel Corp.
00003   All rights reserved.
00004 
00005   Redistribution and use in source and binary forms, with or without
00006   modification, are permitted provided that the following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice,
00009       this list of conditions and the following disclaimer.
00010     * Redistributions in binary form must reproduce the above copyright
00011       notice, this list of conditions and the following disclaimer in the
00012       documentation and/or other materials provided with the distribution.
00013     * Neither the name of Intel Corporation nor the names of its contributors
00014       may be used to endorse or promote products derived from this software
00015       without specific prior written permission.
00016 
00017   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00027   THE POSSIBILITY OF SUCH DAMAGE.
00028 *****************************************************************************/
00029 /*  Contents: test routine for C interface to LAPACK
00030 *   Author: Intel Corporation
00031 *   Created in March, 2010
00032 *
00033 * Purpose
00034 *
00035 * ztbtrs_1 is the test program for the C interface to LAPACK
00036 * routine ztbtrs
00037 * The program doesn't require an input, the input data is hardcoded in the
00038 * test program.
00039 * The program tests the C interface in the four combinations:
00040 *   1) column-major layout, middle-level interface
00041 *   2) column-major layout, high-level interface
00042 *   3) row-major layout, middle-level interface
00043 *   4) row-major layout, high-level interface
00044 * The output of the C interface function is compared to those obtained from
00045 * the corresponiding LAPACK routine with the same input data, and the
00046 * comparison diagnostics is then printed on the standard output having PASSED
00047 * keyword if the test is passed, and FAILED keyword if the test isn't passed.
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_ztbtrs( char *uplo, char *trans, char *diag,
00055                                  lapack_int *n, lapack_int *kd,
00056                                  lapack_int *nrhs, lapack_int *ldab,
00057                                  lapack_int *ldb );
00058 static void init_ab( lapack_int size, lapack_complex_double *ab );
00059 static void init_b( lapack_int size, lapack_complex_double *b );
00060 static int compare_ztbtrs( lapack_complex_double *b, lapack_complex_double *b_i,
00061                            lapack_int info, lapack_int info_i, lapack_int ldb,
00062                            lapack_int nrhs );
00063 
00064 int main(void)
00065 {
00066     /* Local scalars */
00067     char uplo, uplo_i;
00068     char trans, trans_i;
00069     char diag, diag_i;
00070     lapack_int n, n_i;
00071     lapack_int kd, kd_i;
00072     lapack_int nrhs, nrhs_i;
00073     lapack_int ldab, ldab_i;
00074     lapack_int ldab_r;
00075     lapack_int ldb, ldb_i;
00076     lapack_int ldb_r;
00077     lapack_int info, info_i;
00078     lapack_int i;
00079     int failed;
00080 
00081     /* Local arrays */
00082     lapack_complex_double *ab = NULL, *ab_i = NULL;
00083     lapack_complex_double *b = NULL, *b_i = NULL;
00084     lapack_complex_double *b_save = NULL;
00085     lapack_complex_double *ab_r = NULL;
00086     lapack_complex_double *b_r = NULL;
00087 
00088     /* Iniitialize the scalar parameters */
00089     init_scalars_ztbtrs( &uplo, &trans, &diag, &n, &kd, &nrhs, &ldab, &ldb );
00090     ldab_r = n+2;
00091     ldb_r = nrhs+2;
00092     uplo_i = uplo;
00093     trans_i = trans;
00094     diag_i = diag;
00095     n_i = n;
00096     kd_i = kd;
00097     nrhs_i = nrhs;
00098     ldab_i = ldab;
00099     ldb_i = ldb;
00100 
00101     /* Allocate memory for the LAPACK routine arrays */
00102     ab = (lapack_complex_double *)
00103         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_double) );
00104     b = (lapack_complex_double *)
00105         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00106 
00107     /* Allocate memory for the C interface function arrays */
00108     ab_i = (lapack_complex_double *)
00109         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_double) );
00110     b_i = (lapack_complex_double *)
00111         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00112 
00113     /* Allocate memory for the backup arrays */
00114     b_save = (lapack_complex_double *)
00115         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00116 
00117     /* Allocate memory for the row-major arrays */
00118     ab_r = (lapack_complex_double *)
00119         LAPACKE_malloc( (kd+1)*(n+2) * sizeof(lapack_complex_double) );
00120     b_r = (lapack_complex_double *)
00121         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00122 
00123     /* Initialize input arrays */
00124     init_ab( ldab*n, ab );
00125     init_b( ldb*nrhs, b );
00126 
00127     /* Backup the ouptut arrays */
00128     for( i = 0; i < ldb*nrhs; i++ ) {
00129         b_save[i] = b[i];
00130     }
00131 
00132     /* Call the LAPACK routine */
00133     ztbtrs_( &uplo, &trans, &diag, &n, &kd, &nrhs, ab, &ldab, b, &ldb, &info );
00134 
00135     /* Initialize input data, call the column-major middle-level
00136      * interface to LAPACK routine and check the results */
00137     for( i = 0; i < ldab*n; i++ ) {
00138         ab_i[i] = ab[i];
00139     }
00140     for( i = 0; i < ldb*nrhs; i++ ) {
00141         b_i[i] = b_save[i];
00142     }
00143     info_i = LAPACKE_ztbtrs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00144                                   n_i, kd_i, nrhs_i, ab_i, ldab_i, b_i, ldb_i );
00145 
00146     failed = compare_ztbtrs( b, b_i, info, info_i, ldb, nrhs );
00147     if( failed == 0 ) {
00148         printf( "PASSED: column-major middle-level interface to ztbtrs\n" );
00149     } else {
00150         printf( "FAILED: column-major middle-level interface to ztbtrs\n" );
00151     }
00152 
00153     /* Initialize input data, call the column-major high-level
00154      * interface to LAPACK routine and check the results */
00155     for( i = 0; i < ldab*n; i++ ) {
00156         ab_i[i] = ab[i];
00157     }
00158     for( i = 0; i < ldb*nrhs; i++ ) {
00159         b_i[i] = b_save[i];
00160     }
00161     info_i = LAPACKE_ztbtrs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00162                              kd_i, nrhs_i, ab_i, ldab_i, b_i, ldb_i );
00163 
00164     failed = compare_ztbtrs( b, b_i, info, info_i, ldb, nrhs );
00165     if( failed == 0 ) {
00166         printf( "PASSED: column-major high-level interface to ztbtrs\n" );
00167     } else {
00168         printf( "FAILED: column-major high-level interface to ztbtrs\n" );
00169     }
00170 
00171     /* Initialize input data, call the row-major middle-level
00172      * interface to LAPACK routine and check the results */
00173     for( i = 0; i < ldab*n; i++ ) {
00174         ab_i[i] = ab[i];
00175     }
00176     for( i = 0; i < ldb*nrhs; i++ ) {
00177         b_i[i] = b_save[i];
00178     }
00179 
00180     LAPACKE_zge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00181     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00182     info_i = LAPACKE_ztbtrs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00183                                   n_i, kd_i, nrhs_i, ab_r, ldab_r, b_r, ldb_r );
00184 
00185     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00186 
00187     failed = compare_ztbtrs( b, b_i, info, info_i, ldb, nrhs );
00188     if( failed == 0 ) {
00189         printf( "PASSED: row-major middle-level interface to ztbtrs\n" );
00190     } else {
00191         printf( "FAILED: row-major middle-level interface to ztbtrs\n" );
00192     }
00193 
00194     /* Initialize input data, call the row-major high-level
00195      * interface to LAPACK routine and check the results */
00196     for( i = 0; i < ldab*n; i++ ) {
00197         ab_i[i] = ab[i];
00198     }
00199     for( i = 0; i < ldb*nrhs; i++ ) {
00200         b_i[i] = b_save[i];
00201     }
00202 
00203     /* Init row_major arrays */
00204     LAPACKE_zge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00205     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00206     info_i = LAPACKE_ztbtrs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00207                              kd_i, nrhs_i, ab_r, ldab_r, b_r, ldb_r );
00208 
00209     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00210 
00211     failed = compare_ztbtrs( b, b_i, info, info_i, ldb, nrhs );
00212     if( failed == 0 ) {
00213         printf( "PASSED: row-major high-level interface to ztbtrs\n" );
00214     } else {
00215         printf( "FAILED: row-major high-level interface to ztbtrs\n" );
00216     }
00217 
00218     /* Release memory */
00219     if( ab != NULL ) {
00220         LAPACKE_free( ab );
00221     }
00222     if( ab_i != NULL ) {
00223         LAPACKE_free( ab_i );
00224     }
00225     if( ab_r != NULL ) {
00226         LAPACKE_free( ab_r );
00227     }
00228     if( b != NULL ) {
00229         LAPACKE_free( b );
00230     }
00231     if( b_i != NULL ) {
00232         LAPACKE_free( b_i );
00233     }
00234     if( b_r != NULL ) {
00235         LAPACKE_free( b_r );
00236     }
00237     if( b_save != NULL ) {
00238         LAPACKE_free( b_save );
00239     }
00240 
00241     return 0;
00242 }
00243 
00244 /* Auxiliary function: ztbtrs scalar parameters initialization */
00245 static void init_scalars_ztbtrs( char *uplo, char *trans, char *diag,
00246                                  lapack_int *n, lapack_int *kd,
00247                                  lapack_int *nrhs, lapack_int *ldab,
00248                                  lapack_int *ldb )
00249 {
00250     *uplo = 'L';
00251     *trans = 'N';
00252     *diag = 'N';
00253     *n = 4;
00254     *kd = 2;
00255     *nrhs = 2;
00256     *ldab = 9;
00257     *ldb = 8;
00258 
00259     return;
00260 }
00261 
00262 /* Auxiliary functions: ztbtrs array parameters initialization */
00263 static void init_ab( lapack_int size, lapack_complex_double *ab ) {
00264     lapack_int i;
00265     for( i = 0; i < size; i++ ) {
00266         ab[i] = lapack_make_complex_double( 0.0, 0.0 );
00267     }
00268     ab[0] = lapack_make_complex_double( -1.93999999999999990e+000,
00269                                         4.42999999999999970e+000 );
00270     ab[9] = lapack_make_complex_double( 4.12000000000000010e+000,
00271                                         -4.26999999999999960e+000 );
00272     ab[18] = lapack_make_complex_double( 4.29999999999999990e-001,
00273                                          -2.66000000000000010e+000 );
00274     ab[27] = lapack_make_complex_double( 4.40000000000000000e-001,
00275                                          1.00000000000000010e-001 );
00276     ab[1] = lapack_make_complex_double( -3.39000000000000010e+000,
00277                                         3.43999999999999990e+000 );
00278     ab[10] = lapack_make_complex_double( -1.84000000000000010e+000,
00279                                          5.53000000000000020e+000 );
00280     ab[19] = lapack_make_complex_double( 1.74000000000000000e+000,
00281                                          -4.00000000000000010e-002 );
00282     ab[28] = lapack_make_complex_double( 0.00000000000000000e+000,
00283                                          0.00000000000000000e+000 );
00284     ab[2] = lapack_make_complex_double( 1.62000000000000010e+000,
00285                                         3.68000000000000020e+000 );
00286     ab[11] = lapack_make_complex_double( -2.77000000000000000e+000,
00287                                          -1.92999999999999990e+000 );
00288     ab[20] = lapack_make_complex_double( 0.00000000000000000e+000,
00289                                          0.00000000000000000e+000 );
00290     ab[29] = lapack_make_complex_double( 0.00000000000000000e+000,
00291                                          0.00000000000000000e+000 );
00292 }
00293 static void init_b( lapack_int size, lapack_complex_double *b ) {
00294     lapack_int i;
00295     for( i = 0; i < size; i++ ) {
00296         b[i] = lapack_make_complex_double( 0.0, 0.0 );
00297     }
00298     b[0] = lapack_make_complex_double( -8.85999999999999940e+000,
00299                                        -3.87999999999999990e+000 );
00300     b[8] = lapack_make_complex_double( -2.40900000000000000e+001,
00301                                        -5.26999999999999960e+000 );
00302     b[1] = lapack_make_complex_double( -1.55700000000000000e+001,
00303                                        -2.34100000000000000e+001 );
00304     b[9] = lapack_make_complex_double( -5.79699999999999990e+001,
00305                                        8.14000000000000060e+000 );
00306     b[2] = lapack_make_complex_double( -7.62999999999999990e+000,
00307                                        2.27800000000000010e+001 );
00308     b[10] = lapack_make_complex_double( 1.90900000000000000e+001,
00309                                         -2.95100000000000020e+001 );
00310     b[3] = lapack_make_complex_double( -1.47400000000000000e+001,
00311                                        -2.39999999999999990e+000 );
00312     b[11] = lapack_make_complex_double( 1.91700000000000020e+001,
00313                                         2.13299999999999980e+001 );
00314 }
00315 
00316 /* Auxiliary function: C interface to ztbtrs results check */
00317 /* Return value: 0 - test is passed, non-zero - test is failed */
00318 static int compare_ztbtrs( lapack_complex_double *b, lapack_complex_double *b_i,
00319                            lapack_int info, lapack_int info_i, lapack_int ldb,
00320                            lapack_int nrhs )
00321 {
00322     lapack_int i;
00323     int failed = 0;
00324     for( i = 0; i < ldb*nrhs; i++ ) {
00325         failed += compare_complex_doubles(b[i],b_i[i]);
00326     }
00327     failed += (info == info_i) ? 0 : 1;
00328     if( info != 0 || info_i != 0 ) {
00329         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00330     }
00331 
00332     return failed;
00333 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:43