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


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