sopmtr_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 * sopmtr_1 is the test program for the C interface to LAPACK
00036 * routine sopmtr
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_sopmtr( char *side, char *uplo, char *trans,
00055                                  lapack_int *m, lapack_int *n,
00056                                  lapack_int *ldc );
00057 static void init_ap( lapack_int size, float *ap );
00058 static void init_tau( lapack_int size, float *tau );
00059 static void init_c( lapack_int size, float *c );
00060 static void init_work( lapack_int size, float *work );
00061 static int compare_sopmtr( float *c, float *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 uplo, uplo_i;
00069     char trans, trans_i;
00070     lapack_int m, m_i;
00071     lapack_int n, n_i;
00072     lapack_int ldc, ldc_i;
00073     lapack_int ldc_r;
00074     lapack_int info, info_i;
00075     /* Declare scalars */
00076     lapack_int lwork;
00077     lapack_int i;
00078     int failed;
00079 
00080     /* Local arrays */
00081     float *ap = NULL, *ap_i = NULL;
00082     float *tau = NULL, *tau_i = NULL;
00083     float *c = NULL, *c_i = NULL;
00084     float *work = NULL, *work_i = NULL;
00085     float *c_save = NULL;
00086     float *ap_r = NULL;
00087     float *c_r = NULL;
00088 
00089     /* Iniitialize the scalar parameters */
00090     init_scalars_sopmtr( &side, &uplo, &trans, &m, &n, &ldc );
00091     lwork = MAX(m,n);
00092     ldc_r = n+2;
00093     side_i = side;
00094     uplo_i = uplo;
00095     trans_i = trans;
00096     m_i = m;
00097     n_i = n;
00098     ldc_i = ldc;
00099 
00100     /* Allocate memory for the LAPACK routine arrays */
00101     ap = (float *)LAPACKE_malloc( ((m*(m+1)/2)) * sizeof(float) );
00102     tau = (float *)LAPACKE_malloc( (m-1) * sizeof(float) );
00103     c = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00104     work = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00105 
00106     /* Allocate memory for the C interface function arrays */
00107     ap_i = (float *)LAPACKE_malloc( ((m*(m+1)/2)) * sizeof(float) );
00108     tau_i = (float *)LAPACKE_malloc( (m-1) * sizeof(float) );
00109     c_i = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00110     work_i = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00111 
00112     /* Allocate memory for the backup arrays */
00113     c_save = (float *)LAPACKE_malloc( ldc*n * sizeof(float) );
00114 
00115     /* Allocate memory for the row-major arrays */
00116     ap_r = (float *)LAPACKE_malloc( m*(m+1)/2 * sizeof(float) );
00117     c_r = (float *)LAPACKE_malloc( m*(n+2) * sizeof(float) );
00118 
00119     /* Initialize input arrays */
00120     init_ap( (m*(m+1)/2), ap );
00121     init_tau( (m-1), tau );
00122     init_c( ldc*n, c );
00123     init_work( lwork, work );
00124 
00125     /* Backup the ouptut arrays */
00126     for( i = 0; i < ldc*n; i++ ) {
00127         c_save[i] = c[i];
00128     }
00129 
00130     /* Call the LAPACK routine */
00131     sopmtr_( &side, &uplo, &trans, &m, &n, ap, tau, c, &ldc, work, &info );
00132 
00133     /* Initialize input data, call the column-major middle-level
00134      * interface to LAPACK routine and check the results */
00135     for( i = 0; i < (m*(m+1)/2); i++ ) {
00136         ap_i[i] = ap[i];
00137     }
00138     for( i = 0; i < (m-1); i++ ) {
00139         tau_i[i] = tau[i];
00140     }
00141     for( i = 0; i < ldc*n; i++ ) {
00142         c_i[i] = c_save[i];
00143     }
00144     for( i = 0; i < lwork; i++ ) {
00145         work_i[i] = work[i];
00146     }
00147     info_i = LAPACKE_sopmtr_work( LAPACK_COL_MAJOR, side_i, uplo_i, trans_i,
00148                                   m_i, n_i, ap_i, tau_i, c_i, ldc_i, work_i );
00149 
00150     failed = compare_sopmtr( c, c_i, info, info_i, ldc, n );
00151     if( failed == 0 ) {
00152         printf( "PASSED: column-major middle-level interface to sopmtr\n" );
00153     } else {
00154         printf( "FAILED: column-major middle-level interface to sopmtr\n" );
00155     }
00156 
00157     /* Initialize input data, call the column-major high-level
00158      * interface to LAPACK routine and check the results */
00159     for( i = 0; i < (m*(m+1)/2); i++ ) {
00160         ap_i[i] = ap[i];
00161     }
00162     for( i = 0; i < (m-1); i++ ) {
00163         tau_i[i] = tau[i];
00164     }
00165     for( i = 0; i < ldc*n; i++ ) {
00166         c_i[i] = c_save[i];
00167     }
00168     for( i = 0; i < lwork; i++ ) {
00169         work_i[i] = work[i];
00170     }
00171     info_i = LAPACKE_sopmtr( LAPACK_COL_MAJOR, side_i, uplo_i, trans_i, m_i,
00172                              n_i, ap_i, tau_i, c_i, ldc_i );
00173 
00174     failed = compare_sopmtr( c, c_i, info, info_i, ldc, n );
00175     if( failed == 0 ) {
00176         printf( "PASSED: column-major high-level interface to sopmtr\n" );
00177     } else {
00178         printf( "FAILED: column-major high-level interface to sopmtr\n" );
00179     }
00180 
00181     /* Initialize input data, call the row-major middle-level
00182      * interface to LAPACK routine and check the results */
00183     for( i = 0; i < (m*(m+1)/2); i++ ) {
00184         ap_i[i] = ap[i];
00185     }
00186     for( i = 0; i < (m-1); i++ ) {
00187         tau_i[i] = tau[i];
00188     }
00189     for( i = 0; i < ldc*n; i++ ) {
00190         c_i[i] = c_save[i];
00191     }
00192     for( i = 0; i < lwork; i++ ) {
00193         work_i[i] = work[i];
00194     }
00195 
00196     LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, m, ap_i, ap_r );
00197     LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00198     info_i = LAPACKE_sopmtr_work( LAPACK_ROW_MAJOR, side_i, uplo_i, trans_i,
00199                                   m_i, n_i, ap_r, tau_i, c_r, ldc_r, work_i );
00200 
00201     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00202 
00203     failed = compare_sopmtr( c, c_i, info, info_i, ldc, n );
00204     if( failed == 0 ) {
00205         printf( "PASSED: row-major middle-level interface to sopmtr\n" );
00206     } else {
00207         printf( "FAILED: row-major middle-level interface to sopmtr\n" );
00208     }
00209 
00210     /* Initialize input data, call the row-major high-level
00211      * interface to LAPACK routine and check the results */
00212     for( i = 0; i < (m*(m+1)/2); i++ ) {
00213         ap_i[i] = ap[i];
00214     }
00215     for( i = 0; i < (m-1); i++ ) {
00216         tau_i[i] = tau[i];
00217     }
00218     for( i = 0; i < ldc*n; i++ ) {
00219         c_i[i] = c_save[i];
00220     }
00221     for( i = 0; i < lwork; i++ ) {
00222         work_i[i] = work[i];
00223     }
00224 
00225     /* Init row_major arrays */
00226     LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, m, ap_i, ap_r );
00227     LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00228     info_i = LAPACKE_sopmtr( LAPACK_ROW_MAJOR, side_i, uplo_i, trans_i, m_i,
00229                              n_i, ap_r, tau_i, c_r, ldc_r );
00230 
00231     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00232 
00233     failed = compare_sopmtr( c, c_i, info, info_i, ldc, n );
00234     if( failed == 0 ) {
00235         printf( "PASSED: row-major high-level interface to sopmtr\n" );
00236     } else {
00237         printf( "FAILED: row-major high-level interface to sopmtr\n" );
00238     }
00239 
00240     /* Release memory */
00241     if( ap != NULL ) {
00242         LAPACKE_free( ap );
00243     }
00244     if( ap_i != NULL ) {
00245         LAPACKE_free( ap_i );
00246     }
00247     if( ap_r != NULL ) {
00248         LAPACKE_free( ap_r );
00249     }
00250     if( tau != NULL ) {
00251         LAPACKE_free( tau );
00252     }
00253     if( tau_i != NULL ) {
00254         LAPACKE_free( tau_i );
00255     }
00256     if( c != NULL ) {
00257         LAPACKE_free( c );
00258     }
00259     if( c_i != NULL ) {
00260         LAPACKE_free( c_i );
00261     }
00262     if( c_r != NULL ) {
00263         LAPACKE_free( c_r );
00264     }
00265     if( c_save != NULL ) {
00266         LAPACKE_free( c_save );
00267     }
00268     if( work != NULL ) {
00269         LAPACKE_free( work );
00270     }
00271     if( work_i != NULL ) {
00272         LAPACKE_free( work_i );
00273     }
00274 
00275     return 0;
00276 }
00277 
00278 /* Auxiliary function: sopmtr scalar parameters initialization */
00279 static void init_scalars_sopmtr( char *side, char *uplo, char *trans,
00280                                  lapack_int *m, lapack_int *n, lapack_int *ldc )
00281 {
00282     *side = 'L';
00283     *uplo = 'L';
00284     *trans = 'N';
00285     *m = 4;
00286     *n = 2;
00287     *ldc = 8;
00288 
00289     return;
00290 }
00291 
00292 /* Auxiliary functions: sopmtr array parameters initialization */
00293 static void init_ap( lapack_int size, float *ap ) {
00294     lapack_int i;
00295     for( i = 0; i < size; i++ ) {
00296         ap[i] = 0;
00297     }
00298     ap[0] = 2.069999933e+000;
00299     ap[1] = -5.825753212e+000;
00300     ap[2] = 4.331793189e-001;
00301     ap[3] = -1.186086312e-001;
00302     ap[4] = 1.474093199e+000;
00303     ap[5] = 2.624044895e+000;
00304     ap[6] = 8.062880635e-001;
00305     ap[7] = -6.491593122e-001;
00306     ap[8] = 9.162727594e-001;
00307     ap[9] = -1.694934368e+000;
00308 }
00309 static void init_tau( lapack_int size, float *tau ) {
00310     lapack_int i;
00311     for( i = 0; i < size; i++ ) {
00312         tau[i] = 0;
00313     }
00314     tau[0] = 1.664291739e+000;
00315     tau[1] = 1.212047458e+000;
00316     tau[2] = 0.000000000e+000;
00317 }
00318 static void init_c( lapack_int size, float *c ) {
00319     lapack_int i;
00320     for( i = 0; i < size; i++ ) {
00321         c[i] = 0;
00322     }
00323     c[0] = 5.657591820e-001;  /* c[0,0] */
00324     c[8] = -2.328424156e-001;  /* c[0,1] */
00325     c[1] = 6.869179606e-001;  /* c[1,0] */
00326     c[9] = -1.626171023e-001;  /* c[1,1] */
00327     c[2] = -4.395889342e-001;  /* c[2,0] */
00328     c[10] = -3.017273545e-001;  /* c[2,1] */
00329     c[3] = 1.217449754e-001;  /* c[3,0] */
00330     c[11] = 9.101103544e-001;  /* c[3,1] */
00331 }
00332 static void init_work( lapack_int size, float *work ) {
00333     lapack_int i;
00334     for( i = 0; i < size; i++ ) {
00335         work[i] = 0;
00336     }
00337 }
00338 
00339 /* Auxiliary function: C interface to sopmtr results check */
00340 /* Return value: 0 - test is passed, non-zero - test is failed */
00341 static int compare_sopmtr( float *c, float *c_i, lapack_int info,
00342                            lapack_int info_i, lapack_int ldc, lapack_int n )
00343 {
00344     lapack_int i;
00345     int failed = 0;
00346     for( i = 0; i < ldc*n; i++ ) {
00347         failed += compare_floats(c[i],c_i[i]);
00348     }
00349     failed += (info == info_i) ? 0 : 1;
00350     if( info != 0 || info_i != 0 ) {
00351         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00352     }
00353 
00354     return failed;
00355 }


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