ssygst_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 * ssygst_1 is the test program for the C interface to LAPACK
00036 * routine ssygst
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_ssygst( lapack_int *itype, char *uplo, lapack_int *n,
00055                                  lapack_int *lda, lapack_int *ldb );
00056 static void init_a( lapack_int size, float *a );
00057 static void init_b( lapack_int size, float *b );
00058 static int compare_ssygst( float *a, float *a_i, lapack_int info,
00059                            lapack_int info_i, lapack_int lda, lapack_int n );
00060 
00061 int main(void)
00062 {
00063     /* Local scalars */
00064     lapack_int itype, itype_i;
00065     char uplo, uplo_i;
00066     lapack_int n, n_i;
00067     lapack_int lda, lda_i;
00068     lapack_int lda_r;
00069     lapack_int ldb, ldb_i;
00070     lapack_int ldb_r;
00071     lapack_int info, info_i;
00072     lapack_int i;
00073     int failed;
00074 
00075     /* Local arrays */
00076     float *a = NULL, *a_i = NULL;
00077     float *b = NULL, *b_i = NULL;
00078     float *a_save = NULL;
00079     float *a_r = NULL;
00080     float *b_r = NULL;
00081 
00082     /* Iniitialize the scalar parameters */
00083     init_scalars_ssygst( &itype, &uplo, &n, &lda, &ldb );
00084     lda_r = n+2;
00085     ldb_r = n+2;
00086     itype_i = itype;
00087     uplo_i = uplo;
00088     n_i = n;
00089     lda_i = lda;
00090     ldb_i = ldb;
00091 
00092     /* Allocate memory for the LAPACK routine arrays */
00093     a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00094     b = (float *)LAPACKE_malloc( ldb*n * sizeof(float) );
00095 
00096     /* Allocate memory for the C interface function arrays */
00097     a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00098     b_i = (float *)LAPACKE_malloc( ldb*n * sizeof(float) );
00099 
00100     /* Allocate memory for the backup arrays */
00101     a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00102 
00103     /* Allocate memory for the row-major arrays */
00104     a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00105     b_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00106 
00107     /* Initialize input arrays */
00108     init_a( lda*n, a );
00109     init_b( ldb*n, b );
00110 
00111     /* Backup the ouptut arrays */
00112     for( i = 0; i < lda*n; i++ ) {
00113         a_save[i] = a[i];
00114     }
00115 
00116     /* Call the LAPACK routine */
00117     ssygst_( &itype, &uplo, &n, a, &lda, b, &ldb, &info );
00118 
00119     /* Initialize input data, call the column-major middle-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     for( i = 0; i < ldb*n; i++ ) {
00125         b_i[i] = b[i];
00126     }
00127     info_i = LAPACKE_ssygst_work( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, a_i,
00128                                   lda_i, b_i, ldb_i );
00129 
00130     failed = compare_ssygst( a, a_i, info, info_i, lda, n );
00131     if( failed == 0 ) {
00132         printf( "PASSED: column-major middle-level interface to ssygst\n" );
00133     } else {
00134         printf( "FAILED: column-major middle-level interface to ssygst\n" );
00135     }
00136 
00137     /* Initialize input data, call the column-major high-level
00138      * interface to LAPACK routine and check the results */
00139     for( i = 0; i < lda*n; i++ ) {
00140         a_i[i] = a_save[i];
00141     }
00142     for( i = 0; i < ldb*n; i++ ) {
00143         b_i[i] = b[i];
00144     }
00145     info_i = LAPACKE_ssygst( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, a_i, lda_i,
00146                              b_i, ldb_i );
00147 
00148     failed = compare_ssygst( a, a_i, info, info_i, lda, n );
00149     if( failed == 0 ) {
00150         printf( "PASSED: column-major high-level interface to ssygst\n" );
00151     } else {
00152         printf( "FAILED: column-major high-level interface to ssygst\n" );
00153     }
00154 
00155     /* Initialize input data, call the row-major middle-level
00156      * interface to LAPACK routine and check the results */
00157     for( i = 0; i < lda*n; i++ ) {
00158         a_i[i] = a_save[i];
00159     }
00160     for( i = 0; i < ldb*n; i++ ) {
00161         b_i[i] = b[i];
00162     }
00163 
00164     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00165     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00166     info_i = LAPACKE_ssygst_work( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, a_r,
00167                                   lda_r, b_r, ldb_r );
00168 
00169     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00170 
00171     failed = compare_ssygst( a, a_i, info, info_i, lda, n );
00172     if( failed == 0 ) {
00173         printf( "PASSED: row-major middle-level interface to ssygst\n" );
00174     } else {
00175         printf( "FAILED: row-major middle-level interface to ssygst\n" );
00176     }
00177 
00178     /* Initialize input data, call the row-major high-level
00179      * interface to LAPACK routine and check the results */
00180     for( i = 0; i < lda*n; i++ ) {
00181         a_i[i] = a_save[i];
00182     }
00183     for( i = 0; i < ldb*n; i++ ) {
00184         b_i[i] = b[i];
00185     }
00186 
00187     /* Init row_major arrays */
00188     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00189     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00190     info_i = LAPACKE_ssygst( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, a_r, lda_r,
00191                              b_r, ldb_r );
00192 
00193     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00194 
00195     failed = compare_ssygst( a, a_i, info, info_i, lda, n );
00196     if( failed == 0 ) {
00197         printf( "PASSED: row-major high-level interface to ssygst\n" );
00198     } else {
00199         printf( "FAILED: row-major high-level interface to ssygst\n" );
00200     }
00201 
00202     /* Release memory */
00203     if( a != NULL ) {
00204         LAPACKE_free( a );
00205     }
00206     if( a_i != NULL ) {
00207         LAPACKE_free( a_i );
00208     }
00209     if( a_r != NULL ) {
00210         LAPACKE_free( a_r );
00211     }
00212     if( a_save != NULL ) {
00213         LAPACKE_free( a_save );
00214     }
00215     if( b != NULL ) {
00216         LAPACKE_free( b );
00217     }
00218     if( b_i != NULL ) {
00219         LAPACKE_free( b_i );
00220     }
00221     if( b_r != NULL ) {
00222         LAPACKE_free( b_r );
00223     }
00224 
00225     return 0;
00226 }
00227 
00228 /* Auxiliary function: ssygst scalar parameters initialization */
00229 static void init_scalars_ssygst( lapack_int *itype, char *uplo, lapack_int *n,
00230                                  lapack_int *lda, lapack_int *ldb )
00231 {
00232     *itype = 1;
00233     *uplo = 'L';
00234     *n = 4;
00235     *lda = 8;
00236     *ldb = 8;
00237 
00238     return;
00239 }
00240 
00241 /* Auxiliary functions: ssygst array parameters initialization */
00242 static void init_a( lapack_int size, float *a ) {
00243     lapack_int i;
00244     for( i = 0; i < size; i++ ) {
00245         a[i] = 0;
00246     }
00247     a[0] = 2.399999946e-001;  /* a[0,0] */
00248     a[8] = 0.000000000e+000;  /* a[0,1] */
00249     a[16] = 0.000000000e+000;  /* a[0,2] */
00250     a[24] = 0.000000000e+000;  /* a[0,3] */
00251     a[1] = 3.899999857e-001;  /* a[1,0] */
00252     a[9] = -1.099999994e-001;  /* a[1,1] */
00253     a[17] = 0.000000000e+000;  /* a[1,2] */
00254     a[25] = 0.000000000e+000;  /* a[1,3] */
00255     a[2] = 4.199999869e-001;  /* a[2,0] */
00256     a[10] = 7.900000215e-001;  /* a[2,1] */
00257     a[18] = -2.500000000e-001;  /* a[2,2] */
00258     a[26] = 0.000000000e+000;  /* a[2,3] */
00259     a[3] = -1.599999964e-001;  /* a[3,0] */
00260     a[11] = 6.299999952e-001;  /* a[3,1] */
00261     a[19] = 4.799999893e-001;  /* a[3,2] */
00262     a[27] = -2.999999933e-002;  /* a[3,3] */
00263 }
00264 static void init_b( lapack_int size, float *b ) {
00265     lapack_int i;
00266     for( i = 0; i < size; i++ ) {
00267         b[i] = 0;
00268     }
00269     b[0] = 2.039607763e+000;  /* b[0,0] */
00270     b[8] = 0.000000000e+000;  /* b[0,1] */
00271     b[16] = 0.000000000e+000;  /* b[0,2] */
00272     b[24] = 0.000000000e+000;  /* b[0,3] */
00273     b[1] = -1.529705763e+000;  /* b[1,0] */
00274     b[9] = 1.640122056e+000;  /* b[1,1] */
00275     b[17] = 0.000000000e+000;  /* b[1,2] */
00276     b[25] = 0.000000000e+000;  /* b[1,3] */
00277     b[2] = 2.745625973e-001;  /* b[2,0] */
00278     b[10] = -2.499813884e-001;  /* b[2,1] */
00279     b[18] = 7.887488008e-001;  /* b[2,2] */
00280     b[26] = 0.000000000e+000;  /* b[2,3] */
00281     b[3] = -4.902903363e-002;  /* b[3,0] */
00282     b[11] = 6.188563704e-001;  /* b[3,1] */
00283     b[19] = 6.442660689e-001;  /* b[3,2] */
00284     b[27] = 6.160634160e-001;  /* b[3,3] */
00285 }
00286 
00287 /* Auxiliary function: C interface to ssygst results check */
00288 /* Return value: 0 - test is passed, non-zero - test is failed */
00289 static int compare_ssygst( float *a, float *a_i, lapack_int info,
00290                            lapack_int info_i, lapack_int lda, lapack_int n )
00291 {
00292     lapack_int i;
00293     int failed = 0;
00294     for( i = 0; i < lda*n; i++ ) {
00295         failed += compare_floats(a[i],a_i[i]);
00296     }
00297     failed += (info == info_i) ? 0 : 1;
00298     if( info != 0 || info_i != 0 ) {
00299         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00300     }
00301 
00302     return failed;
00303 }


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