dormlq_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 * dormlq_1 is the test program for the C interface to LAPACK
00036 * routine dormlq
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_dormlq( char *side, char *trans, lapack_int *m,
00055                                  lapack_int *n, lapack_int *k, lapack_int *lda,
00056                                  lapack_int *ldc, lapack_int *lwork );
00057 static void init_a( lapack_int size, double *a );
00058 static void init_tau( lapack_int size, double *tau );
00059 static void init_c( lapack_int size, double *c );
00060 static void init_work( lapack_int size, double *work );
00061 static int compare_dormlq( double *c, double *c_i, lapack_int info,
00062                            lapack_int info_i, lapack_int ldc, lapack_int n );
00063 
00064 int main(void)
00065 {
00066     /* Local scalars */
00067     char side, side_i;
00068     char trans, trans_i;
00069     lapack_int m, m_i;
00070     lapack_int n, n_i;
00071     lapack_int k, k_i;
00072     lapack_int lda, lda_i;
00073     lapack_int lda_r;
00074     lapack_int ldc, ldc_i;
00075     lapack_int ldc_r;
00076     lapack_int lwork, lwork_i;
00077     lapack_int info, info_i;
00078     lapack_int i;
00079     int failed;
00080 
00081     /* Local arrays */
00082     double *a = NULL, *a_i = NULL;
00083     double *tau = NULL, *tau_i = NULL;
00084     double *c = NULL, *c_i = NULL;
00085     double *work = NULL, *work_i = NULL;
00086     double *c_save = NULL;
00087     double *a_r = NULL;
00088     double *c_r = NULL;
00089 
00090     /* Iniitialize the scalar parameters */
00091     init_scalars_dormlq( &side, &trans, &m, &n, &k, &lda, &ldc, &lwork );
00092     lda_r = m+2;
00093     ldc_r = n+2;
00094     side_i = side;
00095     trans_i = trans;
00096     m_i = m;
00097     n_i = n;
00098     k_i = k;
00099     lda_i = lda;
00100     ldc_i = ldc;
00101     lwork_i = lwork;
00102 
00103     /* Allocate memory for the LAPACK routine arrays */
00104     a = (double *)LAPACKE_malloc( lda*m * sizeof(double) );
00105     tau = (double *)LAPACKE_malloc( k * sizeof(double) );
00106     c = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00107     work = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00108 
00109     /* Allocate memory for the C interface function arrays */
00110     a_i = (double *)LAPACKE_malloc( lda*m * sizeof(double) );
00111     tau_i = (double *)LAPACKE_malloc( k * sizeof(double) );
00112     c_i = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00113     work_i = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00114 
00115     /* Allocate memory for the backup arrays */
00116     c_save = (double *)LAPACKE_malloc( ldc*n * sizeof(double) );
00117 
00118     /* Allocate memory for the row-major arrays */
00119     a_r = (double *)LAPACKE_malloc( k*(m+2) * sizeof(double) );
00120     c_r = (double *)LAPACKE_malloc( m*(n+2) * sizeof(double) );
00121 
00122     /* Initialize input arrays */
00123     init_a( lda*m, a );
00124     init_tau( k, tau );
00125     init_c( ldc*n, c );
00126     init_work( lwork, work );
00127 
00128     /* Backup the ouptut arrays */
00129     for( i = 0; i < ldc*n; i++ ) {
00130         c_save[i] = c[i];
00131     }
00132 
00133     /* Call the LAPACK routine */
00134     dormlq_( &side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, work, &lwork,
00135              &info );
00136 
00137     /* Initialize input data, call the column-major middle-level
00138      * interface to LAPACK routine and check the results */
00139     for( i = 0; i < lda*m; i++ ) {
00140         a_i[i] = a[i];
00141     }
00142     for( i = 0; i < k; i++ ) {
00143         tau_i[i] = tau[i];
00144     }
00145     for( i = 0; i < ldc*n; i++ ) {
00146         c_i[i] = c_save[i];
00147     }
00148     for( i = 0; i < lwork; i++ ) {
00149         work_i[i] = work[i];
00150     }
00151     info_i = LAPACKE_dormlq_work( LAPACK_COL_MAJOR, side_i, trans_i, m_i, n_i,
00152                                   k_i, a_i, lda_i, tau_i, c_i, ldc_i, work_i,
00153                                   lwork_i );
00154 
00155     failed = compare_dormlq( c, c_i, info, info_i, ldc, n );
00156     if( failed == 0 ) {
00157         printf( "PASSED: column-major middle-level interface to dormlq\n" );
00158     } else {
00159         printf( "FAILED: column-major middle-level interface to dormlq\n" );
00160     }
00161 
00162     /* Initialize input data, call the column-major high-level
00163      * interface to LAPACK routine and check the results */
00164     for( i = 0; i < lda*m; i++ ) {
00165         a_i[i] = a[i];
00166     }
00167     for( i = 0; i < k; i++ ) {
00168         tau_i[i] = tau[i];
00169     }
00170     for( i = 0; i < ldc*n; i++ ) {
00171         c_i[i] = c_save[i];
00172     }
00173     for( i = 0; i < lwork; i++ ) {
00174         work_i[i] = work[i];
00175     }
00176     info_i = LAPACKE_dormlq( LAPACK_COL_MAJOR, side_i, trans_i, m_i, n_i, k_i,
00177                              a_i, lda_i, tau_i, c_i, ldc_i );
00178 
00179     failed = compare_dormlq( c, c_i, info, info_i, ldc, n );
00180     if( failed == 0 ) {
00181         printf( "PASSED: column-major high-level interface to dormlq\n" );
00182     } else {
00183         printf( "FAILED: column-major high-level interface to dormlq\n" );
00184     }
00185 
00186     /* Initialize input data, call the row-major middle-level
00187      * interface to LAPACK routine and check the results */
00188     for( i = 0; i < lda*m; i++ ) {
00189         a_i[i] = a[i];
00190     }
00191     for( i = 0; i < k; i++ ) {
00192         tau_i[i] = tau[i];
00193     }
00194     for( i = 0; i < ldc*n; i++ ) {
00195         c_i[i] = c_save[i];
00196     }
00197     for( i = 0; i < lwork; i++ ) {
00198         work_i[i] = work[i];
00199     }
00200 
00201     LAPACKE_dge_trans( LAPACK_COL_MAJOR, k, m, a_i, lda, a_r, m+2 );
00202     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00203     info_i = LAPACKE_dormlq_work( LAPACK_ROW_MAJOR, side_i, trans_i, m_i, n_i,
00204                                   k_i, a_r, lda_r, tau_i, c_r, ldc_r, work_i,
00205                                   lwork_i );
00206 
00207     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00208 
00209     failed = compare_dormlq( c, c_i, info, info_i, ldc, n );
00210     if( failed == 0 ) {
00211         printf( "PASSED: row-major middle-level interface to dormlq\n" );
00212     } else {
00213         printf( "FAILED: row-major middle-level interface to dormlq\n" );
00214     }
00215 
00216     /* Initialize input data, call the row-major high-level
00217      * interface to LAPACK routine and check the results */
00218     for( i = 0; i < lda*m; i++ ) {
00219         a_i[i] = a[i];
00220     }
00221     for( i = 0; i < k; i++ ) {
00222         tau_i[i] = tau[i];
00223     }
00224     for( i = 0; i < ldc*n; i++ ) {
00225         c_i[i] = c_save[i];
00226     }
00227     for( i = 0; i < lwork; i++ ) {
00228         work_i[i] = work[i];
00229     }
00230 
00231     /* Init row_major arrays */
00232     LAPACKE_dge_trans( LAPACK_COL_MAJOR, k, m, a_i, lda, a_r, m+2 );
00233     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00234     info_i = LAPACKE_dormlq( LAPACK_ROW_MAJOR, side_i, trans_i, m_i, n_i, k_i,
00235                              a_r, lda_r, tau_i, c_r, ldc_r );
00236 
00237     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00238 
00239     failed = compare_dormlq( c, c_i, info, info_i, ldc, n );
00240     if( failed == 0 ) {
00241         printf( "PASSED: row-major high-level interface to dormlq\n" );
00242     } else {
00243         printf( "FAILED: row-major high-level interface to dormlq\n" );
00244     }
00245 
00246     /* Release memory */
00247     if( a != NULL ) {
00248         LAPACKE_free( a );
00249     }
00250     if( a_i != NULL ) {
00251         LAPACKE_free( a_i );
00252     }
00253     if( a_r != NULL ) {
00254         LAPACKE_free( a_r );
00255     }
00256     if( tau != NULL ) {
00257         LAPACKE_free( tau );
00258     }
00259     if( tau_i != NULL ) {
00260         LAPACKE_free( tau_i );
00261     }
00262     if( c != NULL ) {
00263         LAPACKE_free( c );
00264     }
00265     if( c_i != NULL ) {
00266         LAPACKE_free( c_i );
00267     }
00268     if( c_r != NULL ) {
00269         LAPACKE_free( c_r );
00270     }
00271     if( c_save != NULL ) {
00272         LAPACKE_free( c_save );
00273     }
00274     if( work != NULL ) {
00275         LAPACKE_free( work );
00276     }
00277     if( work_i != NULL ) {
00278         LAPACKE_free( work_i );
00279     }
00280 
00281     return 0;
00282 }
00283 
00284 /* Auxiliary function: dormlq scalar parameters initialization */
00285 static void init_scalars_dormlq( char *side, char *trans, lapack_int *m,
00286                                  lapack_int *n, lapack_int *k, lapack_int *lda,
00287                                  lapack_int *ldc, lapack_int *lwork )
00288 {
00289     *side = 'L';
00290     *trans = 'T';
00291     *m = 6;
00292     *n = 2;
00293     *k = 4;
00294     *lda = 8;
00295     *ldc = 8;
00296     *lwork = 512;
00297 
00298     return;
00299 }
00300 
00301 /* Auxiliary functions: dormlq array parameters initialization */
00302 static void init_a( lapack_int size, double *a ) {
00303     lapack_int i;
00304     for( i = 0; i < size; i++ ) {
00305         a[i] = 0;
00306     }
00307     a[0] = 7.62923980485605120e+000;  /* a[0,0] */
00308     a[8] = -2.51355638263265290e-001;  /* a[0,1] */
00309     a[16] = 2.82008764880736670e-001;  /* a[0,2] */
00310     a[24] = -2.06908604667931820e-002;  /* a[0,3] */
00311     a[32] = -1.57863602079977600e-001;  /* a[0,4] */
00312     a[40] = -3.52510956100920840e-002;  /* a[0,5] */
00313     a[1] = 1.20680437835230640e-001;  /* a[1,0] */
00314     a[9] = 6.48479268997273990e+000;  /* a[1,1] */
00315     a[17] = 2.61441274102564740e-001;  /* a[1,2] */
00316     a[25] = 1.03257601872874400e-001;  /* a[1,3] */
00317     a[33] = 4.20095204298865380e-001;  /* a[1,4] */
00318     a[41] = 7.01058900740689300e-003;  /* a[1,5] */
00319     a[2] = 1.02146481161068170e-001;  /* a[2,0] */
00320     a[10] = -1.66186146532236250e+000;  /* a[2,1] */
00321     a[18] = -5.42658111212419050e+000;  /* a[2,2] */
00322     a[26] = 6.05137487741764240e-001;  /* a[2,3] */
00323     a[34] = -5.38668351256243130e-001;  /* a[2,4] */
00324     a[42] = 1.68593777638160250e-001;  /* a[2,5] */
00325     a[3] = 1.47663466979100420e+000;  /* a[3,0] */
00326     a[11] = 1.08823691868845880e-001;  /* a[3,1] */
00327     a[19] = 4.22288562190424880e-001;  /* a[3,2] */
00328     a[27] = 6.25553193791722250e+000;  /* a[3,3] */
00329     a[35] = -1.70447905668462570e-001;  /* a[3,4] */
00330     a[43] = -3.49862972443161500e-001;  /* a[3,5] */
00331 }
00332 static void init_tau( lapack_int size, double *tau ) {
00333     lapack_int i;
00334     for( i = 0; i < size; i++ ) {
00335         tau[i] = 0;
00336     }
00337     tau[0] = 1.71042464762349460e+000;
00338     tau[1] = 1.59293653559008600e+000;
00339     tau[2] = 1.18709943414798150e+000;
00340     tau[3] = 1.73693044165531460e+000;
00341 }
00342 static void init_c( lapack_int size, double *c ) {
00343     lapack_int i;
00344     for( i = 0; i < size; i++ ) {
00345         c[i] = 0;
00346     }
00347     c[0] = -3.76184269129046120e-001;  /* c[0,0] */
00348     c[8] = -6.85520462559202510e-001;  /* c[0,1] */
00349     c[1] = 2.58358001929011930e-001;  /* c[1,0] */
00350     c[9] = 5.74773824524868820e-002;  /* c[1,1] */
00351     c[2] = 5.62457066412861200e-001;  /* c[2,0] */
00352     c[10] = -9.07669644711465610e-001;  /* c[2,1] */
00353     c[3] = 1.18271648823068400e-001;  /* c[3,0] */
00354     c[11] = -1.12231752304341880e+000;  /* c[3,1] */
00355     c[4] = 0.00000000000000000e+000;  /* c[4,0] */
00356     c[12] = 0.00000000000000000e+000;  /* c[4,1] */
00357     c[5] = 0.00000000000000000e+000;  /* c[5,0] */
00358     c[13] = 0.00000000000000000e+000;  /* c[5,1] */
00359 }
00360 static void init_work( lapack_int size, double *work ) {
00361     lapack_int i;
00362     for( i = 0; i < size; i++ ) {
00363         work[i] = 0;
00364     }
00365 }
00366 
00367 /* Auxiliary function: C interface to dormlq results check */
00368 /* Return value: 0 - test is passed, non-zero - test is failed */
00369 static int compare_dormlq( double *c, double *c_i, lapack_int info,
00370                            lapack_int info_i, lapack_int ldc, lapack_int n )
00371 {
00372     lapack_int i;
00373     int failed = 0;
00374     for( i = 0; i < ldc*n; i++ ) {
00375         failed += compare_doubles(c[i],c_i[i]);
00376     }
00377     failed += (info == info_i) ? 0 : 1;
00378     if( info != 0 || info_i != 0 ) {
00379         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00380     }
00381 
00382     return failed;
00383 }


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