dpptri_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 * dpptri_1 is the test program for the C interface to LAPACK
00036 * routine dpptri
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_dpptri( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, double *ap );
00056 static int compare_dpptri( double *ap, double *ap_i, lapack_int info,
00057                            lapack_int info_i, lapack_int n );
00058 
00059 int main(void)
00060 {
00061     /* Local scalars */
00062     char uplo, uplo_i;
00063     lapack_int n, n_i;
00064     lapack_int info, info_i;
00065     lapack_int i;
00066     int failed;
00067 
00068     /* Local arrays */
00069     double *ap = NULL, *ap_i = NULL;
00070     double *ap_save = NULL;
00071     double *ap_r = NULL;
00072 
00073     /* Iniitialize the scalar parameters */
00074     init_scalars_dpptri( &uplo, &n );
00075     uplo_i = uplo;
00076     n_i = n;
00077 
00078     /* Allocate memory for the LAPACK routine arrays */
00079     ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00080 
00081     /* Allocate memory for the C interface function arrays */
00082     ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00083 
00084     /* Allocate memory for the backup arrays */
00085     ap_save = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00086 
00087     /* Allocate memory for the row-major arrays */
00088     ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00089 
00090     /* Initialize input arrays */
00091     init_ap( (n*(n+1)/2), ap );
00092 
00093     /* Backup the ouptut arrays */
00094     for( i = 0; i < (n*(n+1)/2); i++ ) {
00095         ap_save[i] = ap[i];
00096     }
00097 
00098     /* Call the LAPACK routine */
00099     dpptri_( &uplo, &n, ap, &info );
00100 
00101     /* Initialize input data, call the column-major middle-level
00102      * interface to LAPACK routine and check the results */
00103     for( i = 0; i < (n*(n+1)/2); i++ ) {
00104         ap_i[i] = ap_save[i];
00105     }
00106     info_i = LAPACKE_dpptri_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i );
00107 
00108     failed = compare_dpptri( ap, ap_i, info, info_i, n );
00109     if( failed == 0 ) {
00110         printf( "PASSED: column-major middle-level interface to dpptri\n" );
00111     } else {
00112         printf( "FAILED: column-major middle-level interface to dpptri\n" );
00113     }
00114 
00115     /* Initialize input data, call the column-major high-level
00116      * interface to LAPACK routine and check the results */
00117     for( i = 0; i < (n*(n+1)/2); i++ ) {
00118         ap_i[i] = ap_save[i];
00119     }
00120     info_i = LAPACKE_dpptri( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i );
00121 
00122     failed = compare_dpptri( ap, ap_i, info, info_i, n );
00123     if( failed == 0 ) {
00124         printf( "PASSED: column-major high-level interface to dpptri\n" );
00125     } else {
00126         printf( "FAILED: column-major high-level interface to dpptri\n" );
00127     }
00128 
00129     /* Initialize input data, call the row-major middle-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_save[i];
00133     }
00134 
00135     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00136     info_i = LAPACKE_dpptri_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r );
00137 
00138     LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00139 
00140     failed = compare_dpptri( ap, ap_i, info, info_i, n );
00141     if( failed == 0 ) {
00142         printf( "PASSED: row-major middle-level interface to dpptri\n" );
00143     } else {
00144         printf( "FAILED: row-major middle-level interface to dpptri\n" );
00145     }
00146 
00147     /* Initialize input data, call the row-major high-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_save[i];
00151     }
00152 
00153     /* Init row_major arrays */
00154     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00155     info_i = LAPACKE_dpptri( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r );
00156 
00157     LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00158 
00159     failed = compare_dpptri( ap, ap_i, info, info_i, n );
00160     if( failed == 0 ) {
00161         printf( "PASSED: row-major high-level interface to dpptri\n" );
00162     } else {
00163         printf( "FAILED: row-major high-level interface to dpptri\n" );
00164     }
00165 
00166     /* Release memory */
00167     if( ap != NULL ) {
00168         LAPACKE_free( ap );
00169     }
00170     if( ap_i != NULL ) {
00171         LAPACKE_free( ap_i );
00172     }
00173     if( ap_r != NULL ) {
00174         LAPACKE_free( ap_r );
00175     }
00176     if( ap_save != NULL ) {
00177         LAPACKE_free( ap_save );
00178     }
00179 
00180     return 0;
00181 }
00182 
00183 /* Auxiliary function: dpptri scalar parameters initialization */
00184 static void init_scalars_dpptri( char *uplo, lapack_int *n )
00185 {
00186     *uplo = 'L';
00187     *n = 4;
00188 
00189     return;
00190 }
00191 
00192 /* Auxiliary functions: dpptri array parameters initialization */
00193 static void init_ap( lapack_int size, double *ap ) {
00194     lapack_int i;
00195     for( i = 0; i < size; i++ ) {
00196         ap[i] = 0;
00197     }
00198     ap[0] = 2.03960780543711410e+000;
00199     ap[1] = -1.52970585407783540e+000;
00200     ap[2] = 2.74562589193457660e-001;
00201     ap[3] = -4.90290337845460110e-002;
00202     ap[4] = 1.64012194668567270e+000;
00203     ap[5] = -2.49981411948373810e-001;
00204     ap[6] = 6.73730390738910060e-001;
00205     ap[7] = 7.88748805574805310e-001;
00206     ap[8] = 6.61657563374256520e-001;
00207     ap[9] = 5.34689426929868320e-001;
00208 }
00209 
00210 /* Auxiliary function: C interface to dpptri results check */
00211 /* Return value: 0 - test is passed, non-zero - test is failed */
00212 static int compare_dpptri( double *ap, double *ap_i, lapack_int info,
00213                            lapack_int info_i, lapack_int n )
00214 {
00215     lapack_int i;
00216     int failed = 0;
00217     for( i = 0; i < (n*(n+1)/2); i++ ) {
00218         failed += compare_doubles(ap[i],ap_i[i]);
00219     }
00220     failed += (info == info_i) ? 0 : 1;
00221     if( info != 0 || info_i != 0 ) {
00222         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00223     }
00224 
00225     return failed;
00226 }


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