dspgst_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 * dspgst_1 is the test program for the C interface to LAPACK
00036 * routine dspgst
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_dspgst( lapack_int *itype, char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, double *ap );
00056 static void init_bp( lapack_int size, double *bp );
00057 static int compare_dspgst( double *ap, double *ap_i, lapack_int info,
00058                            lapack_int info_i, lapack_int n );
00059 
00060 int main(void)
00061 {
00062     /* Local scalars */
00063     lapack_int itype, itype_i;
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     double *bp = NULL, *bp_i = NULL;
00073     double *ap_save = NULL;
00074     double *ap_r = NULL;
00075     double *bp_r = NULL;
00076 
00077     /* Iniitialize the scalar parameters */
00078     init_scalars_dspgst( &itype, &uplo, &n );
00079     itype_i = itype;
00080     uplo_i = uplo;
00081     n_i = n;
00082 
00083     /* Allocate memory for the LAPACK routine arrays */
00084     ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00085     bp = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00086 
00087     /* Allocate memory for the C interface function arrays */
00088     ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00089     bp_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00090 
00091     /* Allocate memory for the backup arrays */
00092     ap_save = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00093 
00094     /* Allocate memory for the row-major arrays */
00095     ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00096     bp_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00097 
00098     /* Initialize input arrays */
00099     init_ap( (n*(n+1)/2), ap );
00100     init_bp( (n*(n+1)/2), bp );
00101 
00102     /* Backup the ouptut arrays */
00103     for( i = 0; i < (n*(n+1)/2); i++ ) {
00104         ap_save[i] = ap[i];
00105     }
00106 
00107     /* Call the LAPACK routine */
00108     dspgst_( &itype, &uplo, &n, ap, bp, &info );
00109 
00110     /* Initialize input data, call the column-major middle-level
00111      * interface to LAPACK routine and check the results */
00112     for( i = 0; i < (n*(n+1)/2); i++ ) {
00113         ap_i[i] = ap_save[i];
00114     }
00115     for( i = 0; i < (n*(n+1)/2); i++ ) {
00116         bp_i[i] = bp[i];
00117     }
00118     info_i = LAPACKE_dspgst_work( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, ap_i,
00119                                   bp_i );
00120 
00121     failed = compare_dspgst( ap, ap_i, info, info_i, n );
00122     if( failed == 0 ) {
00123         printf( "PASSED: column-major middle-level interface to dspgst\n" );
00124     } else {
00125         printf( "FAILED: column-major middle-level interface to dspgst\n" );
00126     }
00127 
00128     /* Initialize input data, call the column-major high-level
00129      * interface to LAPACK routine and check the results */
00130     for( i = 0; i < (n*(n+1)/2); i++ ) {
00131         ap_i[i] = ap_save[i];
00132     }
00133     for( i = 0; i < (n*(n+1)/2); i++ ) {
00134         bp_i[i] = bp[i];
00135     }
00136     info_i = LAPACKE_dspgst( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, ap_i,
00137                              bp_i );
00138 
00139     failed = compare_dspgst( ap, ap_i, info, info_i, n );
00140     if( failed == 0 ) {
00141         printf( "PASSED: column-major high-level interface to dspgst\n" );
00142     } else {
00143         printf( "FAILED: column-major high-level interface to dspgst\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*(n+1)/2); i++ ) {
00152         bp_i[i] = bp[i];
00153     }
00154 
00155     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00156     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, bp_i, bp_r );
00157     info_i = LAPACKE_dspgst_work( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, ap_r,
00158                                   bp_r );
00159 
00160     LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00161 
00162     failed = compare_dspgst( ap, ap_i, info, info_i, n );
00163     if( failed == 0 ) {
00164         printf( "PASSED: row-major middle-level interface to dspgst\n" );
00165     } else {
00166         printf( "FAILED: row-major middle-level interface to dspgst\n" );
00167     }
00168 
00169     /* Initialize input data, call the row-major high-level
00170      * interface to LAPACK routine and check the results */
00171     for( i = 0; i < (n*(n+1)/2); i++ ) {
00172         ap_i[i] = ap_save[i];
00173     }
00174     for( i = 0; i < (n*(n+1)/2); i++ ) {
00175         bp_i[i] = bp[i];
00176     }
00177 
00178     /* Init row_major arrays */
00179     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00180     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, bp_i, bp_r );
00181     info_i = LAPACKE_dspgst( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, ap_r,
00182                              bp_r );
00183 
00184     LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00185 
00186     failed = compare_dspgst( ap, ap_i, info, info_i, n );
00187     if( failed == 0 ) {
00188         printf( "PASSED: row-major high-level interface to dspgst\n" );
00189     } else {
00190         printf( "FAILED: row-major high-level interface to dspgst\n" );
00191     }
00192 
00193     /* Release memory */
00194     if( ap != NULL ) {
00195         LAPACKE_free( ap );
00196     }
00197     if( ap_i != NULL ) {
00198         LAPACKE_free( ap_i );
00199     }
00200     if( ap_r != NULL ) {
00201         LAPACKE_free( ap_r );
00202     }
00203     if( ap_save != NULL ) {
00204         LAPACKE_free( ap_save );
00205     }
00206     if( bp != NULL ) {
00207         LAPACKE_free( bp );
00208     }
00209     if( bp_i != NULL ) {
00210         LAPACKE_free( bp_i );
00211     }
00212     if( bp_r != NULL ) {
00213         LAPACKE_free( bp_r );
00214     }
00215 
00216     return 0;
00217 }
00218 
00219 /* Auxiliary function: dspgst scalar parameters initialization */
00220 static void init_scalars_dspgst( lapack_int *itype, char *uplo, lapack_int *n )
00221 {
00222     *itype = 1;
00223     *uplo = 'L';
00224     *n = 4;
00225 
00226     return;
00227 }
00228 
00229 /* Auxiliary functions: dspgst array parameters initialization */
00230 static void init_ap( lapack_int size, double *ap ) {
00231     lapack_int i;
00232     for( i = 0; i < size; i++ ) {
00233         ap[i] = 0;
00234     }
00235     ap[0] = 2.39999999999999990e-001;
00236     ap[1] = 3.90000000000000010e-001;
00237     ap[2] = 4.19999999999999980e-001;
00238     ap[3] = -1.60000000000000000e-001;
00239     ap[4] = -1.10000000000000000e-001;
00240     ap[5] = 7.90000000000000040e-001;
00241     ap[6] = 6.30000000000000000e-001;
00242     ap[7] = -2.50000000000000000e-001;
00243     ap[8] = 4.79999999999999980e-001;
00244     ap[9] = -2.99999999999999990e-002;
00245 }
00246 static void init_bp( lapack_int size, double *bp ) {
00247     lapack_int i;
00248     for( i = 0; i < size; i++ ) {
00249         bp[i] = 0;
00250     }
00251     bp[0] = 2.03960780543711410e+000;
00252     bp[1] = -1.52970585407783540e+000;
00253     bp[2] = 2.74562589193457660e-001;
00254     bp[3] = -4.90290337845460110e-002;
00255     bp[4] = 1.64012194668567270e+000;
00256     bp[5] = -2.49981411948373810e-001;
00257     bp[6] = 6.18856422262437760e-001;
00258     bp[7] = 7.88748805574805310e-001;
00259     bp[8] = 6.44266130231023420e-001;
00260     bp[9] = 6.16063337578069970e-001;
00261 }
00262 
00263 /* Auxiliary function: C interface to dspgst results check */
00264 /* Return value: 0 - test is passed, non-zero - test is failed */
00265 static int compare_dspgst( double *ap, double *ap_i, lapack_int info,
00266                            lapack_int info_i, lapack_int n )
00267 {
00268     lapack_int i;
00269     int failed = 0;
00270     for( i = 0; i < (n*(n+1)/2); i++ ) {
00271         failed += compare_doubles(ap[i],ap_i[i]);
00272     }
00273     failed += (info == info_i) ? 0 : 1;
00274     if( info != 0 || info_i != 0 ) {
00275         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00276     }
00277 
00278     return failed;
00279 }


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