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


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