ctbtrs_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 * ctbtrs_1 is the test program for the C interface to LAPACK
00036 * routine ctbtrs
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_ctbtrs( 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_float *ab );
00059 static void init_b( lapack_int size, lapack_complex_float *b );
00060 static int compare_ctbtrs( lapack_complex_float *b, lapack_complex_float *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_float *ab = NULL, *ab_i = NULL;
00083     lapack_complex_float *b = NULL, *b_i = NULL;
00084     lapack_complex_float *b_save = NULL;
00085     lapack_complex_float *ab_r = NULL;
00086     lapack_complex_float *b_r = NULL;
00087 
00088     /* Iniitialize the scalar parameters */
00089     init_scalars_ctbtrs( &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_float *)
00103         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00104     b = (lapack_complex_float *)
00105         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00106 
00107     /* Allocate memory for the C interface function arrays */
00108     ab_i = (lapack_complex_float *)
00109         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00110     b_i = (lapack_complex_float *)
00111         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00112 
00113     /* Allocate memory for the backup arrays */
00114     b_save = (lapack_complex_float *)
00115         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00116 
00117     /* Allocate memory for the row-major arrays */
00118     ab_r = (lapack_complex_float *)
00119         LAPACKE_malloc( (kd+1)*(n+2) * sizeof(lapack_complex_float) );
00120     b_r = (lapack_complex_float *)
00121         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_float) );
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     ctbtrs_( &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_ctbtrs_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_ctbtrs( b, b_i, info, info_i, ldb, nrhs );
00147     if( failed == 0 ) {
00148         printf( "PASSED: column-major middle-level interface to ctbtrs\n" );
00149     } else {
00150         printf( "FAILED: column-major middle-level interface to ctbtrs\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_ctbtrs( 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_ctbtrs( b, b_i, info, info_i, ldb, nrhs );
00165     if( failed == 0 ) {
00166         printf( "PASSED: column-major high-level interface to ctbtrs\n" );
00167     } else {
00168         printf( "FAILED: column-major high-level interface to ctbtrs\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_cge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00181     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00182     info_i = LAPACKE_ctbtrs_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_cge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00186 
00187     failed = compare_ctbtrs( b, b_i, info, info_i, ldb, nrhs );
00188     if( failed == 0 ) {
00189         printf( "PASSED: row-major middle-level interface to ctbtrs\n" );
00190     } else {
00191         printf( "FAILED: row-major middle-level interface to ctbtrs\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_cge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00205     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00206     info_i = LAPACKE_ctbtrs( 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_cge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00210 
00211     failed = compare_ctbtrs( b, b_i, info, info_i, ldb, nrhs );
00212     if( failed == 0 ) {
00213         printf( "PASSED: row-major high-level interface to ctbtrs\n" );
00214     } else {
00215         printf( "FAILED: row-major high-level interface to ctbtrs\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: ctbtrs scalar parameters initialization */
00245 static void init_scalars_ctbtrs( 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: ctbtrs array parameters initialization */
00263 static void init_ab( lapack_int size, lapack_complex_float *ab ) {
00264     lapack_int i;
00265     for( i = 0; i < size; i++ ) {
00266         ab[i] = lapack_make_complex_float( 0.0f, 0.0f );
00267     }
00268     ab[0] = lapack_make_complex_float( -1.940000057e+000, 4.429999828e+000 );
00269     ab[9] = lapack_make_complex_float( 4.119999886e+000, -4.269999981e+000 );
00270     ab[18] = lapack_make_complex_float( 4.300000072e-001, -2.660000086e+000 );
00271     ab[27] = lapack_make_complex_float( 4.399999976e-001, 1.000000015e-001 );
00272     ab[1] = lapack_make_complex_float( -3.390000105e+000, 3.440000057e+000 );
00273     ab[10] = lapack_make_complex_float( -1.840000033e+000, 5.530000210e+000 );
00274     ab[19] = lapack_make_complex_float( 1.740000010e+000, -3.999999911e-002 );
00275     ab[28] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00276     ab[2] = lapack_make_complex_float( 1.620000005e+000, 3.680000067e+000 );
00277     ab[11] = lapack_make_complex_float( -2.769999981e+000, -1.929999948e+000 );
00278     ab[20] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00279     ab[29] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00280 }
00281 static void init_b( lapack_int size, lapack_complex_float *b ) {
00282     lapack_int i;
00283     for( i = 0; i < size; i++ ) {
00284         b[i] = lapack_make_complex_float( 0.0f, 0.0f );
00285     }
00286     b[0] = lapack_make_complex_float( -8.859999657e+000, -3.880000114e+000 );
00287     b[8] = lapack_make_complex_float( -2.409000015e+001, -5.269999981e+000 );
00288     b[1] = lapack_make_complex_float( -1.556999969e+001, -2.340999985e+001 );
00289     b[9] = lapack_make_complex_float( -5.797000122e+001, 8.140000343e+000 );
00290     b[2] = lapack_make_complex_float( -7.630000114e+000, 2.278000069e+001 );
00291     b[10] = lapack_make_complex_float( 1.909000015e+001, -2.951000023e+001 );
00292     b[3] = lapack_make_complex_float( -1.473999977e+001, -2.400000095e+000 );
00293     b[11] = lapack_make_complex_float( 1.917000008e+001, 2.132999992e+001 );
00294 }
00295 
00296 /* Auxiliary function: C interface to ctbtrs results check */
00297 /* Return value: 0 - test is passed, non-zero - test is failed */
00298 static int compare_ctbtrs( lapack_complex_float *b, lapack_complex_float *b_i,
00299                            lapack_int info, lapack_int info_i, lapack_int ldb,
00300                            lapack_int nrhs )
00301 {
00302     lapack_int i;
00303     int failed = 0;
00304     for( i = 0; i < ldb*nrhs; i++ ) {
00305         failed += compare_complex_floats(b[i],b_i[i]);
00306     }
00307     failed += (info == info_i) ? 0 : 1;
00308     if( info != 0 || info_i != 0 ) {
00309         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00310     }
00311 
00312     return failed;
00313 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:34