sormbr_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 * sormbr_2 is the test program for the C interface to LAPACK
00036 * routine sormbr
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_sormbr( char *vect, char *side, char *trans,
00055                                  lapack_int *m, lapack_int *n, lapack_int *k,
00056                                  lapack_int *lda, lapack_int *ldc,
00057                                  lapack_int *lwork );
00058 static void init_a( lapack_int size, float *a );
00059 static void init_tau( lapack_int size, float *tau );
00060 static void init_c( lapack_int size, float *c );
00061 static void init_work( lapack_int size, float *work );
00062 static int compare_sormbr( float *c, float *c_i, lapack_int info,
00063                            lapack_int info_i, lapack_int ldc, lapack_int n );
00064 
00065 int main(void)
00066 {
00067     /* Local scalars */
00068     char vect, vect_i;
00069     char side, side_i;
00070     char trans, trans_i;
00071     lapack_int m, m_i;
00072     lapack_int n, n_i;
00073     lapack_int k, k_i;
00074     lapack_int lda, lda_i;
00075     lapack_int lda_r;
00076     lapack_int ldc, ldc_i;
00077     lapack_int ldc_r;
00078     lapack_int lwork, lwork_i;
00079     lapack_int info, info_i;
00080     /* Declare scalars */
00081     lapack_int nq;
00082     lapack_int r;
00083     lapack_int i;
00084     int failed;
00085 
00086     /* Local arrays */
00087     float *a = NULL, *a_i = NULL;
00088     float *tau = NULL, *tau_i = NULL;
00089     float *c = NULL, *c_i = NULL;
00090     float *work = NULL, *work_i = NULL;
00091     float *c_save = NULL;
00092     float *a_r = NULL;
00093     float *c_r = NULL;
00094 
00095     /* Iniitialize the scalar parameters */
00096     init_scalars_sormbr( &vect, &side, &trans, &m, &n, &k, &lda, &ldc, &lwork );
00097     nq = LAPACKE_lsame( side, 'l' ) ? m : n;
00098     r = LAPACKE_lsame( vect, 'q' ) ? nq : MIN(nq,k);
00099     lda_r = MIN(nq,k)+2;
00100     ldc_r = n+2;
00101     vect_i = vect;
00102     side_i = side;
00103     trans_i = trans;
00104     m_i = m;
00105     n_i = n;
00106     k_i = k;
00107     lda_i = lda;
00108     ldc_i = ldc;
00109     lwork_i = lwork;
00110 
00111     /* Allocate memory for the LAPACK routine arrays */
00112     a = (float *)LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(float) );
00113     tau = (float *)LAPACKE_malloc( MIN(nq,k) * sizeof(float) );
00114     c = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00115     work = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00116 
00117     /* Allocate memory for the C interface function arrays */
00118     a_i = (float *)LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(float) );
00119     tau_i = (float *)LAPACKE_malloc( MIN(nq,k) * sizeof(float) );
00120     c_i = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00121     work_i = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00122 
00123     /* Allocate memory for the backup arrays */
00124     c_save = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00125 
00126     /* Allocate memory for the row-major arrays */
00127     a_r = (float *)LAPACKE_malloc( (r*(MIN(nq,k)+2)) * sizeof(float) );
00128     c_r = (float *)LAPACKE_malloc( m*(n+2) * sizeof(float) );
00129 
00130     /* Initialize input arrays */
00131     init_a( lda*(MIN(nq,k)), a );
00132     init_tau( (MIN(nq,k)), tau );
00133     init_c( ldc*n, c );
00134     init_work( lwork, work );
00135 
00136     /* Backup the ouptut arrays */
00137     for( i = 0; i < ldc*n; i++ ) {
00138         c_save[i] = c[i];
00139     }
00140 
00141     /* Call the LAPACK routine */
00142     sormbr_( &vect, &side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, work,
00143              &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*(MIN(nq,k)); i++ ) {
00148         a_i[i] = a[i];
00149     }
00150     for( i = 0; i < (MIN(nq,k)); i++ ) {
00151         tau_i[i] = tau[i];
00152     }
00153     for( i = 0; i < ldc*n; i++ ) {
00154         c_i[i] = c_save[i];
00155     }
00156     for( i = 0; i < lwork; i++ ) {
00157         work_i[i] = work[i];
00158     }
00159     info_i = LAPACKE_sormbr_work( LAPACK_COL_MAJOR, vect_i, side_i, trans_i,
00160                                   m_i, n_i, k_i, a_i, lda_i, tau_i, c_i, ldc_i,
00161                                   work_i, lwork_i );
00162 
00163     failed = compare_sormbr( c, c_i, info, info_i, ldc, n );
00164     if( failed == 0 ) {
00165         printf( "PASSED: column-major middle-level interface to sormbr\n" );
00166     } else {
00167         printf( "FAILED: column-major middle-level interface to sormbr\n" );
00168     }
00169 
00170     /* Initialize input data, call the column-major high-level
00171      * interface to LAPACK routine and check the results */
00172     for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00173         a_i[i] = a[i];
00174     }
00175     for( i = 0; i < (MIN(nq,k)); i++ ) {
00176         tau_i[i] = tau[i];
00177     }
00178     for( i = 0; i < ldc*n; i++ ) {
00179         c_i[i] = c_save[i];
00180     }
00181     for( i = 0; i < lwork; i++ ) {
00182         work_i[i] = work[i];
00183     }
00184     info_i = LAPACKE_sormbr( LAPACK_COL_MAJOR, vect_i, side_i, trans_i, m_i,
00185                              n_i, k_i, a_i, lda_i, tau_i, c_i, ldc_i );
00186 
00187     failed = compare_sormbr( c, c_i, info, info_i, ldc, n );
00188     if( failed == 0 ) {
00189         printf( "PASSED: column-major high-level interface to sormbr\n" );
00190     } else {
00191         printf( "FAILED: column-major high-level interface to sormbr\n" );
00192     }
00193 
00194     /* Initialize input data, call the row-major middle-level
00195      * interface to LAPACK routine and check the results */
00196     for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00197         a_i[i] = a[i];
00198     }
00199     for( i = 0; i < (MIN(nq,k)); i++ ) {
00200         tau_i[i] = tau[i];
00201     }
00202     for( i = 0; i < ldc*n; i++ ) {
00203         c_i[i] = c_save[i];
00204     }
00205     for( i = 0; i < lwork; i++ ) {
00206         work_i[i] = work[i];
00207     }
00208 
00209     LAPACKE_sge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00210                        k)+2);
00211     LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00212     info_i = LAPACKE_sormbr_work( LAPACK_ROW_MAJOR, vect_i, side_i, trans_i,
00213                                   m_i, n_i, k_i, a_r, lda_r, tau_i, c_r, ldc_r,
00214                                   work_i, lwork_i );
00215 
00216     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00217 
00218     failed = compare_sormbr( c, c_i, info, info_i, ldc, n );
00219     if( failed == 0 ) {
00220         printf( "PASSED: row-major middle-level interface to sormbr\n" );
00221     } else {
00222         printf( "FAILED: row-major middle-level interface to sormbr\n" );
00223     }
00224 
00225     /* Initialize input data, call the row-major high-level
00226      * interface to LAPACK routine and check the results */
00227     for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00228         a_i[i] = a[i];
00229     }
00230     for( i = 0; i < (MIN(nq,k)); i++ ) {
00231         tau_i[i] = tau[i];
00232     }
00233     for( i = 0; i < ldc*n; i++ ) {
00234         c_i[i] = c_save[i];
00235     }
00236     for( i = 0; i < lwork; i++ ) {
00237         work_i[i] = work[i];
00238     }
00239 
00240     /* Init row_major arrays */
00241     LAPACKE_sge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00242                        k)+2);
00243     LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00244     info_i = LAPACKE_sormbr( LAPACK_ROW_MAJOR, vect_i, side_i, trans_i, m_i,
00245                              n_i, k_i, a_r, lda_r, tau_i, c_r, ldc_r );
00246 
00247     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00248 
00249     failed = compare_sormbr( c, c_i, info, info_i, ldc, n );
00250     if( failed == 0 ) {
00251         printf( "PASSED: row-major high-level interface to sormbr\n" );
00252     } else {
00253         printf( "FAILED: row-major high-level interface to sormbr\n" );
00254     }
00255 
00256     /* Release memory */
00257     if( a != NULL ) {
00258         LAPACKE_free( a );
00259     }
00260     if( a_i != NULL ) {
00261         LAPACKE_free( a_i );
00262     }
00263     if( a_r != NULL ) {
00264         LAPACKE_free( a_r );
00265     }
00266     if( tau != NULL ) {
00267         LAPACKE_free( tau );
00268     }
00269     if( tau_i != NULL ) {
00270         LAPACKE_free( tau_i );
00271     }
00272     if( c != NULL ) {
00273         LAPACKE_free( c );
00274     }
00275     if( c_i != NULL ) {
00276         LAPACKE_free( c_i );
00277     }
00278     if( c_r != NULL ) {
00279         LAPACKE_free( c_r );
00280     }
00281     if( c_save != NULL ) {
00282         LAPACKE_free( c_save );
00283     }
00284     if( work != NULL ) {
00285         LAPACKE_free( work );
00286     }
00287     if( work_i != NULL ) {
00288         LAPACKE_free( work_i );
00289     }
00290 
00291     return 0;
00292 }
00293 
00294 /* Auxiliary function: sormbr scalar parameters initialization */
00295 static void init_scalars_sormbr( char *vect, char *side, char *trans,
00296                                  lapack_int *m, lapack_int *n, lapack_int *k,
00297                                  lapack_int *lda, lapack_int *ldc,
00298                                  lapack_int *lwork )
00299 {
00300     *vect = 'P';
00301     *side = 'L';
00302     *trans = 'T';
00303     *m = 4;
00304     *n = 6;
00305     *k = 4;
00306     *lda = 8;
00307     *ldc = 8;
00308     *lwork = 1024;
00309 
00310     return;
00311 }
00312 
00313 /* Auxiliary functions: sormbr array parameters initialization */
00314 static void init_a( lapack_int size, float *a ) {
00315     lapack_int i;
00316     for( i = 0; i < size; i++ ) {
00317         a[i] = 0;
00318     }
00319     a[0] = -7.772435188e+000;  /* a[0,0] */
00320     a[8] = 1.192641139e+000;  /* a[0,1] */
00321     a[16] = 6.896195002e-003;  /* a[0,2] */
00322     a[24] = 9.197353721e-001;  /* a[0,3] */
00323     a[1] = 7.835548371e-003;  /* a[1,0] */
00324     a[9] = 6.157293320e+000;  /* a[1,1] */
00325     a[17] = 5.733590722e-001;  /* a[1,2] */
00326     a[25] = -1.803648025e-001;  /* a[1,3] */
00327     a[2] = 6.632159464e-003;  /* a[2,0] */
00328     a[10] = -2.797574364e-002;  /* a[2,1] */
00329     a[18] = -6.057568073e+000;  /* a[2,2] */
00330     a[26] = -1.914320111e+000;  /* a[2,3] */
00331     a[3] = 9.587492794e-002;  /* a[3,0] */
00332     a[11] = 9.166325927e-001;  /* a[3,1] */
00333     a[19] = 2.011592835e-001;  /* a[3,2] */
00334     a[27] = 5.793256283e+000;  /* a[3,3] */
00335 }
00336 static void init_tau( lapack_int size, float *tau ) {
00337     lapack_int i;
00338     for( i = 0; i < size; i++ ) {
00339         tau[i] = 0;
00340     }
00341     tau[0] = 1.083446622e+000;
00342     tau[1] = 1.936987042e+000;
00343     tau[2] = 0.000000000e+000;
00344     tau[3] = 0.000000000e+000;
00345 }
00346 static void init_c( lapack_int size, float *c ) {
00347     lapack_int i;
00348     for( i = 0; i < size; i++ ) {
00349         c[i] = 0;
00350     }
00351     c[0] = -7.104246616e-001;  /* c[0,0] */
00352     c[8] = 4.299248457e-001;  /* c[0,1] */
00353     c[16] = -4.823547602e-001;  /* c[0,2] */
00354     c[24] = 3.539015725e-002;  /* c[0,3] */
00355     c[32] = 2.700137794e-001;  /* c[0,4] */
00356     c[40] = 6.029434502e-002;  /* c[0,5] */
00357     c[1] = -2.412205487e-001;  /* c[1,0] */
00358     c[9] = -5.323043466e-001;  /* c[1,1] */
00359     c[17] = -4.844856858e-001;  /* c[1,2] */
00360     c[25] = -1.594917476e-001;  /* c[1,3] */
00361     c[33] = -6.311050057e-001;  /* c[1,4] */
00362     c[41] = -2.664134838e-003;  /* c[1,5] */
00363     c[2] = 1.286828667e-001;  /* c[2,0] */
00364     c[10] = -2.619454265e-001;  /* c[2,1] */
00365     c[18] = -2.108367532e-001;  /* c[2,2] */
00366     c[26] = -7.447289824e-001;  /* c[2,3] */
00367     c[34] = 5.226845741e-001;  /* c[2,4] */
00368     c[42] = -2.062834352e-001;  /* c[2,5] */
00369     c[3] = -3.403473496e-001;  /* c[3,0] */
00370     c[11] = -9.212616831e-002;  /* c[3,1] */
00371     c[19] = 4.546407461e-001;  /* c[3,2] */
00372     c[27] = -3.869233131e-001;  /* c[3,3] */
00373     c[35] = -4.647991061e-002;  /* c[3,4] */
00374     c[43] = 7.191025019e-001;  /* c[3,5] */
00375 }
00376 static void init_work( lapack_int size, float *work ) {
00377     lapack_int i;
00378     for( i = 0; i < size; i++ ) {
00379         work[i] = 0;
00380     }
00381 }
00382 
00383 /* Auxiliary function: C interface to sormbr results check */
00384 /* Return value: 0 - test is passed, non-zero - test is failed */
00385 static int compare_sormbr( float *c, float *c_i, lapack_int info,
00386                            lapack_int info_i, lapack_int ldc, lapack_int n )
00387 {
00388     lapack_int i;
00389     int failed = 0;
00390     for( i = 0; i < ldc*n; i++ ) {
00391         failed += compare_floats(c[i],c_i[i]);
00392     }
00393     failed += (info == info_i) ? 0 : 1;
00394     if( info != 0 || info_i != 0 ) {
00395         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00396     }
00397 
00398     return failed;
00399 }


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