dppcon_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 * dppcon_1 is the test program for the C interface to LAPACK
00036 * routine dppcon
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_dppcon( char *uplo, lapack_int *n, double *anorm );
00055 static void init_ap( lapack_int size, double *ap );
00056 static void init_work( lapack_int size, double *work );
00057 static void init_iwork( lapack_int size, lapack_int *iwork );
00058 static int compare_dppcon( double rcond, double rcond_i, lapack_int info,
00059                            lapack_int info_i );
00060 
00061 int main(void)
00062 {
00063     /* Local scalars */
00064     char uplo, uplo_i;
00065     lapack_int n, n_i;
00066     double anorm, anorm_i;
00067     double rcond, rcond_i;
00068     lapack_int info, info_i;
00069     lapack_int i;
00070     int failed;
00071 
00072     /* Local arrays */
00073     double *ap = NULL, *ap_i = NULL;
00074     double *work = NULL, *work_i = NULL;
00075     lapack_int *iwork = NULL, *iwork_i = NULL;
00076     double *ap_r = NULL;
00077 
00078     /* Iniitialize the scalar parameters */
00079     init_scalars_dppcon( &uplo, &n, &anorm );
00080     uplo_i = uplo;
00081     n_i = n;
00082     anorm_i = anorm;
00083 
00084     /* Allocate memory for the LAPACK routine arrays */
00085     ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00086     work = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00087     iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00088 
00089     /* Allocate memory for the C interface function arrays */
00090     ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00091     work_i = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00092     iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00093 
00094     /* Allocate memory for the row-major arrays */
00095     ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00096 
00097     /* Initialize input arrays */
00098     init_ap( (n*(n+1)/2), ap );
00099     init_work( 3*n, work );
00100     init_iwork( n, iwork );
00101 
00102     /* Call the LAPACK routine */
00103     dppcon_( &uplo, &n, ap, &anorm, &rcond, work, iwork, &info );
00104 
00105     /* Initialize input data, call the column-major middle-level
00106      * interface to LAPACK routine and check the results */
00107     for( i = 0; i < (n*(n+1)/2); i++ ) {
00108         ap_i[i] = ap[i];
00109     }
00110     for( i = 0; i < 3*n; i++ ) {
00111         work_i[i] = work[i];
00112     }
00113     for( i = 0; i < n; i++ ) {
00114         iwork_i[i] = iwork[i];
00115     }
00116     info_i = LAPACKE_dppcon_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, anorm_i,
00117                                   &rcond_i, work_i, iwork_i );
00118 
00119     failed = compare_dppcon( rcond, rcond_i, info, info_i );
00120     if( failed == 0 ) {
00121         printf( "PASSED: column-major middle-level interface to dppcon\n" );
00122     } else {
00123         printf( "FAILED: column-major middle-level interface to dppcon\n" );
00124     }
00125 
00126     /* Initialize input data, call the column-major high-level
00127      * interface to LAPACK routine and check the results */
00128     for( i = 0; i < (n*(n+1)/2); i++ ) {
00129         ap_i[i] = ap[i];
00130     }
00131     for( i = 0; i < 3*n; i++ ) {
00132         work_i[i] = work[i];
00133     }
00134     for( i = 0; i < n; i++ ) {
00135         iwork_i[i] = iwork[i];
00136     }
00137     info_i = LAPACKE_dppcon( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, anorm_i,
00138                              &rcond_i );
00139 
00140     failed = compare_dppcon( rcond, rcond_i, info, info_i );
00141     if( failed == 0 ) {
00142         printf( "PASSED: column-major high-level interface to dppcon\n" );
00143     } else {
00144         printf( "FAILED: column-major high-level interface to dppcon\n" );
00145     }
00146 
00147     /* Initialize input data, call the row-major middle-level
00148      * interface to LAPACK routine and check the results */
00149     for( i = 0; i < (n*(n+1)/2); i++ ) {
00150         ap_i[i] = ap[i];
00151     }
00152     for( i = 0; i < 3*n; i++ ) {
00153         work_i[i] = work[i];
00154     }
00155     for( i = 0; i < n; i++ ) {
00156         iwork_i[i] = iwork[i];
00157     }
00158 
00159     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00160     info_i = LAPACKE_dppcon_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, anorm_i,
00161                                   &rcond_i, work_i, iwork_i );
00162 
00163     failed = compare_dppcon( rcond, rcond_i, info, info_i );
00164     if( failed == 0 ) {
00165         printf( "PASSED: row-major middle-level interface to dppcon\n" );
00166     } else {
00167         printf( "FAILED: row-major middle-level interface to dppcon\n" );
00168     }
00169 
00170     /* Initialize input data, call the row-major high-level
00171      * interface to LAPACK routine and check the results */
00172     for( i = 0; i < (n*(n+1)/2); i++ ) {
00173         ap_i[i] = ap[i];
00174     }
00175     for( i = 0; i < 3*n; i++ ) {
00176         work_i[i] = work[i];
00177     }
00178     for( i = 0; i < n; i++ ) {
00179         iwork_i[i] = iwork[i];
00180     }
00181 
00182     /* Init row_major arrays */
00183     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00184     info_i = LAPACKE_dppcon( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, anorm_i,
00185                              &rcond_i );
00186 
00187     failed = compare_dppcon( rcond, rcond_i, info, info_i );
00188     if( failed == 0 ) {
00189         printf( "PASSED: row-major high-level interface to dppcon\n" );
00190     } else {
00191         printf( "FAILED: row-major high-level interface to dppcon\n" );
00192     }
00193 
00194     /* Release memory */
00195     if( ap != NULL ) {
00196         LAPACKE_free( ap );
00197     }
00198     if( ap_i != NULL ) {
00199         LAPACKE_free( ap_i );
00200     }
00201     if( ap_r != NULL ) {
00202         LAPACKE_free( ap_r );
00203     }
00204     if( work != NULL ) {
00205         LAPACKE_free( work );
00206     }
00207     if( work_i != NULL ) {
00208         LAPACKE_free( work_i );
00209     }
00210     if( iwork != NULL ) {
00211         LAPACKE_free( iwork );
00212     }
00213     if( iwork_i != NULL ) {
00214         LAPACKE_free( iwork_i );
00215     }
00216 
00217     return 0;
00218 }
00219 
00220 /* Auxiliary function: dppcon scalar parameters initialization */
00221 static void init_scalars_dppcon( char *uplo, lapack_int *n, double *anorm )
00222 {
00223     *uplo = 'L';
00224     *n = 4;
00225     *anorm = 1.01600000000000000e+001;
00226 
00227     return;
00228 }
00229 
00230 /* Auxiliary functions: dppcon array parameters initialization */
00231 static void init_ap( lapack_int size, double *ap ) {
00232     lapack_int i;
00233     for( i = 0; i < size; i++ ) {
00234         ap[i] = 0;
00235     }
00236     ap[0] = 2.03960780543711410e+000;
00237     ap[1] = -1.52970585407783540e+000;
00238     ap[2] = 2.74562589193457660e-001;
00239     ap[3] = -4.90290337845460110e-002;
00240     ap[4] = 1.64012194668567270e+000;
00241     ap[5] = -2.49981411948373810e-001;
00242     ap[6] = 6.73730390738910060e-001;
00243     ap[7] = 7.88748805574805310e-001;
00244     ap[8] = 6.61657563374256520e-001;
00245     ap[9] = 5.34689426929868320e-001;
00246 }
00247 static void init_work( lapack_int size, double *work ) {
00248     lapack_int i;
00249     for( i = 0; i < size; i++ ) {
00250         work[i] = 0;
00251     }
00252 }
00253 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00254     lapack_int i;
00255     for( i = 0; i < size; i++ ) {
00256         iwork[i] = 0;
00257     }
00258 }
00259 
00260 /* Auxiliary function: C interface to dppcon results check */
00261 /* Return value: 0 - test is passed, non-zero - test is failed */
00262 static int compare_dppcon( double rcond, double rcond_i, lapack_int info,
00263                            lapack_int info_i )
00264 {
00265     int failed = 0;
00266     failed += compare_doubles(rcond,rcond_i);
00267     failed += (info == info_i) ? 0 : 1;
00268     if( info != 0 || info_i != 0 ) {
00269         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00270     }
00271 
00272     return failed;
00273 }


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