cunghr_2.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 * cunghr_2 is the test program for the C interface to LAPACK
00036 * routine cunghr
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_cunghr( lapack_int *n, lapack_int *ilo,
00055                                  lapack_int *ihi, lapack_int *lda,
00056                                  lapack_int *lwork );
00057 static void init_a( lapack_int size, lapack_complex_float *a );
00058 static void init_tau( lapack_int size, lapack_complex_float *tau );
00059 static void init_work( lapack_int size, lapack_complex_float *work );
00060 static int compare_cunghr( lapack_complex_float *a, lapack_complex_float *a_i,
00061                            lapack_int info, lapack_int info_i, lapack_int lda,
00062                            lapack_int n );
00063 
00064 int main(void)
00065 {
00066     /* Local scalars */
00067     lapack_int n, n_i;
00068     lapack_int ilo, ilo_i;
00069     lapack_int ihi, ihi_i;
00070     lapack_int lda, lda_i;
00071     lapack_int lda_r;
00072     lapack_int lwork, lwork_i;
00073     lapack_int info, info_i;
00074     lapack_int i;
00075     int failed;
00076 
00077     /* Local arrays */
00078     lapack_complex_float *a = NULL, *a_i = NULL;
00079     lapack_complex_float *tau = NULL, *tau_i = NULL;
00080     lapack_complex_float *work = NULL, *work_i = NULL;
00081     lapack_complex_float *a_save = NULL;
00082     lapack_complex_float *a_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_cunghr( &n, &ilo, &ihi, &lda, &lwork );
00086     lda_r = n+2;
00087     n_i = n;
00088     ilo_i = ilo;
00089     ihi_i = ihi;
00090     lda_i = lda;
00091     lwork_i = lwork;
00092 
00093     /* Allocate memory for the LAPACK routine arrays */
00094     a = (lapack_complex_float *)
00095         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00096     tau = (lapack_complex_float *)
00097         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00098     work = (lapack_complex_float *)
00099         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00100 
00101     /* Allocate memory for the C interface function arrays */
00102     a_i = (lapack_complex_float *)
00103         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00104     tau_i = (lapack_complex_float *)
00105         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00106     work_i = (lapack_complex_float *)
00107         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00108 
00109     /* Allocate memory for the backup arrays */
00110     a_save = (lapack_complex_float *)
00111         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00112 
00113     /* Allocate memory for the row-major arrays */
00114     a_r = (lapack_complex_float *)
00115         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00116 
00117     /* Initialize input arrays */
00118     init_a( lda*n, a );
00119     init_tau( (n-1), tau );
00120     init_work( lwork, work );
00121 
00122     /* Backup the ouptut arrays */
00123     for( i = 0; i < lda*n; i++ ) {
00124         a_save[i] = a[i];
00125     }
00126 
00127     /* Call the LAPACK routine */
00128     cunghr_( &n, &ilo, &ihi, a, &lda, tau, work, &lwork, &info );
00129 
00130     /* Initialize input data, call the column-major middle-level
00131      * interface to LAPACK routine and check the results */
00132     for( i = 0; i < lda*n; i++ ) {
00133         a_i[i] = a_save[i];
00134     }
00135     for( i = 0; i < (n-1); i++ ) {
00136         tau_i[i] = tau[i];
00137     }
00138     for( i = 0; i < lwork; i++ ) {
00139         work_i[i] = work[i];
00140     }
00141     info_i = LAPACKE_cunghr_work( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i,
00142                                   lda_i, tau_i, work_i, lwork_i );
00143 
00144     failed = compare_cunghr( a, a_i, info, info_i, lda, n );
00145     if( failed == 0 ) {
00146         printf( "PASSED: column-major middle-level interface to cunghr\n" );
00147     } else {
00148         printf( "FAILED: column-major middle-level interface to cunghr\n" );
00149     }
00150 
00151     /* Initialize input data, call the column-major high-level
00152      * interface to LAPACK routine and check the results */
00153     for( i = 0; i < lda*n; i++ ) {
00154         a_i[i] = a_save[i];
00155     }
00156     for( i = 0; i < (n-1); i++ ) {
00157         tau_i[i] = tau[i];
00158     }
00159     for( i = 0; i < lwork; i++ ) {
00160         work_i[i] = work[i];
00161     }
00162     info_i = LAPACKE_cunghr( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i, lda_i,
00163                              tau_i );
00164 
00165     failed = compare_cunghr( a, a_i, info, info_i, lda, n );
00166     if( failed == 0 ) {
00167         printf( "PASSED: column-major high-level interface to cunghr\n" );
00168     } else {
00169         printf( "FAILED: column-major high-level interface to cunghr\n" );
00170     }
00171 
00172     /* Initialize input data, call the row-major middle-level
00173      * interface to LAPACK routine and check the results */
00174     for( i = 0; i < lda*n; i++ ) {
00175         a_i[i] = a_save[i];
00176     }
00177     for( i = 0; i < (n-1); i++ ) {
00178         tau_i[i] = tau[i];
00179     }
00180     for( i = 0; i < lwork; i++ ) {
00181         work_i[i] = work[i];
00182     }
00183 
00184     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00185     info_i = LAPACKE_cunghr_work( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r,
00186                                   lda_r, tau_i, work_i, lwork_i );
00187 
00188     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00189 
00190     failed = compare_cunghr( a, a_i, info, info_i, lda, n );
00191     if( failed == 0 ) {
00192         printf( "PASSED: row-major middle-level interface to cunghr\n" );
00193     } else {
00194         printf( "FAILED: row-major middle-level interface to cunghr\n" );
00195     }
00196 
00197     /* Initialize input data, call the row-major high-level
00198      * interface to LAPACK routine and check the results */
00199     for( i = 0; i < lda*n; i++ ) {
00200         a_i[i] = a_save[i];
00201     }
00202     for( i = 0; i < (n-1); i++ ) {
00203         tau_i[i] = tau[i];
00204     }
00205     for( i = 0; i < lwork; i++ ) {
00206         work_i[i] = work[i];
00207     }
00208 
00209     /* Init row_major arrays */
00210     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00211     info_i = LAPACKE_cunghr( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r, lda_r,
00212                              tau_i );
00213 
00214     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00215 
00216     failed = compare_cunghr( a, a_i, info, info_i, lda, n );
00217     if( failed == 0 ) {
00218         printf( "PASSED: row-major high-level interface to cunghr\n" );
00219     } else {
00220         printf( "FAILED: row-major high-level interface to cunghr\n" );
00221     }
00222 
00223     /* Release memory */
00224     if( a != NULL ) {
00225         LAPACKE_free( a );
00226     }
00227     if( a_i != NULL ) {
00228         LAPACKE_free( a_i );
00229     }
00230     if( a_r != NULL ) {
00231         LAPACKE_free( a_r );
00232     }
00233     if( a_save != NULL ) {
00234         LAPACKE_free( a_save );
00235     }
00236     if( tau != NULL ) {
00237         LAPACKE_free( tau );
00238     }
00239     if( tau_i != NULL ) {
00240         LAPACKE_free( tau_i );
00241     }
00242     if( work != NULL ) {
00243         LAPACKE_free( work );
00244     }
00245     if( work_i != NULL ) {
00246         LAPACKE_free( work_i );
00247     }
00248 
00249     return 0;
00250 }
00251 
00252 /* Auxiliary function: cunghr scalar parameters initialization */
00253 static void init_scalars_cunghr( lapack_int *n, lapack_int *ilo,
00254                                  lapack_int *ihi, lapack_int *lda,
00255                                  lapack_int *lwork )
00256 {
00257     *n = 4;
00258     *ilo = 1;
00259     *ihi = 4;
00260     *lda = 8;
00261     *lwork = 448;
00262 
00263     return;
00264 }
00265 
00266 /* Auxiliary functions: cunghr array parameters initialization */
00267 static void init_a( lapack_int size, lapack_complex_float *a ) {
00268     lapack_int i;
00269     for( i = 0; i < size; i++ ) {
00270         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00271     }
00272     a[0] = lapack_make_complex_float( -3.970000029e+000, -5.039999962e+000 );
00273     a[8] = lapack_make_complex_float( -1.131804943e+000, -2.569304705e+000 );
00274     a[16] = lapack_make_complex_float( -4.602741241e+000, -1.426316500e-001 );
00275     a[24] = lapack_make_complex_float( -1.424912333e+000, 1.732983828e+000 );
00276     a[1] = lapack_make_complex_float( -5.479653358e+000, 0.000000000e+000 );
00277     a[9] = lapack_make_complex_float( 1.858472466e+000, -1.550180435e+000 );
00278     a[17] = lapack_make_complex_float( 4.414464474e+000, -7.638237476e-001 );
00279     a[25] = lapack_make_complex_float( -4.805260897e-001, -1.197600603e+000 );
00280     a[2] = lapack_make_complex_float( 6.932221651e-001, -4.828752279e-001 );
00281     a[10] = lapack_make_complex_float( 6.267275810e+000, 0.000000000e+000 );
00282     a[18] = lapack_make_complex_float( -4.503800869e-001, -2.898204327e-002 );
00283     a[26] = lapack_make_complex_float( -1.346683741e+000, 1.657924891e+000 );
00284     a[3] = lapack_make_complex_float( -2.112946808e-001, 8.644121885e-002 );
00285     a[11] = lapack_make_complex_float( 1.242147088e-001, -2.289276123e-001 );
00286     a[19] = lapack_make_complex_float( -3.499985933e+000, 0.000000000e+000 );
00287     a[27] = lapack_make_complex_float( 2.561908484e+000, -3.370837450e+000 );
00288 }
00289 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00290     lapack_int i;
00291     for( i = 0; i < size; i++ ) {
00292         tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00293     }
00294     tau[0] = lapack_make_complex_float( 1.062047720e+000, -2.737399340e-001 );
00295     tau[1] = lapack_make_complex_float( 1.805921316e+000, 3.479066789e-001 );
00296     tau[2] = lapack_make_complex_float( 1.181823134e+000, 9.833312631e-001 );
00297 }
00298 static void init_work( lapack_int size, lapack_complex_float *work ) {
00299     lapack_int i;
00300     for( i = 0; i < size; i++ ) {
00301         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00302     }
00303 }
00304 
00305 /* Auxiliary function: C interface to cunghr results check */
00306 /* Return value: 0 - test is passed, non-zero - test is failed */
00307 static int compare_cunghr( lapack_complex_float *a, lapack_complex_float *a_i,
00308                            lapack_int info, lapack_int info_i, lapack_int lda,
00309                            lapack_int n )
00310 {
00311     lapack_int i;
00312     int failed = 0;
00313     for( i = 0; i < lda*n; i++ ) {
00314         failed += compare_complex_floats(a[i],a_i[i]);
00315     }
00316     failed += (info == info_i) ? 0 : 1;
00317     if( info != 0 || info_i != 0 ) {
00318         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00319     }
00320 
00321     return failed;
00322 }


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