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


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