ssteqr_4.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 * ssteqr_4 is the test program for the C interface to LAPACK
00036 * routine ssteqr
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_ssteqr( 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, float *z );
00058 static void init_work( lapack_int size, float *work );
00059 static int compare_ssteqr( float *d, float *d_i, float *e, float *e_i, float *z,
00060                            float *z_i, lapack_int info, lapack_int info_i,
00061                            char compz, 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     float *d = NULL, *d_i = NULL;
00076     float *e = NULL, *e_i = NULL;
00077     float *z = NULL, *z_i = NULL;
00078     float *work = NULL, *work_i = NULL;
00079     float *d_save = NULL;
00080     float *e_save = NULL;
00081     float *z_save = NULL;
00082     float *z_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_ssteqr( &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 = (float *)LAPACKE_malloc( n * sizeof(float) );
00093     e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00094     z = (float *)LAPACKE_malloc( ldz*n * sizeof(float) );
00095     work = (float *)LAPACKE_malloc( ((MAX(1,2*n-2))) * sizeof(float) );
00096 
00097     /* Allocate memory for the C interface function arrays */
00098     d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00099     e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00100     z_i = (float *)LAPACKE_malloc( ldz*n * sizeof(float) );
00101     work_i = (float *)LAPACKE_malloc( ((MAX(1,2*n-2))) * sizeof(float) );
00102 
00103     /* Allocate memory for the backup arrays */
00104     d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00105     e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00106     z_save = (float *)LAPACKE_malloc( ldz*n * sizeof(float) );
00107 
00108     /* Allocate memory for the row-major arrays */
00109     z_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
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( (MAX(1,2*n-2)), 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     ssteqr_( &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 < (MAX(1,2*n-2)); i++ ) {
00143         work_i[i] = work[i];
00144     }
00145     info_i = LAPACKE_ssteqr_work( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00146                                   ldz_i, work_i );
00147 
00148     failed = compare_ssteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00149                              n );
00150     if( failed == 0 ) {
00151         printf( "PASSED: column-major middle-level interface to ssteqr\n" );
00152     } else {
00153         printf( "FAILED: column-major middle-level interface to ssteqr\n" );
00154     }
00155 
00156     /* Initialize input data, call the column-major high-level
00157      * interface to LAPACK routine and check the results */
00158     for( i = 0; i < n; i++ ) {
00159         d_i[i] = d_save[i];
00160     }
00161     for( i = 0; i < (n-1); i++ ) {
00162         e_i[i] = e_save[i];
00163     }
00164     for( i = 0; i < ldz*n; i++ ) {
00165         z_i[i] = z_save[i];
00166     }
00167     for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00168         work_i[i] = work[i];
00169     }
00170     info_i = LAPACKE_ssteqr( LAPACK_COL_MAJOR, compz_i, n_i, d_i, e_i, z_i,
00171                              ldz_i );
00172 
00173     failed = compare_ssteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00174                              n );
00175     if( failed == 0 ) {
00176         printf( "PASSED: column-major high-level interface to ssteqr\n" );
00177     } else {
00178         printf( "FAILED: column-major high-level interface to ssteqr\n" );
00179     }
00180 
00181     /* Initialize input data, call the row-major middle-level
00182      * interface to LAPACK routine and check the results */
00183     for( i = 0; i < n; i++ ) {
00184         d_i[i] = d_save[i];
00185     }
00186     for( i = 0; i < (n-1); i++ ) {
00187         e_i[i] = e_save[i];
00188     }
00189     for( i = 0; i < ldz*n; i++ ) {
00190         z_i[i] = z_save[i];
00191     }
00192     for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00193         work_i[i] = work[i];
00194     }
00195 
00196     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00197         LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00198     }
00199     info_i = LAPACKE_ssteqr_work( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00200                                   ldz_r, work_i );
00201 
00202     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00203         LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00204     }
00205 
00206     failed = compare_ssteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00207                              n );
00208     if( failed == 0 ) {
00209         printf( "PASSED: row-major middle-level interface to ssteqr\n" );
00210     } else {
00211         printf( "FAILED: row-major middle-level interface to ssteqr\n" );
00212     }
00213 
00214     /* Initialize input data, call the row-major high-level
00215      * interface to LAPACK routine and check the results */
00216     for( i = 0; i < n; i++ ) {
00217         d_i[i] = d_save[i];
00218     }
00219     for( i = 0; i < (n-1); i++ ) {
00220         e_i[i] = e_save[i];
00221     }
00222     for( i = 0; i < ldz*n; i++ ) {
00223         z_i[i] = z_save[i];
00224     }
00225     for( i = 0; i < (MAX(1,2*n-2)); i++ ) {
00226         work_i[i] = work[i];
00227     }
00228 
00229     /* Init row_major arrays */
00230     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00231         LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, z_i, ldz, z_r, n+2 );
00232     }
00233     info_i = LAPACKE_ssteqr( LAPACK_ROW_MAJOR, compz_i, n_i, d_i, e_i, z_r,
00234                              ldz_r );
00235 
00236     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00237         LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, z_r, n+2, z_i, ldz );
00238     }
00239 
00240     failed = compare_ssteqr( d, d_i, e, e_i, z, z_i, info, info_i, compz, ldz,
00241                              n );
00242     if( failed == 0 ) {
00243         printf( "PASSED: row-major high-level interface to ssteqr\n" );
00244     } else {
00245         printf( "FAILED: row-major high-level interface to ssteqr\n" );
00246     }
00247 
00248     /* Release memory */
00249     if( d != NULL ) {
00250         LAPACKE_free( d );
00251     }
00252     if( d_i != NULL ) {
00253         LAPACKE_free( d_i );
00254     }
00255     if( d_save != NULL ) {
00256         LAPACKE_free( d_save );
00257     }
00258     if( e != NULL ) {
00259         LAPACKE_free( e );
00260     }
00261     if( e_i != NULL ) {
00262         LAPACKE_free( e_i );
00263     }
00264     if( e_save != NULL ) {
00265         LAPACKE_free( e_save );
00266     }
00267     if( z != NULL ) {
00268         LAPACKE_free( z );
00269     }
00270     if( z_i != NULL ) {
00271         LAPACKE_free( z_i );
00272     }
00273     if( z_r != NULL ) {
00274         LAPACKE_free( z_r );
00275     }
00276     if( z_save != NULL ) {
00277         LAPACKE_free( z_save );
00278     }
00279     if( work != NULL ) {
00280         LAPACKE_free( work );
00281     }
00282     if( work_i != NULL ) {
00283         LAPACKE_free( work_i );
00284     }
00285 
00286     return 0;
00287 }
00288 
00289 /* Auxiliary function: ssteqr scalar parameters initialization */
00290 static void init_scalars_ssteqr( char *compz, lapack_int *n, lapack_int *ldz )
00291 {
00292     *compz = 'I';
00293     *n = 4;
00294     *ldz = 8;
00295 
00296     return;
00297 }
00298 
00299 /* Auxiliary functions: ssteqr array parameters initialization */
00300 static void init_d( lapack_int size, float *d ) {
00301     lapack_int i;
00302     for( i = 0; i < size; i++ ) {
00303         d[i] = 0;
00304     }
00305     d[0] = -6.989999771e+000;
00306     d[1] = 7.920000076e+000;
00307     d[2] = 2.339999914e+000;
00308     d[3] = 3.199999928e-001;
00309 }
00310 static void init_e( lapack_int size, float *e ) {
00311     lapack_int i;
00312     for( i = 0; i < size; i++ ) {
00313         e[i] = 0;
00314     }
00315     e[0] = -4.399999976e-001;
00316     e[1] = -2.630000114e+000;
00317     e[2] = -1.179999948e+000;
00318 }
00319 static void init_z( lapack_int size, float *z ) {
00320     lapack_int i;
00321     for( i = 0; i < size; i++ ) {
00322         z[i] = 0;
00323     }
00324     z[0] = 0.000000000e+000;  /* z[0,0] */
00325     z[8] = 0.000000000e+000;  /* z[0,1] */
00326     z[16] = 0.000000000e+000;  /* z[0,2] */
00327     z[24] = 0.000000000e+000;  /* z[0,3] */
00328     z[1] = 0.000000000e+000;  /* z[1,0] */
00329     z[9] = 0.000000000e+000;  /* z[1,1] */
00330     z[17] = 0.000000000e+000;  /* z[1,2] */
00331     z[25] = 0.000000000e+000;  /* z[1,3] */
00332     z[2] = 0.000000000e+000;  /* z[2,0] */
00333     z[10] = 0.000000000e+000;  /* z[2,1] */
00334     z[18] = 0.000000000e+000;  /* z[2,2] */
00335     z[26] = 0.000000000e+000;  /* z[2,3] */
00336     z[3] = 0.000000000e+000;  /* z[3,0] */
00337     z[11] = 0.000000000e+000;  /* z[3,1] */
00338     z[19] = 0.000000000e+000;  /* z[3,2] */
00339     z[27] = 0.000000000e+000;  /* z[3,3] */
00340 }
00341 static void init_work( lapack_int size, float *work ) {
00342     lapack_int i;
00343     for( i = 0; i < size; i++ ) {
00344         work[i] = 0;
00345     }
00346 }
00347 
00348 /* Auxiliary function: C interface to ssteqr results check */
00349 /* Return value: 0 - test is passed, non-zero - test is failed */
00350 static int compare_ssteqr( float *d, float *d_i, float *e, float *e_i, float *z,
00351                            float *z_i, lapack_int info, lapack_int info_i,
00352                            char compz, lapack_int ldz, lapack_int n )
00353 {
00354     lapack_int i;
00355     int failed = 0;
00356     for( i = 0; i < n; i++ ) {
00357         failed += compare_floats(d[i],d_i[i]);
00358     }
00359     for( i = 0; i < (n-1); i++ ) {
00360         failed += compare_floats(e[i],e_i[i]);
00361     }
00362     if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
00363         for( i = 0; i < ldz*n; i++ ) {
00364             failed += compare_floats(z[i],z_i[i]);
00365         }
00366     }
00367     failed += (info == info_i) ? 0 : 1;
00368     if( info != 0 || info_i != 0 ) {
00369         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00370     }
00371 
00372     return failed;
00373 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:14