cgebak_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 * cgebak_1 is the test program for the C interface to LAPACK
00036 * routine cgebak
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_cgebak( char *job, char *side, lapack_int *n,
00055                                  lapack_int *ilo, lapack_int *ihi,
00056                                  lapack_int *m, lapack_int *ldv );
00057 static void init_scale( lapack_int size, float *scale );
00058 static void init_v( lapack_int size, lapack_complex_float *v );
00059 static int compare_cgebak( lapack_complex_float *v, lapack_complex_float *v_i,
00060                            lapack_int info, lapack_int info_i, lapack_int ldv,
00061                            lapack_int m );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char job, job_i;
00067     char side, side_i;
00068     lapack_int n, n_i;
00069     lapack_int ilo, ilo_i;
00070     lapack_int ihi, ihi_i;
00071     lapack_int m, m_i;
00072     lapack_int ldv, ldv_i;
00073     lapack_int ldv_r;
00074     lapack_int info, info_i;
00075     lapack_int i;
00076     int failed;
00077 
00078     /* Local arrays */
00079     float *scale = NULL, *scale_i = NULL;
00080     lapack_complex_float *v = NULL, *v_i = NULL;
00081     lapack_complex_float *v_save = NULL;
00082     lapack_complex_float *v_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_cgebak( &job, &side, &n, &ilo, &ihi, &m, &ldv );
00086     ldv_r = m+2;
00087     job_i = job;
00088     side_i = side;
00089     n_i = n;
00090     ilo_i = ilo;
00091     ihi_i = ihi;
00092     m_i = m;
00093     ldv_i = ldv;
00094 
00095     /* Allocate memory for the LAPACK routine arrays */
00096     scale = (float *)LAPACKE_malloc( n * sizeof(float) );
00097     v = (lapack_complex_float *)
00098         LAPACKE_malloc( ldv*m * sizeof(lapack_complex_float) );
00099 
00100     /* Allocate memory for the C interface function arrays */
00101     scale_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00102     v_i = (lapack_complex_float *)
00103         LAPACKE_malloc( ldv*m * sizeof(lapack_complex_float) );
00104 
00105     /* Allocate memory for the backup arrays */
00106     v_save = (lapack_complex_float *)
00107         LAPACKE_malloc( ldv*m * sizeof(lapack_complex_float) );
00108 
00109     /* Allocate memory for the row-major arrays */
00110     v_r = (lapack_complex_float *)
00111         LAPACKE_malloc( n*(m+2) * sizeof(lapack_complex_float) );
00112 
00113     /* Initialize input arrays */
00114     init_scale( n, scale );
00115     init_v( ldv*m, v );
00116 
00117     /* Backup the ouptut arrays */
00118     for( i = 0; i < ldv*m; i++ ) {
00119         v_save[i] = v[i];
00120     }
00121 
00122     /* Call the LAPACK routine */
00123     cgebak_( &job, &side, &n, &ilo, &ihi, scale, &m, v, &ldv, &info );
00124 
00125     /* Initialize input data, call the column-major middle-level
00126      * interface to LAPACK routine and check the results */
00127     for( i = 0; i < n; i++ ) {
00128         scale_i[i] = scale[i];
00129     }
00130     for( i = 0; i < ldv*m; i++ ) {
00131         v_i[i] = v_save[i];
00132     }
00133     info_i = LAPACKE_cgebak_work( LAPACK_COL_MAJOR, job_i, side_i, n_i, ilo_i,
00134                                   ihi_i, scale_i, m_i, v_i, ldv_i );
00135 
00136     failed = compare_cgebak( v, v_i, info, info_i, ldv, m );
00137     if( failed == 0 ) {
00138         printf( "PASSED: column-major middle-level interface to cgebak\n" );
00139     } else {
00140         printf( "FAILED: column-major middle-level interface to cgebak\n" );
00141     }
00142 
00143     /* Initialize input data, call the column-major high-level
00144      * interface to LAPACK routine and check the results */
00145     for( i = 0; i < n; i++ ) {
00146         scale_i[i] = scale[i];
00147     }
00148     for( i = 0; i < ldv*m; i++ ) {
00149         v_i[i] = v_save[i];
00150     }
00151     info_i = LAPACKE_cgebak( LAPACK_COL_MAJOR, job_i, side_i, n_i, ilo_i, ihi_i,
00152                              scale_i, m_i, v_i, ldv_i );
00153 
00154     failed = compare_cgebak( v, v_i, info, info_i, ldv, m );
00155     if( failed == 0 ) {
00156         printf( "PASSED: column-major high-level interface to cgebak\n" );
00157     } else {
00158         printf( "FAILED: column-major high-level interface to cgebak\n" );
00159     }
00160 
00161     /* Initialize input data, call the row-major middle-level
00162      * interface to LAPACK routine and check the results */
00163     for( i = 0; i < n; i++ ) {
00164         scale_i[i] = scale[i];
00165     }
00166     for( i = 0; i < ldv*m; i++ ) {
00167         v_i[i] = v_save[i];
00168     }
00169 
00170     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, m, v_i, ldv, v_r, m+2 );
00171     info_i = LAPACKE_cgebak_work( LAPACK_ROW_MAJOR, job_i, side_i, n_i, ilo_i,
00172                                   ihi_i, scale_i, m_i, v_r, ldv_r );
00173 
00174     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, m, v_r, m+2, v_i, ldv );
00175 
00176     failed = compare_cgebak( v, v_i, info, info_i, ldv, m );
00177     if( failed == 0 ) {
00178         printf( "PASSED: row-major middle-level interface to cgebak\n" );
00179     } else {
00180         printf( "FAILED: row-major middle-level interface to cgebak\n" );
00181     }
00182 
00183     /* Initialize input data, call the row-major high-level
00184      * interface to LAPACK routine and check the results */
00185     for( i = 0; i < n; i++ ) {
00186         scale_i[i] = scale[i];
00187     }
00188     for( i = 0; i < ldv*m; i++ ) {
00189         v_i[i] = v_save[i];
00190     }
00191 
00192     /* Init row_major arrays */
00193     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, m, v_i, ldv, v_r, m+2 );
00194     info_i = LAPACKE_cgebak( LAPACK_ROW_MAJOR, job_i, side_i, n_i, ilo_i, ihi_i,
00195                              scale_i, m_i, v_r, ldv_r );
00196 
00197     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, m, v_r, m+2, v_i, ldv );
00198 
00199     failed = compare_cgebak( v, v_i, info, info_i, ldv, m );
00200     if( failed == 0 ) {
00201         printf( "PASSED: row-major high-level interface to cgebak\n" );
00202     } else {
00203         printf( "FAILED: row-major high-level interface to cgebak\n" );
00204     }
00205 
00206     /* Release memory */
00207     if( scale != NULL ) {
00208         LAPACKE_free( scale );
00209     }
00210     if( scale_i != NULL ) {
00211         LAPACKE_free( scale_i );
00212     }
00213     if( v != NULL ) {
00214         LAPACKE_free( v );
00215     }
00216     if( v_i != NULL ) {
00217         LAPACKE_free( v_i );
00218     }
00219     if( v_r != NULL ) {
00220         LAPACKE_free( v_r );
00221     }
00222     if( v_save != NULL ) {
00223         LAPACKE_free( v_save );
00224     }
00225 
00226     return 0;
00227 }
00228 
00229 /* Auxiliary function: cgebak scalar parameters initialization */
00230 static void init_scalars_cgebak( char *job, char *side, lapack_int *n,
00231                                  lapack_int *ilo, lapack_int *ihi,
00232                                  lapack_int *m, lapack_int *ldv )
00233 {
00234     *job = 'B';
00235     *side = 'R';
00236     *n = 4;
00237     *ilo = 2;
00238     *ihi = 3;
00239     *m = 4;
00240     *ldv = 8;
00241 
00242     return;
00243 }
00244 
00245 /* Auxiliary functions: cgebak array parameters initialization */
00246 static void init_scale( lapack_int size, float *scale ) {
00247     lapack_int i;
00248     for( i = 0; i < size; i++ ) {
00249         scale[i] = 0;
00250     }
00251     scale[0] = 3.000000000e+000;
00252     scale[1] = 1.000000000e+000;
00253     scale[2] = 1.000000000e+000;
00254     scale[3] = 1.000000000e+000;
00255 }
00256 static void init_v( lapack_int size, lapack_complex_float *v ) {
00257     lapack_int i;
00258     for( i = 0; i < size; i++ ) {
00259         v[i] = lapack_make_complex_float( 0.0f, 0.0f );
00260     }
00261     v[0] = lapack_make_complex_float( 1.000000000e+000, 0.000000000e+000 );
00262     v[8] = lapack_make_complex_float( 9.889337420e-001, 1.106624212e-002 );
00263     v[16] = lapack_make_complex_float( -3.104490042e-001, -6.895509958e-001 );
00264     v[24] = lapack_make_complex_float( 7.768256664e-001, 2.231743932e-001 );
00265     v[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00266     v[9] = lapack_make_complex_float( -1.015302986e-001, -2.538260305e-004 );
00267     v[17] = lapack_make_complex_float( -4.574148655e-001, 9.666460566e-003 );
00268     v[25] = lapack_make_complex_float( -2.071938366e-001, -2.450199276e-001 );
00269     v[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00270     v[10] = lapack_make_complex_float( 9.340759367e-002, 6.294859946e-002 );
00271     v[18] = lapack_make_complex_float( -4.274975955e-001, -2.736344635e-001 );
00272     v[26] = lapack_make_complex_float( -1.188957784e-002, 4.371840060e-001 );
00273     v[3] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00274     v[11] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00275     v[19] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00276     v[27] = lapack_make_complex_float( 1.452103257e-001, 0.000000000e+000 );
00277 }
00278 
00279 /* Auxiliary function: C interface to cgebak results check */
00280 /* Return value: 0 - test is passed, non-zero - test is failed */
00281 static int compare_cgebak( lapack_complex_float *v, lapack_complex_float *v_i,
00282                            lapack_int info, lapack_int info_i, lapack_int ldv,
00283                            lapack_int m )
00284 {
00285     lapack_int i;
00286     int failed = 0;
00287     for( i = 0; i < ldv*m; i++ ) {
00288         failed += compare_complex_floats(v[i],v_i[i]);
00289     }
00290     failed += (info == info_i) ? 0 : 1;
00291     if( info != 0 || info_i != 0 ) {
00292         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00293     }
00294 
00295     return failed;
00296 }


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