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


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