chseqr_3.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 * chseqr_3 is the test program for the C interface to LAPACK
00036 * routine chseqr
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_chseqr( char *job, char *compz, lapack_int *n,
00055                                  lapack_int *ilo, lapack_int *ihi,
00056                                  lapack_int *ldh, lapack_int *ldz,
00057                                  lapack_int *lwork );
00058 static void init_h( lapack_int size, lapack_complex_float *h );
00059 static void init_w( lapack_int size, lapack_complex_float *w );
00060 static void init_z( lapack_int size, lapack_complex_float *z );
00061 static void init_work( lapack_int size, lapack_complex_float *work );
00062 static int compare_chseqr( lapack_complex_float *h, lapack_complex_float *h_i,
00063                            lapack_complex_float *w, lapack_complex_float *w_i,
00064                            lapack_complex_float *z, lapack_complex_float *z_i,
00065                            lapack_int info, lapack_int info_i, char compz,
00066                            lapack_int ldh, lapack_int ldz, lapack_int n );
00067 
00068 int main(void)
00069 {
00070     /* Local scalars */
00071     char job, job_i;
00072     char compz, compz_i;
00073     lapack_int n, n_i;
00074     lapack_int ilo, ilo_i;
00075     lapack_int ihi, ihi_i;
00076     lapack_int ldh, ldh_i;
00077     lapack_int ldh_r;
00078     lapack_int ldz, ldz_i;
00079     lapack_int ldz_r;
00080     lapack_int lwork, lwork_i;
00081     lapack_int info, info_i;
00082     lapack_int i;
00083     int failed;
00084 
00085     /* Local arrays */
00086     lapack_complex_float *h = NULL, *h_i = NULL;
00087     lapack_complex_float *w = NULL, *w_i = NULL;
00088     lapack_complex_float *z = NULL, *z_i = NULL;
00089     lapack_complex_float *work = NULL, *work_i = NULL;
00090     lapack_complex_float *h_save = NULL;
00091     lapack_complex_float *w_save = NULL;
00092     lapack_complex_float *z_save = NULL;
00093     lapack_complex_float *h_r = NULL;
00094     lapack_complex_float *z_r = NULL;
00095 
00096     /* Iniitialize the scalar parameters */
00097     init_scalars_chseqr( &job, &compz, &n, &ilo, &ihi, &ldh, &ldz, &lwork );
00098     ldh_r = n+2;
00099     ldz_r = n+2;
00100     job_i = job;
00101     compz_i = compz;
00102     n_i = n;
00103     ilo_i = ilo;
00104     ihi_i = ihi;
00105     ldh_i = ldh;
00106     ldz_i = ldz;
00107     lwork_i = lwork;
00108 
00109     /* Allocate memory for the LAPACK routine arrays */
00110     h = (lapack_complex_float *)
00111         LAPACKE_malloc( ldh*n * sizeof(lapack_complex_float) );
00112     w = (lapack_complex_float *)
00113         LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00114     z = (lapack_complex_float *)
00115         LAPACKE_malloc( ldz*n * sizeof(lapack_complex_float) );
00116     work = (lapack_complex_float *)
00117         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00118 
00119     /* Allocate memory for the C interface function arrays */
00120     h_i = (lapack_complex_float *)
00121         LAPACKE_malloc( ldh*n * sizeof(lapack_complex_float) );
00122     w_i = (lapack_complex_float *)
00123         LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00124     z_i = (lapack_complex_float *)
00125         LAPACKE_malloc( ldz*n * sizeof(lapack_complex_float) );
00126     work_i = (lapack_complex_float *)
00127         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00128 
00129     /* Allocate memory for the backup arrays */
00130     h_save = (lapack_complex_float *)
00131         LAPACKE_malloc( ldh*n * sizeof(lapack_complex_float) );
00132     w_save = (lapack_complex_float *)
00133         LAPACKE_malloc( n * sizeof(lapack_complex_float) );
00134     z_save = (lapack_complex_float *)
00135         LAPACKE_malloc( ldz*n * sizeof(lapack_complex_float) );
00136 
00137     /* Allocate memory for the row-major arrays */
00138     h_r = (lapack_complex_float *)
00139         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00140     z_r = (lapack_complex_float *)
00141         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00142 
00143     /* Initialize input arrays */
00144     init_h( ldh*n, h );
00145     init_w( n, w );
00146     init_z( ldz*n, z );
00147     init_work( lwork, work );
00148 
00149     /* Backup the ouptut arrays */
00150     for( i = 0; i < ldh*n; i++ ) {
00151         h_save[i] = h[i];
00152     }
00153     for( i = 0; i < n; i++ ) {
00154         w_save[i] = w[i];
00155     }
00156     for( i = 0; i < ldz*n; i++ ) {
00157         z_save[i] = z[i];
00158     }
00159 
00160     /* Call the LAPACK routine */
00161     chseqr_( &job, &compz, &n, &ilo, &ihi, h, &ldh, w, z, &ldz, work, &lwork,
00162              &info );
00163 
00164     /* Initialize input data, call the column-major middle-level
00165      * interface to LAPACK routine and check the results */
00166     for( i = 0; i < ldh*n; i++ ) {
00167         h_i[i] = h_save[i];
00168     }
00169     for( i = 0; i < n; i++ ) {
00170         w_i[i] = w_save[i];
00171     }
00172     for( i = 0; i < ldz*n; i++ ) {
00173         z_i[i] = z_save[i];
00174     }
00175     for( i = 0; i < lwork; i++ ) {
00176         work_i[i] = work[i];
00177     }
00178     info_i = LAPACKE_chseqr_work( LAPACK_COL_MAJOR, job_i, compz_i, n_i, ilo_i,
00179                                   ihi_i, h_i, ldh_i, w_i, z_i, ldz_i, work_i,
00180                                   lwork_i );
00181 
00182     failed = compare_chseqr( h, h_i, w, w_i, z, z_i, info, info_i, compz, ldh,
00183                              ldz, n );
00184     if( failed == 0 ) {
00185         printf( "PASSED: column-major middle-level interface to chseqr\n" );
00186     } else {
00187         printf( "FAILED: column-major middle-level interface to chseqr\n" );
00188     }
00189 
00190     /* Initialize input data, call the column-major high-level
00191      * interface to LAPACK routine and check the results */
00192     for( i = 0; i < ldh*n; i++ ) {
00193         h_i[i] = h_save[i];
00194     }
00195     for( i = 0; i < n; i++ ) {
00196         w_i[i] = w_save[i];
00197     }
00198     for( i = 0; i < ldz*n; i++ ) {
00199         z_i[i] = z_save[i];
00200     }
00201     for( i = 0; i < lwork; i++ ) {
00202         work_i[i] = work[i];
00203     }
00204     info_i = LAPACKE_chseqr( LAPACK_COL_MAJOR, job_i, compz_i, n_i, ilo_i,
00205                              ihi_i, h_i, ldh_i, w_i, z_i, ldz_i );
00206 
00207     failed = compare_chseqr( h, h_i, w, w_i, z, z_i, info, info_i, compz, ldh,
00208                              ldz, n );
00209     if( failed == 0 ) {
00210         printf( "PASSED: column-major high-level interface to chseqr\n" );
00211     } else {
00212         printf( "FAILED: column-major high-level interface to chseqr\n" );
00213     }
00214 
00215     /* Initialize input data, call the row-major middle-level
00216      * interface to LAPACK routine and check the results */
00217     for( i = 0; i < ldh*n; i++ ) {
00218         h_i[i] = h_save[i];
00219     }
00220     for( i = 0; i < n; i++ ) {
00221         w_i[i] = w_save[i];
00222     }
00223     for( i = 0; i < ldz*n; i++ ) {
00224         z_i[i] = z_save[i];
00225     }
00226     for( i = 0; i < lwork; i++ ) {
00227         work_i[i] = work[i];
00228     }
00229 
00230     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, h_i, ldh, h_r, n+2 );
00231     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00232         LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00233     }
00234     info_i = LAPACKE_chseqr_work( LAPACK_ROW_MAJOR, job_i, compz_i, n_i, ilo_i,
00235                                   ihi_i, h_r, ldh_r, w_i, z_r, ldz_r, work_i,
00236                                   lwork_i );
00237 
00238     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, h_r, n+2, h_i, ldh );
00239     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00240         LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00241     }
00242 
00243     failed = compare_chseqr( h, h_i, w, w_i, z, z_i, info, info_i, compz, ldh,
00244                              ldz, n );
00245     if( failed == 0 ) {
00246         printf( "PASSED: row-major middle-level interface to chseqr\n" );
00247     } else {
00248         printf( "FAILED: row-major middle-level interface to chseqr\n" );
00249     }
00250 
00251     /* Initialize input data, call the row-major high-level
00252      * interface to LAPACK routine and check the results */
00253     for( i = 0; i < ldh*n; i++ ) {
00254         h_i[i] = h_save[i];
00255     }
00256     for( i = 0; i < n; i++ ) {
00257         w_i[i] = w_save[i];
00258     }
00259     for( i = 0; i < ldz*n; i++ ) {
00260         z_i[i] = z_save[i];
00261     }
00262     for( i = 0; i < lwork; i++ ) {
00263         work_i[i] = work[i];
00264     }
00265 
00266     /* Init row_major arrays */
00267     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, h_i, ldh, h_r, n+2 );
00268     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00269         LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00270     }
00271     info_i = LAPACKE_chseqr( LAPACK_ROW_MAJOR, job_i, compz_i, n_i, ilo_i,
00272                              ihi_i, h_r, ldh_r, w_i, z_r, ldz_r );
00273 
00274     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, h_r, n+2, h_i, ldh );
00275     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00276         LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00277     }
00278 
00279     failed = compare_chseqr( h, h_i, w, w_i, z, z_i, info, info_i, compz, ldh,
00280                              ldz, n );
00281     if( failed == 0 ) {
00282         printf( "PASSED: row-major high-level interface to chseqr\n" );
00283     } else {
00284         printf( "FAILED: row-major high-level interface to chseqr\n" );
00285     }
00286 
00287     /* Release memory */
00288     if( h != NULL ) {
00289         LAPACKE_free( h );
00290     }
00291     if( h_i != NULL ) {
00292         LAPACKE_free( h_i );
00293     }
00294     if( h_r != NULL ) {
00295         LAPACKE_free( h_r );
00296     }
00297     if( h_save != NULL ) {
00298         LAPACKE_free( h_save );
00299     }
00300     if( w != NULL ) {
00301         LAPACKE_free( w );
00302     }
00303     if( w_i != NULL ) {
00304         LAPACKE_free( w_i );
00305     }
00306     if( w_save != NULL ) {
00307         LAPACKE_free( w_save );
00308     }
00309     if( z != NULL ) {
00310         LAPACKE_free( z );
00311     }
00312     if( z_i != NULL ) {
00313         LAPACKE_free( z_i );
00314     }
00315     if( z_r != NULL ) {
00316         LAPACKE_free( z_r );
00317     }
00318     if( z_save != NULL ) {
00319         LAPACKE_free( z_save );
00320     }
00321     if( work != NULL ) {
00322         LAPACKE_free( work );
00323     }
00324     if( work_i != NULL ) {
00325         LAPACKE_free( work_i );
00326     }
00327 
00328     return 0;
00329 }
00330 
00331 /* Auxiliary function: chseqr scalar parameters initialization */
00332 static void init_scalars_chseqr( char *job, char *compz, lapack_int *n,
00333                                  lapack_int *ilo, lapack_int *ihi,
00334                                  lapack_int *ldh, lapack_int *ldz,
00335                                  lapack_int *lwork )
00336 {
00337     *job = 'S';
00338     *compz = 'V';
00339     *n = 4;
00340     *ilo = 1;
00341     *ihi = 4;
00342     *ldh = 8;
00343     *ldz = 8;
00344     *lwork = 448;
00345 
00346     return;
00347 }
00348 
00349 /* Auxiliary functions: chseqr array parameters initialization */
00350 static void init_h( lapack_int size, lapack_complex_float *h ) {
00351     lapack_int i;
00352     for( i = 0; i < size; i++ ) {
00353         h[i] = lapack_make_complex_float( 0.0f, 0.0f );
00354     }
00355     h[0] = lapack_make_complex_float( -3.970000029e+000, -5.039999962e+000 );
00356     h[8] = lapack_make_complex_float( -1.131804943e+000, -2.569304705e+000 );
00357     h[16] = lapack_make_complex_float( -4.602741241e+000, -1.426316500e-001 );
00358     h[24] = lapack_make_complex_float( -1.424912333e+000, 1.732983828e+000 );
00359     h[1] = lapack_make_complex_float( -5.479653358e+000, 0.000000000e+000 );
00360     h[9] = lapack_make_complex_float( 1.858472466e+000, -1.550180435e+000 );
00361     h[17] = lapack_make_complex_float( 4.414464474e+000, -7.638237476e-001 );
00362     h[25] = lapack_make_complex_float( -4.805260897e-001, -1.197600603e+000 );
00363     h[2] = lapack_make_complex_float( 6.932221651e-001, -4.828752279e-001 );
00364     h[10] = lapack_make_complex_float( 6.267275810e+000, 0.000000000e+000 );
00365     h[18] = lapack_make_complex_float( -4.503800869e-001, -2.898204327e-002 );
00366     h[26] = lapack_make_complex_float( -1.346683741e+000, 1.657924891e+000 );
00367     h[3] = lapack_make_complex_float( -2.112946808e-001, 8.644121885e-002 );
00368     h[11] = lapack_make_complex_float( 1.242147088e-001, -2.289276123e-001 );
00369     h[19] = lapack_make_complex_float( -3.499985933e+000, 0.000000000e+000 );
00370     h[27] = lapack_make_complex_float( 2.561908484e+000, -3.370837450e+000 );
00371 }
00372 static void init_w( lapack_int size, lapack_complex_float *w ) {
00373     lapack_int i;
00374     for( i = 0; i < size; i++ ) {
00375         w[i] = lapack_make_complex_float( 0.0f, 0.0f );
00376     }
00377 }
00378 static void init_z( lapack_int size, lapack_complex_float *z ) {
00379     lapack_int i;
00380     for( i = 0; i < size; i++ ) {
00381         z[i] = lapack_make_complex_float( 0.0f, 0.0f );
00382     }
00383     z[0] = lapack_make_complex_float( 1.000000000e+000, 0.000000000e+000 );
00384     z[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00385     z[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00386     z[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00387     z[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00388     z[9] = lapack_make_complex_float( -6.204771996e-002, 2.737399340e-001 );
00389     z[17] = lapack_make_complex_float( 4.994977713e-001, 6.440132260e-001 );
00390     z[25] = lapack_make_complex_float( 4.237119257e-001, -2.782686949e-001 );
00391     z[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00392     z[10] = lapack_make_complex_float( -6.040527821e-001, 7.025991082e-001 );
00393     z[18] = lapack_make_complex_float( -1.486803293e-001, -1.426575333e-001 );
00394     z[26] = lapack_make_complex_float( -2.633657455e-001, -1.722092628e-001 );
00395     z[3] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00396     z[11] = lapack_make_complex_float( 2.007426172e-001, -1.496444941e-001 );
00397     z[19] = lapack_make_complex_float( -4.651779532e-001, 2.773107588e-001 );
00398     z[27] = lapack_make_complex_float( -2.482300401e-001, -7.631506920e-001 );
00399 }
00400 static void init_work( lapack_int size, lapack_complex_float *work ) {
00401     lapack_int i;
00402     for( i = 0; i < size; i++ ) {
00403         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00404     }
00405 }
00406 
00407 /* Auxiliary function: C interface to chseqr results check */
00408 /* Return value: 0 - test is passed, non-zero - test is failed */
00409 static int compare_chseqr( lapack_complex_float *h, lapack_complex_float *h_i,
00410                            lapack_complex_float *w, lapack_complex_float *w_i,
00411                            lapack_complex_float *z, lapack_complex_float *z_i,
00412                            lapack_int info, lapack_int info_i, char compz,
00413                            lapack_int ldh, lapack_int ldz, lapack_int n )
00414 {
00415     lapack_int i;
00416     int failed = 0;
00417     for( i = 0; i < ldh*n; i++ ) {
00418         failed += compare_complex_floats(h[i],h_i[i]);
00419     }
00420     for( i = 0; i < n; i++ ) {
00421         failed += compare_complex_floats(w[i],w_i[i]);
00422     }
00423     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00424         for( i = 0; i < ldz*n; i++ ) {
00425             failed += compare_complex_floats(z[i],z_i[i]);
00426         }
00427     }
00428     failed += (info == info_i) ? 0 : 1;
00429     if( info != 0 || info_i != 0 ) {
00430         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00431     }
00432 
00433     return failed;
00434 }


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