zhegst_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 * zhegst_1 is the test program for the C interface to LAPACK
00036 * routine zhegst
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_zhegst( lapack_int *itype, char *uplo, lapack_int *n,
00055                                  lapack_int *lda, lapack_int *ldb );
00056 static void init_a( lapack_int size, lapack_complex_double *a );
00057 static void init_b( lapack_int size, lapack_complex_double *b );
00058 static int compare_zhegst( lapack_complex_double *a, lapack_complex_double *a_i,
00059                            lapack_int info, lapack_int info_i, lapack_int lda,
00060                            lapack_int n );
00061 
00062 int main(void)
00063 {
00064     /* Local scalars */
00065     lapack_int itype, itype_i;
00066     char uplo, uplo_i;
00067     lapack_int n, n_i;
00068     lapack_int lda, lda_i;
00069     lapack_int lda_r;
00070     lapack_int ldb, ldb_i;
00071     lapack_int ldb_r;
00072     lapack_int info, info_i;
00073     lapack_int i;
00074     int failed;
00075 
00076     /* Local arrays */
00077     lapack_complex_double *a = NULL, *a_i = NULL;
00078     lapack_complex_double *b = NULL, *b_i = NULL;
00079     lapack_complex_double *a_save = NULL;
00080     lapack_complex_double *a_r = NULL;
00081     lapack_complex_double *b_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_zhegst( &itype, &uplo, &n, &lda, &ldb );
00085     lda_r = n+2;
00086     ldb_r = n+2;
00087     itype_i = itype;
00088     uplo_i = uplo;
00089     n_i = n;
00090     lda_i = lda;
00091     ldb_i = ldb;
00092 
00093     /* Allocate memory for the LAPACK routine arrays */
00094     a = (lapack_complex_double *)
00095         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00096     b = (lapack_complex_double *)
00097         LAPACKE_malloc( ldb*n * sizeof(lapack_complex_double) );
00098 
00099     /* Allocate memory for the C interface function arrays */
00100     a_i = (lapack_complex_double *)
00101         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00102     b_i = (lapack_complex_double *)
00103         LAPACKE_malloc( ldb*n * sizeof(lapack_complex_double) );
00104 
00105     /* Allocate memory for the backup arrays */
00106     a_save = (lapack_complex_double *)
00107         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00108 
00109     /* Allocate memory for the row-major arrays */
00110     a_r = (lapack_complex_double *)
00111         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00112     b_r = (lapack_complex_double *)
00113         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00114 
00115     /* Initialize input arrays */
00116     init_a( lda*n, a );
00117     init_b( ldb*n, b );
00118 
00119     /* Backup the ouptut arrays */
00120     for( i = 0; i < lda*n; i++ ) {
00121         a_save[i] = a[i];
00122     }
00123 
00124     /* Call the LAPACK routine */
00125     zhegst_( &itype, &uplo, &n, a, &lda, b, &ldb, &info );
00126 
00127     /* Initialize input data, call the column-major middle-level
00128      * interface to LAPACK routine and check the results */
00129     for( i = 0; i < lda*n; i++ ) {
00130         a_i[i] = a_save[i];
00131     }
00132     for( i = 0; i < ldb*n; i++ ) {
00133         b_i[i] = b[i];
00134     }
00135     info_i = LAPACKE_zhegst_work( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, a_i,
00136                                   lda_i, b_i, ldb_i );
00137 
00138     failed = compare_zhegst( a, a_i, info, info_i, lda, n );
00139     if( failed == 0 ) {
00140         printf( "PASSED: column-major middle-level interface to zhegst\n" );
00141     } else {
00142         printf( "FAILED: column-major middle-level interface to zhegst\n" );
00143     }
00144 
00145     /* Initialize input data, call the column-major high-level
00146      * interface to LAPACK routine and check the results */
00147     for( i = 0; i < lda*n; i++ ) {
00148         a_i[i] = a_save[i];
00149     }
00150     for( i = 0; i < ldb*n; i++ ) {
00151         b_i[i] = b[i];
00152     }
00153     info_i = LAPACKE_zhegst( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, a_i, lda_i,
00154                              b_i, ldb_i );
00155 
00156     failed = compare_zhegst( a, a_i, info, info_i, lda, n );
00157     if( failed == 0 ) {
00158         printf( "PASSED: column-major high-level interface to zhegst\n" );
00159     } else {
00160         printf( "FAILED: column-major high-level interface to zhegst\n" );
00161     }
00162 
00163     /* Initialize input data, call the row-major middle-level
00164      * interface to LAPACK routine and check the results */
00165     for( i = 0; i < lda*n; i++ ) {
00166         a_i[i] = a_save[i];
00167     }
00168     for( i = 0; i < ldb*n; i++ ) {
00169         b_i[i] = b[i];
00170     }
00171 
00172     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00173     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00174     info_i = LAPACKE_zhegst_work( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, a_r,
00175                                   lda_r, b_r, ldb_r );
00176 
00177     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00178 
00179     failed = compare_zhegst( a, a_i, info, info_i, lda, n );
00180     if( failed == 0 ) {
00181         printf( "PASSED: row-major middle-level interface to zhegst\n" );
00182     } else {
00183         printf( "FAILED: row-major middle-level interface to zhegst\n" );
00184     }
00185 
00186     /* Initialize input data, call the row-major high-level
00187      * interface to LAPACK routine and check the results */
00188     for( i = 0; i < lda*n; i++ ) {
00189         a_i[i] = a_save[i];
00190     }
00191     for( i = 0; i < ldb*n; i++ ) {
00192         b_i[i] = b[i];
00193     }
00194 
00195     /* Init row_major arrays */
00196     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00197     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, b_i, ldb, b_r, n+2 );
00198     info_i = LAPACKE_zhegst( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, a_r, lda_r,
00199                              b_r, ldb_r );
00200 
00201     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00202 
00203     failed = compare_zhegst( a, a_i, info, info_i, lda, n );
00204     if( failed == 0 ) {
00205         printf( "PASSED: row-major high-level interface to zhegst\n" );
00206     } else {
00207         printf( "FAILED: row-major high-level interface to zhegst\n" );
00208     }
00209 
00210     /* Release memory */
00211     if( a != NULL ) {
00212         LAPACKE_free( a );
00213     }
00214     if( a_i != NULL ) {
00215         LAPACKE_free( a_i );
00216     }
00217     if( a_r != NULL ) {
00218         LAPACKE_free( a_r );
00219     }
00220     if( a_save != NULL ) {
00221         LAPACKE_free( a_save );
00222     }
00223     if( b != NULL ) {
00224         LAPACKE_free( b );
00225     }
00226     if( b_i != NULL ) {
00227         LAPACKE_free( b_i );
00228     }
00229     if( b_r != NULL ) {
00230         LAPACKE_free( b_r );
00231     }
00232 
00233     return 0;
00234 }
00235 
00236 /* Auxiliary function: zhegst scalar parameters initialization */
00237 static void init_scalars_zhegst( lapack_int *itype, char *uplo, lapack_int *n,
00238                                  lapack_int *lda, lapack_int *ldb )
00239 {
00240     *itype = 1;
00241     *uplo = 'L';
00242     *n = 4;
00243     *lda = 8;
00244     *ldb = 8;
00245 
00246     return;
00247 }
00248 
00249 /* Auxiliary functions: zhegst array parameters initialization */
00250 static void init_a( lapack_int size, lapack_complex_double *a ) {
00251     lapack_int i;
00252     for( i = 0; i < size; i++ ) {
00253         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00254     }
00255     a[0] = lapack_make_complex_double( -7.36000000000000030e+000,
00256                                        0.00000000000000000e+000 );
00257     a[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00258                                        0.00000000000000000e+000 );
00259     a[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00260                                         0.00000000000000000e+000 );
00261     a[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00262                                         0.00000000000000000e+000 );
00263     a[1] = lapack_make_complex_double( 7.70000000000000020e-001,
00264                                        4.29999999999999990e-001 );
00265     a[9] = lapack_make_complex_double( 3.49000000000000020e+000,
00266                                        0.00000000000000000e+000 );
00267     a[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00268                                         0.00000000000000000e+000 );
00269     a[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00270                                         0.00000000000000000e+000 );
00271     a[2] = lapack_make_complex_double( -6.40000000000000010e-001,
00272                                        9.20000000000000040e-001 );
00273     a[10] = lapack_make_complex_double( 2.18999999999999990e+000,
00274                                         -4.45000000000000020e+000 );
00275     a[18] = lapack_make_complex_double( 1.20000000000000000e-001,
00276                                         0.00000000000000000e+000 );
00277     a[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00278                                         0.00000000000000000e+000 );
00279     a[3] = lapack_make_complex_double( 3.00999999999999980e+000,
00280                                        6.96999999999999980e+000 );
00281     a[11] = lapack_make_complex_double( 1.89999999999999990e+000,
00282                                         -3.73000000000000000e+000 );
00283     a[19] = lapack_make_complex_double( 2.87999999999999990e+000,
00284                                         3.16999999999999990e+000 );
00285     a[27] = lapack_make_complex_double( -2.54000000000000000e+000,
00286                                         0.00000000000000000e+000 );
00287 }
00288 static void init_b( lapack_int size, lapack_complex_double *b ) {
00289     lapack_int i;
00290     for( i = 0; i < size; i++ ) {
00291         b[i] = lapack_make_complex_double( 0.0, 0.0 );
00292     }
00293     b[0] = lapack_make_complex_double( 1.79722007556114290e+000,
00294                                        0.00000000000000000e+000 );
00295     b[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00296                                        0.00000000000000000e+000 );
00297     b[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00298                                         0.00000000000000000e+000 );
00299     b[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00300                                         0.00000000000000000e+000 );
00301     b[1] = lapack_make_complex_double( 8.40186474952732460e-001,
00302                                        1.06831657742334190e+000 );
00303     b[9] = lapack_make_complex_double( 1.31635343950968520e+000,
00304                                        0.00000000000000000e+000 );
00305     b[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00306                                         0.00000000000000000e+000 );
00307     b[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00308                                         0.00000000000000000e+000 );
00309     b[2] = lapack_make_complex_double( 1.05718827974184860e+000,
00310                                        -4.67388502622712030e-001 );
00311     b[10] = lapack_make_complex_double( -4.70174947010632950e-001,
00312                                         3.13065815599946400e-001 );
00313     b[18] = lapack_make_complex_double( 1.56039297713712430e+000,
00314                                         0.00000000000000000e+000 );
00315     b[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00316                                         0.00000000000000000e+000 );
00317     b[3] = lapack_make_complex_double( 2.33694251311356020e-001,
00318                                        -1.39103721018664310e+000 );
00319     b[11] = lapack_make_complex_double( 8.33525092394419580e-002,
00320                                         3.67607144303747430e-002 );
00321     b[19] = lapack_make_complex_double( 9.35961733792340160e-001,
00322                                         9.89969219281573660e-001 );
00323     b[27] = lapack_make_complex_double( 6.60333297365589100e-001,
00324                                         0.00000000000000000e+000 );
00325 }
00326 
00327 /* Auxiliary function: C interface to zhegst results check */
00328 /* Return value: 0 - test is passed, non-zero - test is failed */
00329 static int compare_zhegst( lapack_complex_double *a, lapack_complex_double *a_i,
00330                            lapack_int info, lapack_int info_i, lapack_int lda,
00331                            lapack_int n )
00332 {
00333     lapack_int i;
00334     int failed = 0;
00335     for( i = 0; i < lda*n; i++ ) {
00336         failed += compare_complex_doubles(a[i],a_i[i]);
00337     }
00338     failed += (info == info_i) ? 0 : 1;
00339     if( info != 0 || info_i != 0 ) {
00340         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00341     }
00342 
00343     return failed;
00344 }


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