spotri_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 * spotri_1 is the test program for the C interface to LAPACK
00036 * routine spotri
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_spotri( char *uplo, lapack_int *n, lapack_int *lda );
00055 static void init_a( lapack_int size, float *a );
00056 static int compare_spotri( float *a, float *a_i, lapack_int info,
00057                            lapack_int info_i, lapack_int lda, 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 lda, lda_i;
00065     lapack_int lda_r;
00066     lapack_int info, info_i;
00067     lapack_int i;
00068     int failed;
00069 
00070     /* Local arrays */
00071     float *a = NULL, *a_i = NULL;
00072     float *a_save = NULL;
00073     float *a_r = NULL;
00074 
00075     /* Iniitialize the scalar parameters */
00076     init_scalars_spotri( &uplo, &n, &lda );
00077     lda_r = n+2;
00078     uplo_i = uplo;
00079     n_i = n;
00080     lda_i = lda;
00081 
00082     /* Allocate memory for the LAPACK routine arrays */
00083     a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00084 
00085     /* Allocate memory for the C interface function arrays */
00086     a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00087 
00088     /* Allocate memory for the backup arrays */
00089     a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00090 
00091     /* Allocate memory for the row-major arrays */
00092     a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00093 
00094     /* Initialize input arrays */
00095     init_a( lda*n, a );
00096 
00097     /* Backup the ouptut arrays */
00098     for( i = 0; i < lda*n; i++ ) {
00099         a_save[i] = a[i];
00100     }
00101 
00102     /* Call the LAPACK routine */
00103     spotri_( &uplo, &n, a, &lda, &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 < lda*n; i++ ) {
00108         a_i[i] = a_save[i];
00109     }
00110     info_i = LAPACKE_spotri_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i );
00111 
00112     failed = compare_spotri( a, a_i, info, info_i, lda, n );
00113     if( failed == 0 ) {
00114         printf( "PASSED: column-major middle-level interface to spotri\n" );
00115     } else {
00116         printf( "FAILED: column-major middle-level interface to spotri\n" );
00117     }
00118 
00119     /* Initialize input data, call the column-major high-level
00120      * interface to LAPACK routine and check the results */
00121     for( i = 0; i < lda*n; i++ ) {
00122         a_i[i] = a_save[i];
00123     }
00124     info_i = LAPACKE_spotri( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i );
00125 
00126     failed = compare_spotri( a, a_i, info, info_i, lda, n );
00127     if( failed == 0 ) {
00128         printf( "PASSED: column-major high-level interface to spotri\n" );
00129     } else {
00130         printf( "FAILED: column-major high-level interface to spotri\n" );
00131     }
00132 
00133     /* Initialize input data, call the row-major middle-level
00134      * interface to LAPACK routine and check the results */
00135     for( i = 0; i < lda*n; i++ ) {
00136         a_i[i] = a_save[i];
00137     }
00138 
00139     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00140     info_i = LAPACKE_spotri_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r );
00141 
00142     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00143 
00144     failed = compare_spotri( a, a_i, info, info_i, lda, n );
00145     if( failed == 0 ) {
00146         printf( "PASSED: row-major middle-level interface to spotri\n" );
00147     } else {
00148         printf( "FAILED: row-major middle-level interface to spotri\n" );
00149     }
00150 
00151     /* Initialize input data, call the row-major high-level
00152      * interface to LAPACK routine and check the results */
00153     for( i = 0; i < lda*n; i++ ) {
00154         a_i[i] = a_save[i];
00155     }
00156 
00157     /* Init row_major arrays */
00158     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00159     info_i = LAPACKE_spotri( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r );
00160 
00161     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00162 
00163     failed = compare_spotri( a, a_i, info, info_i, lda, n );
00164     if( failed == 0 ) {
00165         printf( "PASSED: row-major high-level interface to spotri\n" );
00166     } else {
00167         printf( "FAILED: row-major high-level interface to spotri\n" );
00168     }
00169 
00170     /* Release memory */
00171     if( a != NULL ) {
00172         LAPACKE_free( a );
00173     }
00174     if( a_i != NULL ) {
00175         LAPACKE_free( a_i );
00176     }
00177     if( a_r != NULL ) {
00178         LAPACKE_free( a_r );
00179     }
00180     if( a_save != NULL ) {
00181         LAPACKE_free( a_save );
00182     }
00183 
00184     return 0;
00185 }
00186 
00187 /* Auxiliary function: spotri scalar parameters initialization */
00188 static void init_scalars_spotri( char *uplo, lapack_int *n, lapack_int *lda )
00189 {
00190     *uplo = 'L';
00191     *n = 4;
00192     *lda = 8;
00193 
00194     return;
00195 }
00196 
00197 /* Auxiliary functions: spotri array parameters initialization */
00198 static void init_a( lapack_int size, float *a ) {
00199     lapack_int i;
00200     for( i = 0; i < size; i++ ) {
00201         a[i] = 0;
00202     }
00203     a[0] = 2.039607763e+000;  /* a[0,0] */
00204     a[8] = 0.000000000e+000;  /* a[0,1] */
00205     a[16] = 0.000000000e+000;  /* a[0,2] */
00206     a[24] = 0.000000000e+000;  /* a[0,3] */
00207     a[1] = -1.529705763e+000;  /* a[1,0] */
00208     a[9] = 1.640122056e+000;  /* a[1,1] */
00209     a[17] = 0.000000000e+000;  /* a[1,2] */
00210     a[25] = 0.000000000e+000;  /* a[1,3] */
00211     a[2] = 2.745625973e-001;  /* a[2,0] */
00212     a[10] = -2.499813884e-001;  /* a[2,1] */
00213     a[18] = 7.887488008e-001;  /* a[2,2] */
00214     a[26] = 0.000000000e+000;  /* a[2,3] */
00215     a[3] = -4.902903363e-002;  /* a[3,0] */
00216     a[11] = 6.737302542e-001;  /* a[3,1] */
00217     a[19] = 6.616575122e-001;  /* a[3,2] */
00218     a[27] = 5.346896052e-001;  /* a[3,3] */
00219 }
00220 
00221 /* Auxiliary function: C interface to spotri results check */
00222 /* Return value: 0 - test is passed, non-zero - test is failed */
00223 static int compare_spotri( float *a, float *a_i, lapack_int info,
00224                            lapack_int info_i, lapack_int lda, lapack_int n )
00225 {
00226     lapack_int i;
00227     int failed = 0;
00228     for( i = 0; i < lda*n; i++ ) {
00229         failed += compare_floats(a[i],a_i[i]);
00230     }
00231     failed += (info == info_i) ? 0 : 1;
00232     if( info != 0 || info_i != 0 ) {
00233         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00234     }
00235 
00236     return failed;
00237 }


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