zhpgst_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 * zhpgst_1 is the test program for the C interface to LAPACK
00036 * routine zhpgst
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_zhpgst( lapack_int *itype, char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, lapack_complex_double *ap );
00056 static void init_bp( lapack_int size, lapack_complex_double *bp );
00057 static int compare_zhpgst( lapack_complex_double *ap,
00058                            lapack_complex_double *ap_i, lapack_int info,
00059                            lapack_int info_i, 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 info, info_i;
00068     lapack_int i;
00069     int failed;
00070 
00071     /* Local arrays */
00072     lapack_complex_double *ap = NULL, *ap_i = NULL;
00073     lapack_complex_double *bp = NULL, *bp_i = NULL;
00074     lapack_complex_double *ap_save = NULL;
00075     lapack_complex_double *ap_r = NULL;
00076     lapack_complex_double *bp_r = NULL;
00077 
00078     /* Iniitialize the scalar parameters */
00079     init_scalars_zhpgst( &itype, &uplo, &n );
00080     itype_i = itype;
00081     uplo_i = uplo;
00082     n_i = n;
00083 
00084     /* Allocate memory for the LAPACK routine arrays */
00085     ap = (lapack_complex_double *)
00086         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00087     bp = (lapack_complex_double *)
00088         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00089 
00090     /* Allocate memory for the C interface function arrays */
00091     ap_i = (lapack_complex_double *)
00092         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00093     bp_i = (lapack_complex_double *)
00094         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00095 
00096     /* Allocate memory for the backup arrays */
00097     ap_save = (lapack_complex_double *)
00098         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00099 
00100     /* Allocate memory for the row-major arrays */
00101     ap_r = (lapack_complex_double *)
00102         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00103     bp_r = (lapack_complex_double *)
00104         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00105 
00106     /* Initialize input arrays */
00107     init_ap( (n*(n+1)/2), ap );
00108     init_bp( (n*(n+1)/2), bp );
00109 
00110     /* Backup the ouptut arrays */
00111     for( i = 0; i < (n*(n+1)/2); i++ ) {
00112         ap_save[i] = ap[i];
00113     }
00114 
00115     /* Call the LAPACK routine */
00116     zhpgst_( &itype, &uplo, &n, ap, bp, &info );
00117 
00118     /* Initialize input data, call the column-major middle-level
00119      * interface to LAPACK routine and check the results */
00120     for( i = 0; i < (n*(n+1)/2); i++ ) {
00121         ap_i[i] = ap_save[i];
00122     }
00123     for( i = 0; i < (n*(n+1)/2); i++ ) {
00124         bp_i[i] = bp[i];
00125     }
00126     info_i = LAPACKE_zhpgst_work( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, ap_i,
00127                                   bp_i );
00128 
00129     failed = compare_zhpgst( ap, ap_i, info, info_i, n );
00130     if( failed == 0 ) {
00131         printf( "PASSED: column-major middle-level interface to zhpgst\n" );
00132     } else {
00133         printf( "FAILED: column-major middle-level interface to zhpgst\n" );
00134     }
00135 
00136     /* Initialize input data, call the column-major high-level
00137      * interface to LAPACK routine and check the results */
00138     for( i = 0; i < (n*(n+1)/2); i++ ) {
00139         ap_i[i] = ap_save[i];
00140     }
00141     for( i = 0; i < (n*(n+1)/2); i++ ) {
00142         bp_i[i] = bp[i];
00143     }
00144     info_i = LAPACKE_zhpgst( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, ap_i,
00145                              bp_i );
00146 
00147     failed = compare_zhpgst( ap, ap_i, info, info_i, n );
00148     if( failed == 0 ) {
00149         printf( "PASSED: column-major high-level interface to zhpgst\n" );
00150     } else {
00151         printf( "FAILED: column-major high-level interface to zhpgst\n" );
00152     }
00153 
00154     /* Initialize input data, call the row-major middle-level
00155      * interface to LAPACK routine and check the results */
00156     for( i = 0; i < (n*(n+1)/2); i++ ) {
00157         ap_i[i] = ap_save[i];
00158     }
00159     for( i = 0; i < (n*(n+1)/2); i++ ) {
00160         bp_i[i] = bp[i];
00161     }
00162 
00163     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00164     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, bp_i, bp_r );
00165     info_i = LAPACKE_zhpgst_work( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, ap_r,
00166                                   bp_r );
00167 
00168     LAPACKE_zpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00169 
00170     failed = compare_zhpgst( ap, ap_i, info, info_i, n );
00171     if( failed == 0 ) {
00172         printf( "PASSED: row-major middle-level interface to zhpgst\n" );
00173     } else {
00174         printf( "FAILED: row-major middle-level interface to zhpgst\n" );
00175     }
00176 
00177     /* Initialize input data, call the row-major high-level
00178      * interface to LAPACK routine and check the results */
00179     for( i = 0; i < (n*(n+1)/2); i++ ) {
00180         ap_i[i] = ap_save[i];
00181     }
00182     for( i = 0; i < (n*(n+1)/2); i++ ) {
00183         bp_i[i] = bp[i];
00184     }
00185 
00186     /* Init row_major arrays */
00187     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00188     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, bp_i, bp_r );
00189     info_i = LAPACKE_zhpgst( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, ap_r,
00190                              bp_r );
00191 
00192     LAPACKE_zpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00193 
00194     failed = compare_zhpgst( ap, ap_i, info, info_i, n );
00195     if( failed == 0 ) {
00196         printf( "PASSED: row-major high-level interface to zhpgst\n" );
00197     } else {
00198         printf( "FAILED: row-major high-level interface to zhpgst\n" );
00199     }
00200 
00201     /* Release memory */
00202     if( ap != NULL ) {
00203         LAPACKE_free( ap );
00204     }
00205     if( ap_i != NULL ) {
00206         LAPACKE_free( ap_i );
00207     }
00208     if( ap_r != NULL ) {
00209         LAPACKE_free( ap_r );
00210     }
00211     if( ap_save != NULL ) {
00212         LAPACKE_free( ap_save );
00213     }
00214     if( bp != NULL ) {
00215         LAPACKE_free( bp );
00216     }
00217     if( bp_i != NULL ) {
00218         LAPACKE_free( bp_i );
00219     }
00220     if( bp_r != NULL ) {
00221         LAPACKE_free( bp_r );
00222     }
00223 
00224     return 0;
00225 }
00226 
00227 /* Auxiliary function: zhpgst scalar parameters initialization */
00228 static void init_scalars_zhpgst( lapack_int *itype, char *uplo, lapack_int *n )
00229 {
00230     *itype = 1;
00231     *uplo = 'L';
00232     *n = 4;
00233 
00234     return;
00235 }
00236 
00237 /* Auxiliary functions: zhpgst array parameters initialization */
00238 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00239     lapack_int i;
00240     for( i = 0; i < size; i++ ) {
00241         ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00242     }
00243     ap[0] = lapack_make_complex_double( -7.36000000000000030e+000,
00244                                         0.00000000000000000e+000 );
00245     ap[1] = lapack_make_complex_double( 7.70000000000000020e-001,
00246                                         4.29999999999999990e-001 );
00247     ap[2] = lapack_make_complex_double( -6.40000000000000010e-001,
00248                                         9.20000000000000040e-001 );
00249     ap[3] = lapack_make_complex_double( 3.00999999999999980e+000,
00250                                         6.96999999999999980e+000 );
00251     ap[4] = lapack_make_complex_double( 3.49000000000000020e+000,
00252                                         0.00000000000000000e+000 );
00253     ap[5] = lapack_make_complex_double( 2.18999999999999990e+000,
00254                                         -4.45000000000000020e+000 );
00255     ap[6] = lapack_make_complex_double( 1.89999999999999990e+000,
00256                                         -3.73000000000000000e+000 );
00257     ap[7] = lapack_make_complex_double( 1.20000000000000000e-001,
00258                                         0.00000000000000000e+000 );
00259     ap[8] = lapack_make_complex_double( 2.87999999999999990e+000,
00260                                         3.16999999999999990e+000 );
00261     ap[9] = lapack_make_complex_double( -2.54000000000000000e+000,
00262                                         0.00000000000000000e+000 );
00263 }
00264 static void init_bp( lapack_int size, lapack_complex_double *bp ) {
00265     lapack_int i;
00266     for( i = 0; i < size; i++ ) {
00267         bp[i] = lapack_make_complex_double( 0.0, 0.0 );
00268     }
00269     bp[0] = lapack_make_complex_double( 1.79722007556114290e+000,
00270                                         0.00000000000000000e+000 );
00271     bp[1] = lapack_make_complex_double( 8.40186474952732460e-001,
00272                                         1.06831657742334190e+000 );
00273     bp[2] = lapack_make_complex_double( 1.05718827974184860e+000,
00274                                         -4.67388502622712030e-001 );
00275     bp[3] = lapack_make_complex_double( 2.33694251311356020e-001,
00276                                         -1.39103721018664310e+000 );
00277     bp[4] = lapack_make_complex_double( 1.31635343950968520e+000,
00278                                         0.00000000000000000e+000 );
00279     bp[5] = lapack_make_complex_double( -4.70174947010632950e-001,
00280                                         3.13065815599946400e-001 );
00281     bp[6] = lapack_make_complex_double( 8.33525092394419580e-002,
00282                                         3.67607144303747430e-002 );
00283     bp[7] = lapack_make_complex_double( 1.56039297713712430e+000,
00284                                         0.00000000000000000e+000 );
00285     bp[8] = lapack_make_complex_double( 9.35961733792340160e-001,
00286                                         9.89969219281573890e-001 );
00287     bp[9] = lapack_make_complex_double( 6.60333297365588770e-001,
00288                                         0.00000000000000000e+000 );
00289 }
00290 
00291 /* Auxiliary function: C interface to zhpgst results check */
00292 /* Return value: 0 - test is passed, non-zero - test is failed */
00293 static int compare_zhpgst( lapack_complex_double *ap,
00294                            lapack_complex_double *ap_i, lapack_int info,
00295                            lapack_int info_i, lapack_int n )
00296 {
00297     lapack_int i;
00298     int failed = 0;
00299     for( i = 0; i < (n*(n+1)/2); i++ ) {
00300         failed += compare_complex_doubles(ap[i],ap_i[i]);
00301     }
00302     failed += (info == info_i) ? 0 : 1;
00303     if( info != 0 || info_i != 0 ) {
00304         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00305     }
00306 
00307     return failed;
00308 }


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