ssytrd_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 * ssytrd_3 is the test program for the C interface to LAPACK
00036 * routine ssytrd
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_ssytrd( char *uplo, lapack_int *n, lapack_int *lda,
00055                                  lapack_int *lwork );
00056 static void init_a( lapack_int size, float *a );
00057 static void init_d( lapack_int size, float *d );
00058 static void init_e( lapack_int size, float *e );
00059 static void init_tau( lapack_int size, float *tau );
00060 static void init_work( lapack_int size, float *work );
00061 static int compare_ssytrd( float *a, float *a_i, float *d, float *d_i, float *e,
00062                            float *e_i, float *tau, float *tau_i,
00063                            lapack_int info, lapack_int info_i, lapack_int lda,
00064                            lapack_int n );
00065 
00066 int main(void)
00067 {
00068     /* Local scalars */
00069     char uplo, uplo_i;
00070     lapack_int n, n_i;
00071     lapack_int lda, lda_i;
00072     lapack_int lda_r;
00073     lapack_int lwork, lwork_i;
00074     lapack_int info, info_i;
00075     lapack_int i;
00076     int failed;
00077 
00078     /* Local arrays */
00079     float *a = NULL, *a_i = NULL;
00080     float *d = NULL, *d_i = NULL;
00081     float *e = NULL, *e_i = NULL;
00082     float *tau = NULL, *tau_i = NULL;
00083     float *work = NULL, *work_i = NULL;
00084     float *a_save = NULL;
00085     float *d_save = NULL;
00086     float *e_save = NULL;
00087     float *tau_save = NULL;
00088     float *a_r = NULL;
00089 
00090     /* Iniitialize the scalar parameters */
00091     init_scalars_ssytrd( &uplo, &n, &lda, &lwork );
00092     lda_r = n+2;
00093     uplo_i = uplo;
00094     n_i = n;
00095     lda_i = lda;
00096     lwork_i = lwork;
00097 
00098     /* Allocate memory for the LAPACK routine arrays */
00099     a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00100     d = (float *)LAPACKE_malloc( n * sizeof(float) );
00101     e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00102     tau = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00103     work = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00104 
00105     /* Allocate memory for the C interface function arrays */
00106     a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00107     d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00108     e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00109     tau_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00110     work_i = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00111 
00112     /* Allocate memory for the backup arrays */
00113     a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00114     d_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00115     e_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00116     tau_save = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00117 
00118     /* Allocate memory for the row-major arrays */
00119     a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00120 
00121     /* Initialize input arrays */
00122     init_a( lda*n, a );
00123     init_d( n, d );
00124     init_e( (n-1), e );
00125     init_tau( (n-1), tau );
00126     init_work( lwork, work );
00127 
00128     /* Backup the ouptut arrays */
00129     for( i = 0; i < lda*n; i++ ) {
00130         a_save[i] = a[i];
00131     }
00132     for( i = 0; i < n; i++ ) {
00133         d_save[i] = d[i];
00134     }
00135     for( i = 0; i < (n-1); i++ ) {
00136         e_save[i] = e[i];
00137     }
00138     for( i = 0; i < (n-1); i++ ) {
00139         tau_save[i] = tau[i];
00140     }
00141 
00142     /* Call the LAPACK routine */
00143     ssytrd_( &uplo, &n, a, &lda, d, e, tau, work, &lwork, &info );
00144 
00145     /* Initialize input data, call the column-major middle-level
00146      * interface to LAPACK routine and check the results */
00147     for( i = 0; i < lda*n; i++ ) {
00148         a_i[i] = a_save[i];
00149     }
00150     for( i = 0; i < n; i++ ) {
00151         d_i[i] = d_save[i];
00152     }
00153     for( i = 0; i < (n-1); i++ ) {
00154         e_i[i] = e_save[i];
00155     }
00156     for( i = 0; i < (n-1); i++ ) {
00157         tau_i[i] = tau_save[i];
00158     }
00159     for( i = 0; i < lwork; i++ ) {
00160         work_i[i] = work[i];
00161     }
00162     info_i = LAPACKE_ssytrd_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00163                                   d_i, e_i, tau_i, work_i, lwork_i );
00164 
00165     failed = compare_ssytrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00166                              lda, n );
00167     if( failed == 0 ) {
00168         printf( "PASSED: column-major middle-level interface to ssytrd\n" );
00169     } else {
00170         printf( "FAILED: column-major middle-level interface to ssytrd\n" );
00171     }
00172 
00173     /* Initialize input data, call the column-major high-level
00174      * interface to LAPACK routine and check the results */
00175     for( i = 0; i < lda*n; i++ ) {
00176         a_i[i] = a_save[i];
00177     }
00178     for( i = 0; i < n; i++ ) {
00179         d_i[i] = d_save[i];
00180     }
00181     for( i = 0; i < (n-1); i++ ) {
00182         e_i[i] = e_save[i];
00183     }
00184     for( i = 0; i < (n-1); i++ ) {
00185         tau_i[i] = tau_save[i];
00186     }
00187     for( i = 0; i < lwork; i++ ) {
00188         work_i[i] = work[i];
00189     }
00190     info_i = LAPACKE_ssytrd( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i, d_i,
00191                              e_i, tau_i );
00192 
00193     failed = compare_ssytrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00194                              lda, n );
00195     if( failed == 0 ) {
00196         printf( "PASSED: column-major high-level interface to ssytrd\n" );
00197     } else {
00198         printf( "FAILED: column-major high-level interface to ssytrd\n" );
00199     }
00200 
00201     /* Initialize input data, call the row-major middle-level
00202      * interface to LAPACK routine and check the results */
00203     for( i = 0; i < lda*n; i++ ) {
00204         a_i[i] = a_save[i];
00205     }
00206     for( i = 0; i < n; i++ ) {
00207         d_i[i] = d_save[i];
00208     }
00209     for( i = 0; i < (n-1); i++ ) {
00210         e_i[i] = e_save[i];
00211     }
00212     for( i = 0; i < (n-1); i++ ) {
00213         tau_i[i] = tau_save[i];
00214     }
00215     for( i = 0; i < lwork; i++ ) {
00216         work_i[i] = work[i];
00217     }
00218 
00219     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00220     info_i = LAPACKE_ssytrd_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00221                                   d_i, e_i, tau_i, work_i, lwork_i );
00222 
00223     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00224 
00225     failed = compare_ssytrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00226                              lda, n );
00227     if( failed == 0 ) {
00228         printf( "PASSED: row-major middle-level interface to ssytrd\n" );
00229     } else {
00230         printf( "FAILED: row-major middle-level interface to ssytrd\n" );
00231     }
00232 
00233     /* Initialize input data, call the row-major high-level
00234      * interface to LAPACK routine and check the results */
00235     for( i = 0; i < lda*n; i++ ) {
00236         a_i[i] = a_save[i];
00237     }
00238     for( i = 0; i < n; i++ ) {
00239         d_i[i] = d_save[i];
00240     }
00241     for( i = 0; i < (n-1); i++ ) {
00242         e_i[i] = e_save[i];
00243     }
00244     for( i = 0; i < (n-1); i++ ) {
00245         tau_i[i] = tau_save[i];
00246     }
00247     for( i = 0; i < lwork; i++ ) {
00248         work_i[i] = work[i];
00249     }
00250 
00251     /* Init row_major arrays */
00252     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00253     info_i = LAPACKE_ssytrd( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r, d_i,
00254                              e_i, tau_i );
00255 
00256     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00257 
00258     failed = compare_ssytrd( a, a_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00259                              lda, n );
00260     if( failed == 0 ) {
00261         printf( "PASSED: row-major high-level interface to ssytrd\n" );
00262     } else {
00263         printf( "FAILED: row-major high-level interface to ssytrd\n" );
00264     }
00265 
00266     /* Release memory */
00267     if( a != NULL ) {
00268         LAPACKE_free( a );
00269     }
00270     if( a_i != NULL ) {
00271         LAPACKE_free( a_i );
00272     }
00273     if( a_r != NULL ) {
00274         LAPACKE_free( a_r );
00275     }
00276     if( a_save != NULL ) {
00277         LAPACKE_free( a_save );
00278     }
00279     if( d != NULL ) {
00280         LAPACKE_free( d );
00281     }
00282     if( d_i != NULL ) {
00283         LAPACKE_free( d_i );
00284     }
00285     if( d_save != NULL ) {
00286         LAPACKE_free( d_save );
00287     }
00288     if( e != NULL ) {
00289         LAPACKE_free( e );
00290     }
00291     if( e_i != NULL ) {
00292         LAPACKE_free( e_i );
00293     }
00294     if( e_save != NULL ) {
00295         LAPACKE_free( e_save );
00296     }
00297     if( tau != NULL ) {
00298         LAPACKE_free( tau );
00299     }
00300     if( tau_i != NULL ) {
00301         LAPACKE_free( tau_i );
00302     }
00303     if( tau_save != NULL ) {
00304         LAPACKE_free( tau_save );
00305     }
00306     if( work != NULL ) {
00307         LAPACKE_free( work );
00308     }
00309     if( work_i != NULL ) {
00310         LAPACKE_free( work_i );
00311     }
00312 
00313     return 0;
00314 }
00315 
00316 /* Auxiliary function: ssytrd scalar parameters initialization */
00317 static void init_scalars_ssytrd( char *uplo, lapack_int *n, lapack_int *lda,
00318                                  lapack_int *lwork )
00319 {
00320     *uplo = 'L';
00321     *n = 4;
00322     *lda = 8;
00323     *lwork = 512;
00324 
00325     return;
00326 }
00327 
00328 /* Auxiliary functions: ssytrd array parameters initialization */
00329 static void init_a( lapack_int size, float *a ) {
00330     lapack_int i;
00331     for( i = 0; i < size; i++ ) {
00332         a[i] = 0;
00333     }
00334     a[0] = 5.769230798e-002;  /* a[0,0] */
00335     a[8] = 0.000000000e+000;  /* a[0,1] */
00336     a[16] = 0.000000000e+000;  /* a[0,2] */
00337     a[24] = 0.000000000e+000;  /* a[0,3] */
00338     a[1] = 1.703930944e-001;  /* a[1,0] */
00339     a[9] = 2.267657369e-001;  /* a[1,1] */
00340     a[17] = 0.000000000e+000;  /* a[1,2] */
00341     a[25] = 0.000000000e+000;  /* a[1,3] */
00342     a[2] = 2.949949205e-001;  /* a[2,0] */
00343     a[10] = 8.667321205e-001;  /* a[2,1] */
00344     a[18] = -5.000129342e-002;  /* a[2,2] */
00345     a[26] = 0.000000000e+000;  /* a[2,3] */
00346     a[3] = -6.024086475e-001;  /* a[3,0] */
00347     a[11] = -6.159023643e-001;  /* a[3,1] */
00348     a[19] = 3.972190022e-001;  /* a[3,2] */
00349     a[27] = -1.687545180e+000;  /* a[3,3] */
00350 }
00351 static void init_d( lapack_int size, float *d ) {
00352     lapack_int i;
00353     for( i = 0; i < size; i++ ) {
00354         d[i] = 0;
00355     }
00356 }
00357 static void init_e( lapack_int size, float *e ) {
00358     lapack_int i;
00359     for( i = 0; i < size; i++ ) {
00360         e[i] = 0;
00361     }
00362 }
00363 static void init_tau( lapack_int size, float *tau ) {
00364     lapack_int i;
00365     for( i = 0; i < size; i++ ) {
00366         tau[i] = 0;
00367     }
00368 }
00369 static void init_work( lapack_int size, float *work ) {
00370     lapack_int i;
00371     for( i = 0; i < size; i++ ) {
00372         work[i] = 0;
00373     }
00374 }
00375 
00376 /* Auxiliary function: C interface to ssytrd results check */
00377 /* Return value: 0 - test is passed, non-zero - test is failed */
00378 static int compare_ssytrd( float *a, float *a_i, float *d, float *d_i, float *e,
00379                            float *e_i, float *tau, float *tau_i,
00380                            lapack_int info, lapack_int info_i, lapack_int lda,
00381                            lapack_int n )
00382 {
00383     lapack_int i;
00384     int failed = 0;
00385     for( i = 0; i < lda*n; i++ ) {
00386         failed += compare_floats(a[i],a_i[i]);
00387     }
00388     for( i = 0; i < n; i++ ) {
00389         failed += compare_floats(d[i],d_i[i]);
00390     }
00391     for( i = 0; i < (n-1); i++ ) {
00392         failed += compare_floats(e[i],e_i[i]);
00393     }
00394     for( i = 0; i < (n-1); i++ ) {
00395         failed += compare_floats(tau[i],tau_i[i]);
00396     }
00397     failed += (info == info_i) ? 0 : 1;
00398     if( info != 0 || info_i != 0 ) {
00399         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00400     }
00401 
00402     return failed;
00403 }


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