cpteqr_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 * cpteqr_1 is the test program for the C interface to LAPACK
00036 * routine cpteqr
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_cpteqr( char *compz, lapack_int *n, lapack_int *ldz );
00055 static void init_d( lapack_int size, float *d );
00056 static void init_e( lapack_int size, float *e );
00057 static void init_z( lapack_int size, lapack_complex_float *z );
00058 static void init_work( lapack_int size, float *work );
00059 static int compare_cpteqr( float *d, float *d_i, float *e, float *e_i,
00060                            lapack_complex_float *z, lapack_complex_float *z_i,
00061                            lapack_int info, lapack_int info_i, lapack_int ldz,
00062                            lapack_int n );
00063 
00064 int main(void)
00065 {
00066     /* Local scalars */
00067     char compz, compz_i;
00068     lapack_int n, n_i;
00069     lapack_int ldz, ldz_i;
00070     lapack_int ldz_r;
00071     lapack_int info, info_i;
00072     lapack_int i;
00073     int failed;
00074 
00075     /* Local arrays */
00076     float *d = NULL, *d_i = NULL;
00077     float *e = NULL, *e_i = NULL;
00078     lapack_complex_float *z = NULL, *z_i = NULL;
00079     float *work = NULL, *work_i = NULL;
00080     float *d_save = NULL;
00081     float *e_save = NULL;
00082     lapack_complex_float *z_save = NULL;
00083     lapack_complex_float *z_r = NULL;
00084 
00085     /* Iniitialize the scalar parameters */
00086     init_scalars_cpteqr( &compz, &n, &ldz );
00087     ldz_r = n+2;
00088     compz_i = compz;
00089     n_i = n;
00090     ldz_i = ldz;
00091 
00092     /* Allocate memory for the LAPACK routine arrays */
00093     d = (float *)LAPACKE_malloc( n * sizeof(float) );
00094     e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00095     z = (lapack_complex_float *)
00096         LAPACKE_malloc( ldz*n * sizeof(lapack_complex_float) );
00097     work = (float *)LAPACKE_malloc( 4*n * sizeof(float) );
00098 
00099     /* Allocate memory for the C interface function arrays */
00100     d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00101     e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00102     z_i = (lapack_complex_float *)
00103         LAPACKE_malloc( ldz*n * sizeof(lapack_complex_float) );
00104     work_i = (float *)LAPACKE_malloc( 4*n * sizeof(float) );
00105 
00106     /* Allocate memory for the backup arrays */
00107     d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00108     e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00109     z_save = (lapack_complex_float *)
00110         LAPACKE_malloc( ldz*n * sizeof(lapack_complex_float) );
00111 
00112     /* Allocate memory for the row-major arrays */
00113     z_r = (lapack_complex_float *)
00114         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00115 
00116     /* Initialize input arrays */
00117     init_d( n, d );
00118     init_e( (n-1), e );
00119     init_z( ldz*n, z );
00120     init_work( 4*n, work );
00121 
00122     /* Backup the ouptut arrays */
00123     for( i = 0; i < n; i++ ) {
00124         d_save[i] = d[i];
00125     }
00126     for( i = 0; i < (n-1); i++ ) {
00127         e_save[i] = e[i];
00128     }
00129     for( i = 0; i < ldz*n; i++ ) {
00130         z_save[i] = z[i];
00131     }
00132 
00133     /* Call the LAPACK routine */
00134     cpteqr_( &compz, &n, d, e, z, &ldz, work, &info );
00135 
00136     /* Initialize input data, call the column-major middle-level
00137      * interface to LAPACK routine and check the results */
00138     for( i = 0; i < n; i++ ) {
00139         d_i[i] = d_save[i];
00140     }
00141     for( i = 0; i < (n-1); i++ ) {
00142         e_i[i] = e_save[i];
00143     }
00144     for( i = 0; i < ldz*n; i++ ) {
00145         z_i[i] = z_save[i];
00146     }
00147     for( i = 0; i < 4*n; i++ ) {
00148         work_i[i] = work[i];
00149     }
00150     info_i = LAPACKE_cpteqr_work( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00151                                   ldz_i, work_i );
00152 
00153     failed = compare_cpteqr( d, d_i, e, e_i, z, z_i, info, info_i, ldz, n );
00154     if( failed == 0 ) {
00155         printf( "PASSED: column-major middle-level interface to cpteqr\n" );
00156     } else {
00157         printf( "FAILED: column-major middle-level interface to cpteqr\n" );
00158     }
00159 
00160     /* Initialize input data, call the column-major high-level
00161      * interface to LAPACK routine and check the results */
00162     for( i = 0; i < n; i++ ) {
00163         d_i[i] = d_save[i];
00164     }
00165     for( i = 0; i < (n-1); i++ ) {
00166         e_i[i] = e_save[i];
00167     }
00168     for( i = 0; i < ldz*n; i++ ) {
00169         z_i[i] = z_save[i];
00170     }
00171     for( i = 0; i < 4*n; i++ ) {
00172         work_i[i] = work[i];
00173     }
00174     info_i = LAPACKE_cpteqr( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00175                              ldz_i );
00176 
00177     failed = compare_cpteqr( d, d_i, e, e_i, z, z_i, info, info_i, ldz, n );
00178     if( failed == 0 ) {
00179         printf( "PASSED: column-major high-level interface to cpteqr\n" );
00180     } else {
00181         printf( "FAILED: column-major high-level interface to cpteqr\n" );
00182     }
00183 
00184     /* Initialize input data, call the row-major middle-level
00185      * interface to LAPACK routine and check the results */
00186     for( i = 0; i < n; i++ ) {
00187         d_i[i] = d_save[i];
00188     }
00189     for( i = 0; i < (n-1); i++ ) {
00190         e_i[i] = e_save[i];
00191     }
00192     for( i = 0; i < ldz*n; i++ ) {
00193         z_i[i] = z_save[i];
00194     }
00195     for( i = 0; i < 4*n; i++ ) {
00196         work_i[i] = work[i];
00197     }
00198 
00199     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00200     info_i = LAPACKE_cpteqr_work( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00201                                   ldz_r, work_i );
00202 
00203     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00204 
00205     failed = compare_cpteqr( d, d_i, e, e_i, z, z_i, info, info_i, ldz, n );
00206     if( failed == 0 ) {
00207         printf( "PASSED: row-major middle-level interface to cpteqr\n" );
00208     } else {
00209         printf( "FAILED: row-major middle-level interface to cpteqr\n" );
00210     }
00211 
00212     /* Initialize input data, call the row-major high-level
00213      * interface to LAPACK routine and check the results */
00214     for( i = 0; i < n; i++ ) {
00215         d_i[i] = d_save[i];
00216     }
00217     for( i = 0; i < (n-1); i++ ) {
00218         e_i[i] = e_save[i];
00219     }
00220     for( i = 0; i < ldz*n; i++ ) {
00221         z_i[i] = z_save[i];
00222     }
00223     for( i = 0; i < 4*n; i++ ) {
00224         work_i[i] = work[i];
00225     }
00226 
00227     /* Init row_major arrays */
00228     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00229     info_i = LAPACKE_cpteqr( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00230                              ldz_r );
00231 
00232     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00233 
00234     failed = compare_cpteqr( d, d_i, e, e_i, z, z_i, info, info_i, ldz, n );
00235     if( failed == 0 ) {
00236         printf( "PASSED: row-major high-level interface to cpteqr\n" );
00237     } else {
00238         printf( "FAILED: row-major high-level interface to cpteqr\n" );
00239     }
00240 
00241     /* Release memory */
00242     if( d != NULL ) {
00243         LAPACKE_free( d );
00244     }
00245     if( d_i != NULL ) {
00246         LAPACKE_free( d_i );
00247     }
00248     if( d_save != NULL ) {
00249         LAPACKE_free( d_save );
00250     }
00251     if( e != NULL ) {
00252         LAPACKE_free( e );
00253     }
00254     if( e_i != NULL ) {
00255         LAPACKE_free( e_i );
00256     }
00257     if( e_save != NULL ) {
00258         LAPACKE_free( e_save );
00259     }
00260     if( z != NULL ) {
00261         LAPACKE_free( z );
00262     }
00263     if( z_i != NULL ) {
00264         LAPACKE_free( z_i );
00265     }
00266     if( z_r != NULL ) {
00267         LAPACKE_free( z_r );
00268     }
00269     if( z_save != NULL ) {
00270         LAPACKE_free( z_save );
00271     }
00272     if( work != NULL ) {
00273         LAPACKE_free( work );
00274     }
00275     if( work_i != NULL ) {
00276         LAPACKE_free( work_i );
00277     }
00278 
00279     return 0;
00280 }
00281 
00282 /* Auxiliary function: cpteqr scalar parameters initialization */
00283 static void init_scalars_cpteqr( char *compz, lapack_int *n, lapack_int *ldz )
00284 {
00285     *compz = 'V';
00286     *n = 4;
00287     *ldz = 8;
00288 
00289     return;
00290 }
00291 
00292 /* Auxiliary functions: cpteqr array parameters initialization */
00293 static void init_d( lapack_int size, float *d ) {
00294     lapack_int i;
00295     for( i = 0; i < size; i++ ) {
00296         d[i] = 0;
00297     }
00298     d[0] = 6.019999981e+000;
00299     d[1] = 2.738845587e+000;
00300     d[2] = 5.173556328e+000;
00301     d[3] = 2.467597485e+000;
00302 }
00303 static void init_e( lapack_int size, float *e ) {
00304     lapack_int i;
00305     for( i = 0; i < size; i++ ) {
00306         e[i] = 0;
00307     }
00308     e[0] = 2.742389441e+000;
00309     e[1] = 1.835962176e+000;
00310     e[2] = 1.695211291e+000;
00311 }
00312 static void init_z( lapack_int size, lapack_complex_float *z ) {
00313     lapack_int i;
00314     for( i = 0; i < size; i++ ) {
00315         z[i] = lapack_make_complex_float( 0.0f, 0.0f );
00316     }
00317     z[0] = lapack_make_complex_float( 1.000000000e+000, 0.000000000e+000 );
00318     z[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00319     z[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00320     z[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00321     z[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00322     z[9] = lapack_make_complex_float( -1.640905142e-001, -9.116137773e-002 );
00323     z[17] = lapack_make_complex_float( 4.492193833e-002, -1.991468519e-001 );
00324     z[25] = lapack_make_complex_float( -7.606251240e-001, -5.869720578e-001 );
00325     z[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00326     z[10] = lapack_make_complex_float( -4.740391970e-001, -6.344832182e-001 );
00327     z[18] = lapack_make_complex_float( -4.067592323e-001, 4.544042349e-001 );
00328     z[26] = lapack_make_complex_float( 2.193787694e-002, 1.733219624e-002 );
00329     z[3] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00330     z[11] = lapack_make_complex_float( 5.287360549e-001, 2.406660616e-001 );
00331     z[19] = lapack_make_complex_float( -1.787167192e-001, 7.446116805e-001 );
00332     z[27] = lapack_make_complex_float( -2.225494087e-001, -1.631059647e-001 );
00333 }
00334 static void init_work( lapack_int size, float *work ) {
00335     lapack_int i;
00336     for( i = 0; i < size; i++ ) {
00337         work[i] = 0;
00338     }
00339 }
00340 
00341 /* Auxiliary function: C interface to cpteqr results check */
00342 /* Return value: 0 - test is passed, non-zero - test is failed */
00343 static int compare_cpteqr( float *d, float *d_i, float *e, float *e_i,
00344                            lapack_complex_float *z, lapack_complex_float *z_i,
00345                            lapack_int info, lapack_int info_i, lapack_int ldz,
00346                            lapack_int n )
00347 {
00348     lapack_int i;
00349     int failed = 0;
00350     for( i = 0; i < n; i++ ) {
00351         failed += compare_floats(d[i],d_i[i]);
00352     }
00353     for( i = 0; i < (n-1); i++ ) {
00354         failed += compare_floats(e[i],e_i[i]);
00355     }
00356     for( i = 0; i < ldz*n; i++ ) {
00357         failed += compare_complex_floats(z[i],z_i[i]);
00358     }
00359     failed += (info == info_i) ? 0 : 1;
00360     if( info != 0 || info_i != 0 ) {
00361         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00362     }
00363 
00364     return failed;
00365 }


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