dsptrf_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 * dsptrf_1 is the test program for the C interface to LAPACK
00036 * routine dsptrf
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_dsptrf( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, double *ap );
00056 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00057 static int compare_dsptrf( double *ap, double *ap_i, lapack_int *ipiv,
00058                            lapack_int *ipiv_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     double *ap = NULL, *ap_i = NULL;
00072     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00073     double *ap_save = NULL;
00074     lapack_int *ipiv_save = NULL;
00075     double *ap_r = NULL;
00076 
00077     /* Iniitialize the scalar parameters */
00078     init_scalars_dsptrf( &uplo, &n );
00079     uplo_i = uplo;
00080     n_i = n;
00081 
00082     /* Allocate memory for the LAPACK routine arrays */
00083     ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00084     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00085 
00086     /* Allocate memory for the C interface function arrays */
00087     ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00088     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00089 
00090     /* Allocate memory for the backup arrays */
00091     ap_save = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00092     ipiv_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00093 
00094     /* Allocate memory for the row-major arrays */
00095     ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00096 
00097     /* Initialize input arrays */
00098     init_ap( (n*(n+1)/2), ap );
00099     init_ipiv( n, ipiv );
00100 
00101     /* Backup the ouptut arrays */
00102     for( i = 0; i < (n*(n+1)/2); i++ ) {
00103         ap_save[i] = ap[i];
00104     }
00105     for( i = 0; i < n; i++ ) {
00106         ipiv_save[i] = ipiv[i];
00107     }
00108 
00109     /* Call the LAPACK routine */
00110     dsptrf_( &uplo, &n, ap, ipiv, &info );
00111 
00112     /* Initialize input data, call the column-major middle-level
00113      * interface to LAPACK routine and check the results */
00114     for( i = 0; i < (n*(n+1)/2); i++ ) {
00115         ap_i[i] = ap_save[i];
00116     }
00117     for( i = 0; i < n; i++ ) {
00118         ipiv_i[i] = ipiv_save[i];
00119     }
00120     info_i = LAPACKE_dsptrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00121 
00122     failed = compare_dsptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00123     if( failed == 0 ) {
00124         printf( "PASSED: column-major middle-level interface to dsptrf\n" );
00125     } else {
00126         printf( "FAILED: column-major middle-level interface to dsptrf\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_save[i];
00133     }
00134     for( i = 0; i < n; i++ ) {
00135         ipiv_i[i] = ipiv_save[i];
00136     }
00137     info_i = LAPACKE_dsptrf( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, ipiv_i );
00138 
00139     failed = compare_dsptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00140     if( failed == 0 ) {
00141         printf( "PASSED: column-major high-level interface to dsptrf\n" );
00142     } else {
00143         printf( "FAILED: column-major high-level interface to dsptrf\n" );
00144     }
00145 
00146     /* Initialize input data, call the row-major middle-level
00147      * interface to LAPACK routine and check the results */
00148     for( i = 0; i < (n*(n+1)/2); i++ ) {
00149         ap_i[i] = ap_save[i];
00150     }
00151     for( i = 0; i < n; i++ ) {
00152         ipiv_i[i] = ipiv_save[i];
00153     }
00154 
00155     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00156     info_i = LAPACKE_dsptrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00157 
00158     LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00159 
00160     failed = compare_dsptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00161     if( failed == 0 ) {
00162         printf( "PASSED: row-major middle-level interface to dsptrf\n" );
00163     } else {
00164         printf( "FAILED: row-major middle-level interface to dsptrf\n" );
00165     }
00166 
00167     /* Initialize input data, call the row-major high-level
00168      * interface to LAPACK routine and check the results */
00169     for( i = 0; i < (n*(n+1)/2); i++ ) {
00170         ap_i[i] = ap_save[i];
00171     }
00172     for( i = 0; i < n; i++ ) {
00173         ipiv_i[i] = ipiv_save[i];
00174     }
00175 
00176     /* Init row_major arrays */
00177     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00178     info_i = LAPACKE_dsptrf( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, ipiv_i );
00179 
00180     LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00181 
00182     failed = compare_dsptrf( ap, ap_i, ipiv, ipiv_i, info, info_i, n );
00183     if( failed == 0 ) {
00184         printf( "PASSED: row-major high-level interface to dsptrf\n" );
00185     } else {
00186         printf( "FAILED: row-major high-level interface to dsptrf\n" );
00187     }
00188 
00189     /* Release memory */
00190     if( ap != NULL ) {
00191         LAPACKE_free( ap );
00192     }
00193     if( ap_i != NULL ) {
00194         LAPACKE_free( ap_i );
00195     }
00196     if( ap_r != NULL ) {
00197         LAPACKE_free( ap_r );
00198     }
00199     if( ap_save != NULL ) {
00200         LAPACKE_free( ap_save );
00201     }
00202     if( ipiv != NULL ) {
00203         LAPACKE_free( ipiv );
00204     }
00205     if( ipiv_i != NULL ) {
00206         LAPACKE_free( ipiv_i );
00207     }
00208     if( ipiv_save != NULL ) {
00209         LAPACKE_free( ipiv_save );
00210     }
00211 
00212     return 0;
00213 }
00214 
00215 /* Auxiliary function: dsptrf scalar parameters initialization */
00216 static void init_scalars_dsptrf( char *uplo, lapack_int *n )
00217 {
00218     *uplo = 'L';
00219     *n = 4;
00220 
00221     return;
00222 }
00223 
00224 /* Auxiliary functions: dsptrf array parameters initialization */
00225 static void init_ap( lapack_int size, double *ap ) {
00226     lapack_int i;
00227     for( i = 0; i < size; i++ ) {
00228         ap[i] = 0;
00229     }
00230     ap[0] = 2.06999999999999980e+000;
00231     ap[1] = 3.87000000000000010e+000;
00232     ap[2] = 4.20000000000000020e+000;
00233     ap[3] = -1.14999999999999990e+000;
00234     ap[4] = -2.09999999999999990e-001;
00235     ap[5] = 1.87000000000000010e+000;
00236     ap[6] = 6.30000000000000000e-001;
00237     ap[7] = 1.14999999999999990e+000;
00238     ap[8] = 2.06000000000000010e+000;
00239     ap[9] = -1.81000000000000010e+000;
00240 }
00241 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00242     lapack_int i;
00243     for( i = 0; i < size; i++ ) {
00244         ipiv[i] = 0;
00245     }
00246 }
00247 
00248 /* Auxiliary function: C interface to dsptrf results check */
00249 /* Return value: 0 - test is passed, non-zero - test is failed */
00250 static int compare_dsptrf( double *ap, double *ap_i, lapack_int *ipiv,
00251                            lapack_int *ipiv_i, lapack_int info,
00252                            lapack_int info_i, lapack_int n )
00253 {
00254     lapack_int i;
00255     int failed = 0;
00256     for( i = 0; i < (n*(n+1)/2); i++ ) {
00257         failed += compare_doubles(ap[i],ap_i[i]);
00258     }
00259     for( i = 0; i < n; i++ ) {
00260         failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00261     }
00262     failed += (info == info_i) ? 0 : 1;
00263     if( info != 0 || info_i != 0 ) {
00264         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00265     }
00266 
00267     return failed;
00268 }


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