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


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