sorglq_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 * sorglq_2 is the test program for the C interface to LAPACK
00036 * routine sorglq
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_sorglq( lapack_int *m, lapack_int *n, lapack_int *k,
00055                                  lapack_int *lda, lapack_int *lwork );
00056 static void init_a( lapack_int size, float *a );
00057 static void init_tau( lapack_int size, float *tau );
00058 static void init_work( lapack_int size, float *work );
00059 static int compare_sorglq( float *a, float *a_i, lapack_int info,
00060                            lapack_int info_i, lapack_int lda, lapack_int n );
00061 
00062 int main(void)
00063 {
00064     /* Local scalars */
00065     lapack_int m, m_i;
00066     lapack_int n, n_i;
00067     lapack_int k, k_i;
00068     lapack_int lda, lda_i;
00069     lapack_int lda_r;
00070     lapack_int lwork, lwork_i;
00071     lapack_int info, info_i;
00072     lapack_int i;
00073     int failed;
00074 
00075     /* Local arrays */
00076     float *a = NULL, *a_i = NULL;
00077     float *tau = NULL, *tau_i = NULL;
00078     float *work = NULL, *work_i = NULL;
00079     float *a_save = NULL;
00080     float *a_r = NULL;
00081 
00082     /* Iniitialize the scalar parameters */
00083     init_scalars_sorglq( &m, &n, &k, &lda, &lwork );
00084     lda_r = n+2;
00085     m_i = m;
00086     n_i = n;
00087     k_i = k;
00088     lda_i = lda;
00089     lwork_i = lwork;
00090 
00091     /* Allocate memory for the LAPACK routine arrays */
00092     a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00093     tau = (float *)LAPACKE_malloc( k * sizeof(float) );
00094     work = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00095 
00096     /* Allocate memory for the C interface function arrays */
00097     a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00098     tau_i = (float *)LAPACKE_malloc( k * sizeof(float) );
00099     work_i = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00100 
00101     /* Allocate memory for the backup arrays */
00102     a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00103 
00104     /* Allocate memory for the row-major arrays */
00105     a_r = (float *)LAPACKE_malloc( m*(n+2) * sizeof(float) );
00106 
00107     /* Initialize input arrays */
00108     init_a( lda*n, a );
00109     init_tau( k, tau );
00110     init_work( lwork, work );
00111 
00112     /* Backup the ouptut arrays */
00113     for( i = 0; i < lda*n; i++ ) {
00114         a_save[i] = a[i];
00115     }
00116 
00117     /* Call the LAPACK routine */
00118     sorglq_( &m, &n, &k, a, &lda, tau, work, &lwork, &info );
00119 
00120     /* Initialize input data, call the column-major middle-level
00121      * interface to LAPACK routine and check the results */
00122     for( i = 0; i < lda*n; i++ ) {
00123         a_i[i] = a_save[i];
00124     }
00125     for( i = 0; i < k; i++ ) {
00126         tau_i[i] = tau[i];
00127     }
00128     for( i = 0; i < lwork; i++ ) {
00129         work_i[i] = work[i];
00130     }
00131     info_i = LAPACKE_sorglq_work( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i,
00132                                   tau_i, work_i, lwork_i );
00133 
00134     failed = compare_sorglq( a, a_i, info, info_i, lda, n );
00135     if( failed == 0 ) {
00136         printf( "PASSED: column-major middle-level interface to sorglq\n" );
00137     } else {
00138         printf( "FAILED: column-major middle-level interface to sorglq\n" );
00139     }
00140 
00141     /* Initialize input data, call the column-major high-level
00142      * interface to LAPACK routine and check the results */
00143     for( i = 0; i < lda*n; i++ ) {
00144         a_i[i] = a_save[i];
00145     }
00146     for( i = 0; i < k; i++ ) {
00147         tau_i[i] = tau[i];
00148     }
00149     for( i = 0; i < lwork; i++ ) {
00150         work_i[i] = work[i];
00151     }
00152     info_i = LAPACKE_sorglq( LAPACK_COL_MAJOR, m_i, n_i, k_i, a_i, lda_i,
00153                              tau_i );
00154 
00155     failed = compare_sorglq( a, a_i, info, info_i, lda, n );
00156     if( failed == 0 ) {
00157         printf( "PASSED: column-major high-level interface to sorglq\n" );
00158     } else {
00159         printf( "FAILED: column-major high-level interface to sorglq\n" );
00160     }
00161 
00162     /* Initialize input data, call the row-major middle-level
00163      * interface to LAPACK routine and check the results */
00164     for( i = 0; i < lda*n; i++ ) {
00165         a_i[i] = a_save[i];
00166     }
00167     for( i = 0; i < k; i++ ) {
00168         tau_i[i] = tau[i];
00169     }
00170     for( i = 0; i < lwork; i++ ) {
00171         work_i[i] = work[i];
00172     }
00173 
00174     LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00175     info_i = LAPACKE_sorglq_work( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r,
00176                                   tau_i, work_i, lwork_i );
00177 
00178     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00179 
00180     failed = compare_sorglq( a, a_i, info, info_i, lda, n );
00181     if( failed == 0 ) {
00182         printf( "PASSED: row-major middle-level interface to sorglq\n" );
00183     } else {
00184         printf( "FAILED: row-major middle-level interface to sorglq\n" );
00185     }
00186 
00187     /* Initialize input data, call the row-major high-level
00188      * interface to LAPACK routine and check the results */
00189     for( i = 0; i < lda*n; i++ ) {
00190         a_i[i] = a_save[i];
00191     }
00192     for( i = 0; i < k; i++ ) {
00193         tau_i[i] = tau[i];
00194     }
00195     for( i = 0; i < lwork; i++ ) {
00196         work_i[i] = work[i];
00197     }
00198 
00199     /* Init row_major arrays */
00200     LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00201     info_i = LAPACKE_sorglq( LAPACK_ROW_MAJOR, m_i, n_i, k_i, a_r, lda_r,
00202                              tau_i );
00203 
00204     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00205 
00206     failed = compare_sorglq( a, a_i, info, info_i, lda, n );
00207     if( failed == 0 ) {
00208         printf( "PASSED: row-major high-level interface to sorglq\n" );
00209     } else {
00210         printf( "FAILED: row-major high-level interface to sorglq\n" );
00211     }
00212 
00213     /* Release memory */
00214     if( a != NULL ) {
00215         LAPACKE_free( a );
00216     }
00217     if( a_i != NULL ) {
00218         LAPACKE_free( a_i );
00219     }
00220     if( a_r != NULL ) {
00221         LAPACKE_free( a_r );
00222     }
00223     if( a_save != NULL ) {
00224         LAPACKE_free( a_save );
00225     }
00226     if( tau != NULL ) {
00227         LAPACKE_free( tau );
00228     }
00229     if( tau_i != NULL ) {
00230         LAPACKE_free( tau_i );
00231     }
00232     if( work != NULL ) {
00233         LAPACKE_free( work );
00234     }
00235     if( work_i != NULL ) {
00236         LAPACKE_free( work_i );
00237     }
00238 
00239     return 0;
00240 }
00241 
00242 /* Auxiliary function: sorglq scalar parameters initialization */
00243 static void init_scalars_sorglq( lapack_int *m, lapack_int *n, lapack_int *k,
00244                                  lapack_int *lda, lapack_int *lwork )
00245 {
00246     *m = 6;
00247     *n = 6;
00248     *k = 4;
00249     *lda = 8;
00250     *lwork = 1024;
00251 
00252     return;
00253 }
00254 
00255 /* Auxiliary functions: sorglq array parameters initialization */
00256 static void init_a( lapack_int size, float *a ) {
00257     lapack_int i;
00258     for( i = 0; i < size; i++ ) {
00259         a[i] = 0;
00260     }
00261     a[0] = 7.629240036e+000;  /* a[0,0] */
00262     a[8] = -2.513556182e-001;  /* a[0,1] */
00263     a[16] = 2.820087671e-001;  /* a[0,2] */
00264     a[24] = -2.069086023e-002;  /* a[0,3] */
00265     a[32] = -1.578635871e-001;  /* a[0,4] */
00266     a[40] = -3.525109589e-002;  /* a[0,5] */
00267     a[1] = 0.000000000e+000;  /* a[1,0] */
00268     a[9] = 6.484792709e+000;  /* a[1,1] */
00269     a[17] = 2.614412904e-001;  /* a[1,2] */
00270     a[25] = 1.032576039e-001;  /* a[1,3] */
00271     a[33] = 4.200951755e-001;  /* a[1,4] */
00272     a[41] = 7.010589354e-003;  /* a[1,5] */
00273     a[2] = 0.000000000e+000;  /* a[2,0] */
00274     a[10] = 2.040916309e-002;  /* a[2,1] */
00275     a[18] = -5.426580906e+000;  /* a[2,2] */
00276     a[26] = 6.051375270e-001;  /* a[2,3] */
00277     a[34] = -5.386683345e-001;  /* a[2,4] */
00278     a[42] = 1.685937792e-001;  /* a[2,5] */
00279     a[3] = 0.000000000e+000;  /* a[3,0] */
00280     a[11] = -3.216264248e-001;  /* a[3,1] */
00281     a[19] = 1.342281103e-001;  /* a[3,2] */
00282     a[27] = 6.255532265e+000;  /* a[3,3] */
00283     a[35] = -1.704478860e-001;  /* a[3,4] */
00284     a[43] = -3.498629630e-001;  /* a[3,5] */
00285     a[4] = 0.000000000e+000;  /* a[4,0] */
00286     a[12] = 0.000000000e+000;  /* a[4,1] */
00287     a[20] = 0.000000000e+000;  /* a[4,2] */
00288     a[28] = 0.000000000e+000;  /* a[4,3] */
00289     a[36] = 0.000000000e+000;  /* a[4,4] */
00290     a[44] = 0.000000000e+000;  /* a[4,5] */
00291     a[5] = 0.000000000e+000;  /* a[5,0] */
00292     a[13] = 0.000000000e+000;  /* a[5,1] */
00293     a[21] = 0.000000000e+000;  /* a[5,2] */
00294     a[29] = 0.000000000e+000;  /* a[5,3] */
00295     a[37] = 0.000000000e+000;  /* a[5,4] */
00296     a[45] = 0.000000000e+000;  /* a[5,5] */
00297 }
00298 static void init_tau( lapack_int size, float *tau ) {
00299     lapack_int i;
00300     for( i = 0; i < size; i++ ) {
00301         tau[i] = 0;
00302     }
00303     tau[0] = 1.710424662e+000;
00304     tau[1] = 1.592936516e+000;
00305     tau[2] = 1.187099457e+000;
00306     tau[3] = 1.736930490e+000;
00307 }
00308 static void init_work( lapack_int size, float *work ) {
00309     lapack_int i;
00310     for( i = 0; i < size; i++ ) {
00311         work[i] = 0;
00312     }
00313 }
00314 
00315 /* Auxiliary function: C interface to sorglq results check */
00316 /* Return value: 0 - test is passed, non-zero - test is failed */
00317 static int compare_sorglq( float *a, float *a_i, lapack_int info,
00318                            lapack_int info_i, lapack_int lda, lapack_int n )
00319 {
00320     lapack_int i;
00321     int failed = 0;
00322     for( i = 0; i < lda*n; i++ ) {
00323         failed += compare_floats(a[i],a_i[i]);
00324     }
00325     failed += (info == info_i) ? 0 : 1;
00326     if( info != 0 || info_i != 0 ) {
00327         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00328     }
00329 
00330     return failed;
00331 }


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