chpgst_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 * chpgst_1 is the test program for the C interface to LAPACK
00036 * routine chpgst
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_chpgst( lapack_int *itype, char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, lapack_complex_float *ap );
00056 static void init_bp( lapack_int size, lapack_complex_float *bp );
00057 static int compare_chpgst( lapack_complex_float *ap, lapack_complex_float *ap_i,
00058                            lapack_int info, 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     lapack_complex_float *ap = NULL, *ap_i = NULL;
00072     lapack_complex_float *bp = NULL, *bp_i = NULL;
00073     lapack_complex_float *ap_save = NULL;
00074     lapack_complex_float *ap_r = NULL;
00075     lapack_complex_float *bp_r = NULL;
00076 
00077     /* Iniitialize the scalar parameters */
00078     init_scalars_chpgst( &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 = (lapack_complex_float *)
00085         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00086     bp = (lapack_complex_float *)
00087         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00088 
00089     /* Allocate memory for the C interface function arrays */
00090     ap_i = (lapack_complex_float *)
00091         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00092     bp_i = (lapack_complex_float *)
00093         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00094 
00095     /* Allocate memory for the backup arrays */
00096     ap_save = (lapack_complex_float *)
00097         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00098 
00099     /* Allocate memory for the row-major arrays */
00100     ap_r = (lapack_complex_float *)
00101         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00102     bp_r = (lapack_complex_float *)
00103         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00104 
00105     /* Initialize input arrays */
00106     init_ap( (n*(n+1)/2), ap );
00107     init_bp( (n*(n+1)/2), bp );
00108 
00109     /* Backup the ouptut arrays */
00110     for( i = 0; i < (n*(n+1)/2); i++ ) {
00111         ap_save[i] = ap[i];
00112     }
00113 
00114     /* Call the LAPACK routine */
00115     chpgst_( &itype, &uplo, &n, ap, bp, &info );
00116 
00117     /* Initialize input data, call the column-major middle-level
00118      * interface to LAPACK routine and check the results */
00119     for( i = 0; i < (n*(n+1)/2); i++ ) {
00120         ap_i[i] = ap_save[i];
00121     }
00122     for( i = 0; i < (n*(n+1)/2); i++ ) {
00123         bp_i[i] = bp[i];
00124     }
00125     info_i = LAPACKE_chpgst_work( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, ap_i,
00126                                   bp_i );
00127 
00128     failed = compare_chpgst( ap, ap_i, info, info_i, n );
00129     if( failed == 0 ) {
00130         printf( "PASSED: column-major middle-level interface to chpgst\n" );
00131     } else {
00132         printf( "FAILED: column-major middle-level interface to chpgst\n" );
00133     }
00134 
00135     /* Initialize input data, call the column-major high-level
00136      * interface to LAPACK routine and check the results */
00137     for( i = 0; i < (n*(n+1)/2); i++ ) {
00138         ap_i[i] = ap_save[i];
00139     }
00140     for( i = 0; i < (n*(n+1)/2); i++ ) {
00141         bp_i[i] = bp[i];
00142     }
00143     info_i = LAPACKE_chpgst( LAPACK_COL_MAJOR, itype_i, uplo_i, n_i, ap_i,
00144                              bp_i );
00145 
00146     failed = compare_chpgst( ap, ap_i, info, info_i, n );
00147     if( failed == 0 ) {
00148         printf( "PASSED: column-major high-level interface to chpgst\n" );
00149     } else {
00150         printf( "FAILED: column-major high-level interface to chpgst\n" );
00151     }
00152 
00153     /* Initialize input data, call the row-major middle-level
00154      * interface to LAPACK routine and check the results */
00155     for( i = 0; i < (n*(n+1)/2); i++ ) {
00156         ap_i[i] = ap_save[i];
00157     }
00158     for( i = 0; i < (n*(n+1)/2); i++ ) {
00159         bp_i[i] = bp[i];
00160     }
00161 
00162     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00163     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, bp_i, bp_r );
00164     info_i = LAPACKE_chpgst_work( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, ap_r,
00165                                   bp_r );
00166 
00167     LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00168 
00169     failed = compare_chpgst( ap, ap_i, info, info_i, n );
00170     if( failed == 0 ) {
00171         printf( "PASSED: row-major middle-level interface to chpgst\n" );
00172     } else {
00173         printf( "FAILED: row-major middle-level interface to chpgst\n" );
00174     }
00175 
00176     /* Initialize input data, call the row-major high-level
00177      * interface to LAPACK routine and check the results */
00178     for( i = 0; i < (n*(n+1)/2); i++ ) {
00179         ap_i[i] = ap_save[i];
00180     }
00181     for( i = 0; i < (n*(n+1)/2); i++ ) {
00182         bp_i[i] = bp[i];
00183     }
00184 
00185     /* Init row_major arrays */
00186     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00187     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, bp_i, bp_r );
00188     info_i = LAPACKE_chpgst( LAPACK_ROW_MAJOR, itype_i, uplo_i, n_i, ap_r,
00189                              bp_r );
00190 
00191     LAPACKE_cpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00192 
00193     failed = compare_chpgst( ap, ap_i, info, info_i, n );
00194     if( failed == 0 ) {
00195         printf( "PASSED: row-major high-level interface to chpgst\n" );
00196     } else {
00197         printf( "FAILED: row-major high-level interface to chpgst\n" );
00198     }
00199 
00200     /* Release memory */
00201     if( ap != NULL ) {
00202         LAPACKE_free( ap );
00203     }
00204     if( ap_i != NULL ) {
00205         LAPACKE_free( ap_i );
00206     }
00207     if( ap_r != NULL ) {
00208         LAPACKE_free( ap_r );
00209     }
00210     if( ap_save != NULL ) {
00211         LAPACKE_free( ap_save );
00212     }
00213     if( bp != NULL ) {
00214         LAPACKE_free( bp );
00215     }
00216     if( bp_i != NULL ) {
00217         LAPACKE_free( bp_i );
00218     }
00219     if( bp_r != NULL ) {
00220         LAPACKE_free( bp_r );
00221     }
00222 
00223     return 0;
00224 }
00225 
00226 /* Auxiliary function: chpgst scalar parameters initialization */
00227 static void init_scalars_chpgst( lapack_int *itype, char *uplo, lapack_int *n )
00228 {
00229     *itype = 1;
00230     *uplo = 'L';
00231     *n = 4;
00232 
00233     return;
00234 }
00235 
00236 /* Auxiliary functions: chpgst array parameters initialization */
00237 static void init_ap( lapack_int size, lapack_complex_float *ap ) {
00238     lapack_int i;
00239     for( i = 0; i < size; i++ ) {
00240         ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00241     }
00242     ap[0] = lapack_make_complex_float( -7.360000134e+000, 0.000000000e+000 );
00243     ap[1] = lapack_make_complex_float( 7.699999809e-001, 4.300000072e-001 );
00244     ap[2] = lapack_make_complex_float( -6.399999857e-001, 9.200000167e-001 );
00245     ap[3] = lapack_make_complex_float( 3.009999990e+000, 6.969999790e+000 );
00246     ap[4] = lapack_make_complex_float( 3.490000010e+000, 0.000000000e+000 );
00247     ap[5] = lapack_make_complex_float( 2.190000057e+000, -4.449999809e+000 );
00248     ap[6] = lapack_make_complex_float( 1.899999976e+000, -3.730000019e+000 );
00249     ap[7] = lapack_make_complex_float( 1.199999973e-001, 0.000000000e+000 );
00250     ap[8] = lapack_make_complex_float( 2.880000114e+000, 3.170000076e+000 );
00251     ap[9] = lapack_make_complex_float( -2.539999962e+000, 0.000000000e+000 );
00252 }
00253 static void init_bp( lapack_int size, lapack_complex_float *bp ) {
00254     lapack_int i;
00255     for( i = 0; i < size; i++ ) {
00256         bp[i] = lapack_make_complex_float( 0.0f, 0.0f );
00257     }
00258     bp[0] = lapack_make_complex_float( 1.797220111e+000, 0.000000000e+000 );
00259     bp[1] = lapack_make_complex_float( 8.401864767e-001, 1.068316579e+000 );
00260     bp[2] = lapack_make_complex_float( 1.057188272e+000, -4.673885107e-001 );
00261     bp[3] = lapack_make_complex_float( 2.336942554e-001, -1.391037226e+000 );
00262     bp[4] = lapack_make_complex_float( 1.316353440e+000, 0.000000000e+000 );
00263     bp[5] = lapack_make_complex_float( -4.701749682e-001, 3.130658865e-001 );
00264     bp[6] = lapack_make_complex_float( 8.335255831e-002, 3.676066920e-002 );
00265     bp[7] = lapack_make_complex_float( 1.560392976e+000, 0.000000000e+000 );
00266     bp[8] = lapack_make_complex_float( 9.359616637e-001, 9.899691939e-001 );
00267     bp[9] = lapack_make_complex_float( 6.603332758e-001, 0.000000000e+000 );
00268 }
00269 
00270 /* Auxiliary function: C interface to chpgst results check */
00271 /* Return value: 0 - test is passed, non-zero - test is failed */
00272 static int compare_chpgst( lapack_complex_float *ap, lapack_complex_float *ap_i,
00273                            lapack_int info, lapack_int info_i, lapack_int n )
00274 {
00275     lapack_int i;
00276     int failed = 0;
00277     for( i = 0; i < (n*(n+1)/2); i++ ) {
00278         failed += compare_complex_floats(ap[i],ap_i[i]);
00279     }
00280     failed += (info == info_i) ? 0 : 1;
00281     if( info != 0 || info_i != 0 ) {
00282         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00283     }
00284 
00285     return failed;
00286 }


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