dormbr_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 * dormbr_1 is the test program for the C interface to LAPACK
00036 * routine dormbr
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_dormbr( 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, double *a );
00059 static void init_tau( lapack_int size, double *tau );
00060 static void init_c( lapack_int size, double *c );
00061 static void init_work( lapack_int size, double *work );
00062 static int compare_dormbr( double *c, double *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     double *a = NULL, *a_i = NULL;
00088     double *tau = NULL, *tau_i = NULL;
00089     double *c = NULL, *c_i = NULL;
00090     double *work = NULL, *work_i = NULL;
00091     double *c_save = NULL;
00092     double *a_r = NULL;
00093     double *c_r = NULL;
00094 
00095     /* Iniitialize the scalar parameters */
00096     init_scalars_dormbr( &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 = (double *)LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(double) );
00113     tau = (double *)LAPACKE_malloc( MIN(nq,k) * sizeof(double) );
00114     c = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00115     work = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00116 
00117     /* Allocate memory for the C interface function arrays */
00118     a_i = (double *)LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(double) );
00119     tau_i = (double *)LAPACKE_malloc( MIN(nq,k) * sizeof(double) );
00120     c_i = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00121     work_i = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00122 
00123     /* Allocate memory for the backup arrays */
00124     c_save = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00125 
00126     /* Allocate memory for the row-major arrays */
00127     a_r = (double *)LAPACKE_malloc( (r*(MIN(nq,k)+2)) * sizeof(double) );
00128     c_r = (double *)LAPACKE_malloc( m*(n+2) * sizeof(double) );
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     dormbr_( &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_dormbr_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_dormbr( c, c_i, info, info_i, ldc, n );
00164     if( failed == 0 ) {
00165         printf( "PASSED: column-major middle-level interface to dormbr\n" );
00166     } else {
00167         printf( "FAILED: column-major middle-level interface to dormbr\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_dormbr( 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_dormbr( c, c_i, info, info_i, ldc, n );
00188     if( failed == 0 ) {
00189         printf( "PASSED: column-major high-level interface to dormbr\n" );
00190     } else {
00191         printf( "FAILED: column-major high-level interface to dormbr\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_dge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00210                        k)+2);
00211     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00212     info_i = LAPACKE_dormbr_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_dge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00217 
00218     failed = compare_dormbr( c, c_i, info, info_i, ldc, n );
00219     if( failed == 0 ) {
00220         printf( "PASSED: row-major middle-level interface to dormbr\n" );
00221     } else {
00222         printf( "FAILED: row-major middle-level interface to dormbr\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_dge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00242                        k)+2);
00243     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00244     info_i = LAPACKE_dormbr( 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_dge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00248 
00249     failed = compare_dormbr( c, c_i, info, info_i, ldc, n );
00250     if( failed == 0 ) {
00251         printf( "PASSED: row-major high-level interface to dormbr\n" );
00252     } else {
00253         printf( "FAILED: row-major high-level interface to dormbr\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: dormbr scalar parameters initialization */
00295 static void init_scalars_dormbr( 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 = 'Q';
00301     *side = 'R';
00302     *trans = 'N';
00303     *m = 6;
00304     *n = 4;
00305     *k = 4;
00306     *lda = 8;
00307     *ldc = 8;
00308     *lwork = 1024;
00309 
00310     return;
00311 }
00312 
00313 /* Auxiliary functions: dormbr array parameters initialization */
00314 static void init_a( lapack_int size, double *a ) {
00315     lapack_int i;
00316     for( i = 0; i < size; i++ ) {
00317         a[i] = 0;
00318     }
00319     a[0] = 3.61767881382524030e+000;  /* a[0,0] */
00320     a[8] = 1.25871140471055650e+000;  /* a[0,1] */
00321     a[16] = -4.66788533970659230e-001;  /* a[0,2] */
00322     a[24] = -4.10950544929054030e-001;  /* a[0,3] */
00323     a[1] = 0.00000000000000000e+000;  /* a[1,0] */
00324     a[9] = -2.41605534042332600e+000;  /* a[1,1] */
00325     a[17] = -1.52615488994111680e+000;  /* a[1,2] */
00326     a[25] = -2.09455650564123440e-001;  /* a[1,3] */
00327     a[2] = 0.00000000000000000e+000;  /* a[2,0] */
00328     a[10] = 2.04091961983997000e-002;  /* a[2,1] */
00329     a[18] = 1.92131096370999940e+000;  /* a[2,2] */
00330     a[26] = 1.18946667701939000e+000;  /* a[2,3] */
00331     a[3] = 0.00000000000000000e+000;  /* a[3,0] */
00332     a[11] = -3.21626418690548640e-001;  /* a[3,1] */
00333     a[19] = 1.34228166612422040e-001;  /* a[3,2] */
00334     a[27] = -1.42650154173085970e+000;  /* a[3,3] */
00335 }
00336 static void init_tau( lapack_int size, double *tau ) {
00337     lapack_int i;
00338     for( i = 0; i < size; i++ ) {
00339         tau[i] = 0;
00340     }
00341     tau[0] = 0.00000000000000000e+000;
00342     tau[1] = 1.81182381794177600e+000;
00343     tau[2] = 1.96460334717423550e+000;
00344     tau[3] = 0.00000000000000000e+000;
00345 }
00346 static void init_c( lapack_int size, double *c ) {
00347     lapack_int i;
00348     for( i = 0; i < size; i++ ) {
00349         c[i] = 0;
00350     }
00351     c[0] = -1.57559592582321220e-001;  /* c[0,0] */
00352     c[8] = 6.74381518209104080e-001;  /* c[0,1] */
00353     c[16] = -4.57149964215295970e-001;  /* c[0,2] */
00354     c[24] = 4.48851645119849540e-001;  /* c[0,3] */
00355     c[1] = -5.33491252076982340e-001;  /* c[1,0] */
00356     c[9] = -3.86108989331406360e-001;  /* c[1,1] */
00357     c[17] = 2.58252726077486450e-001;  /* c[1,2] */
00358     c[25] = 3.89817437867655880e-001;  /* c[1,3] */
00359     c[2] = 6.35766777086559380e-001;  /* c[2,0] */
00360     c[10] = -2.92823089959412750e-001;  /* c[2,1] */
00361     c[18] = 1.65384263845584910e-002;  /* c[2,2] */
00362     c[26] = 1.92952916776812260e-001;  /* c[2,3] */
00363     c[3] = -5.33491252076982340e-001;  /* c[3,0] */
00364     c[11] = -1.69154705537664260e-001;  /* c[3,1] */
00365     c[19] = -8.34273545141680510e-002;  /* c[3,2] */
00366     c[27] = -2.34987319363205350e-001;  /* c[3,3] */
00367     c[4] = 4.14630506795582170e-002;  /* c[4,0] */
00368     c[12] = -1.59302792034020260e-001;  /* c[4,1] */
00369     c[20] = 1.47478303793470600e-001;  /* c[4,2] */
00370     c[28] = 7.43640764641989470e-001;  /* c[4,3] */
00371     c[5] = -5.52840675727442940e-003;  /* c[5,0] */
00372     c[13] = -5.06352999681760840e-001;  /* c[5,1] */
00373     c[21] = -8.33868063049059920e-001;  /* c[5,2] */
00374     c[29] = 3.35128425531637520e-002;  /* c[5,3] */
00375 }
00376 static void init_work( lapack_int size, double *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 dormbr results check */
00384 /* Return value: 0 - test is passed, non-zero - test is failed */
00385 static int compare_dormbr( double *c, double *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_doubles(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:55:47