stptrs_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 * stptrs_1 is the test program for the C interface to LAPACK
00036 * routine stptrs
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_stptrs( char *uplo, char *trans, char *diag,
00055                                  lapack_int *n, lapack_int *nrhs,
00056                                  lapack_int *ldb );
00057 static void init_ap( lapack_int size, float *ap );
00058 static void init_b( lapack_int size, float *b );
00059 static int compare_stptrs( float *b, float *b_i, lapack_int info,
00060                            lapack_int info_i, lapack_int ldb, lapack_int nrhs );
00061 
00062 int main(void)
00063 {
00064     /* Local scalars */
00065     char uplo, uplo_i;
00066     char trans, trans_i;
00067     char diag, diag_i;
00068     lapack_int n, n_i;
00069     lapack_int nrhs, nrhs_i;
00070     lapack_int ldb, ldb_i;
00071     lapack_int ldb_r;
00072     lapack_int info, info_i;
00073     lapack_int i;
00074     int failed;
00075 
00076     /* Local arrays */
00077     float *ap = NULL, *ap_i = NULL;
00078     float *b = NULL, *b_i = NULL;
00079     float *b_save = NULL;
00080     float *ap_r = NULL;
00081     float *b_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_stptrs( &uplo, &trans, &diag, &n, &nrhs, &ldb );
00085     ldb_r = nrhs+2;
00086     uplo_i = uplo;
00087     trans_i = trans;
00088     diag_i = diag;
00089     n_i = n;
00090     nrhs_i = nrhs;
00091     ldb_i = ldb;
00092 
00093     /* Allocate memory for the LAPACK routine arrays */
00094     ap = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00095     b = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00096 
00097     /* Allocate memory for the C interface function arrays */
00098     ap_i = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00099     b_i = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00100 
00101     /* Allocate memory for the backup arrays */
00102     b_save = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00103 
00104     /* Allocate memory for the row-major arrays */
00105     ap_r = (float *)LAPACKE_malloc( n*(n+1)/2 * sizeof(float) );
00106     b_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00107 
00108     /* Initialize input arrays */
00109     init_ap( (n*(n+1)/2), ap );
00110     init_b( ldb*nrhs, b );
00111 
00112     /* Backup the ouptut arrays */
00113     for( i = 0; i < ldb*nrhs; i++ ) {
00114         b_save[i] = b[i];
00115     }
00116 
00117     /* Call the LAPACK routine */
00118     stptrs_( &uplo, &trans, &diag, &n, &nrhs, ap, b, &ldb, &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 < (n*(n+1)/2); i++ ) {
00123         ap_i[i] = ap[i];
00124     }
00125     for( i = 0; i < ldb*nrhs; i++ ) {
00126         b_i[i] = b_save[i];
00127     }
00128     info_i = LAPACKE_stptrs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00129                                   n_i, nrhs_i, ap_i, b_i, ldb_i );
00130 
00131     failed = compare_stptrs( b, b_i, info, info_i, ldb, nrhs );
00132     if( failed == 0 ) {
00133         printf( "PASSED: column-major middle-level interface to stptrs\n" );
00134     } else {
00135         printf( "FAILED: column-major middle-level interface to stptrs\n" );
00136     }
00137 
00138     /* Initialize input data, call the column-major high-level
00139      * interface to LAPACK routine and check the results */
00140     for( i = 0; i < (n*(n+1)/2); i++ ) {
00141         ap_i[i] = ap[i];
00142     }
00143     for( i = 0; i < ldb*nrhs; i++ ) {
00144         b_i[i] = b_save[i];
00145     }
00146     info_i = LAPACKE_stptrs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00147                              nrhs_i, ap_i, b_i, ldb_i );
00148 
00149     failed = compare_stptrs( b, b_i, info, info_i, ldb, nrhs );
00150     if( failed == 0 ) {
00151         printf( "PASSED: column-major high-level interface to stptrs\n" );
00152     } else {
00153         printf( "FAILED: column-major high-level interface to stptrs\n" );
00154     }
00155 
00156     /* Initialize input data, call the row-major middle-level
00157      * interface to LAPACK routine and check the results */
00158     for( i = 0; i < (n*(n+1)/2); i++ ) {
00159         ap_i[i] = ap[i];
00160     }
00161     for( i = 0; i < ldb*nrhs; i++ ) {
00162         b_i[i] = b_save[i];
00163     }
00164 
00165     LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00166     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00167     info_i = LAPACKE_stptrs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00168                                   n_i, nrhs_i, ap_r, b_r, ldb_r );
00169 
00170     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00171 
00172     failed = compare_stptrs( b, b_i, info, info_i, ldb, nrhs );
00173     if( failed == 0 ) {
00174         printf( "PASSED: row-major middle-level interface to stptrs\n" );
00175     } else {
00176         printf( "FAILED: row-major middle-level interface to stptrs\n" );
00177     }
00178 
00179     /* Initialize input data, call the row-major high-level
00180      * interface to LAPACK routine and check the results */
00181     for( i = 0; i < (n*(n+1)/2); i++ ) {
00182         ap_i[i] = ap[i];
00183     }
00184     for( i = 0; i < ldb*nrhs; i++ ) {
00185         b_i[i] = b_save[i];
00186     }
00187 
00188     /* Init row_major arrays */
00189     LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00190     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00191     info_i = LAPACKE_stptrs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00192                              nrhs_i, ap_r, b_r, ldb_r );
00193 
00194     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00195 
00196     failed = compare_stptrs( b, b_i, info, info_i, ldb, nrhs );
00197     if( failed == 0 ) {
00198         printf( "PASSED: row-major high-level interface to stptrs\n" );
00199     } else {
00200         printf( "FAILED: row-major high-level interface to stptrs\n" );
00201     }
00202 
00203     /* Release memory */
00204     if( ap != NULL ) {
00205         LAPACKE_free( ap );
00206     }
00207     if( ap_i != NULL ) {
00208         LAPACKE_free( ap_i );
00209     }
00210     if( ap_r != NULL ) {
00211         LAPACKE_free( ap_r );
00212     }
00213     if( b != NULL ) {
00214         LAPACKE_free( b );
00215     }
00216     if( b_i != NULL ) {
00217         LAPACKE_free( b_i );
00218     }
00219     if( b_r != NULL ) {
00220         LAPACKE_free( b_r );
00221     }
00222     if( b_save != NULL ) {
00223         LAPACKE_free( b_save );
00224     }
00225 
00226     return 0;
00227 }
00228 
00229 /* Auxiliary function: stptrs scalar parameters initialization */
00230 static void init_scalars_stptrs( char *uplo, char *trans, char *diag,
00231                                  lapack_int *n, lapack_int *nrhs,
00232                                  lapack_int *ldb )
00233 {
00234     *uplo = 'L';
00235     *trans = 'N';
00236     *diag = 'N';
00237     *n = 4;
00238     *nrhs = 2;
00239     *ldb = 8;
00240 
00241     return;
00242 }
00243 
00244 /* Auxiliary functions: stptrs array parameters initialization */
00245 static void init_ap( lapack_int size, float *ap ) {
00246     lapack_int i;
00247     for( i = 0; i < size; i++ ) {
00248         ap[i] = 0;
00249     }
00250     ap[0] = 4.300000191e+000;
00251     ap[1] = -3.960000038e+000;
00252     ap[2] = 4.000000060e-001;
00253     ap[3] = -2.700000107e-001;
00254     ap[4] = -4.869999886e+000;
00255     ap[5] = 3.100000024e-001;
00256     ap[6] = 7.000000030e-002;
00257     ap[7] = -8.020000458e+000;
00258     ap[8] = -5.949999809e+000;
00259     ap[9] = 1.199999973e-001;
00260 }
00261 static void init_b( lapack_int size, float *b ) {
00262     lapack_int i;
00263     for( i = 0; i < size; i++ ) {
00264         b[i] = 0;
00265     }
00266     b[0] = -1.289999962e+001;  /* b[0,0] */
00267     b[8] = -2.150000000e+001;  /* b[0,1] */
00268     b[1] = 1.675000000e+001;  /* b[1,0] */
00269     b[9] = 1.493000031e+001;  /* b[1,1] */
00270     b[2] = -1.754999924e+001;  /* b[2,0] */
00271     b[10] = 6.329999924e+000;  /* b[2,1] */
00272     b[3] = -1.103999996e+001;  /* b[3,0] */
00273     b[11] = 8.090000153e+000;  /* b[3,1] */
00274 }
00275 
00276 /* Auxiliary function: C interface to stptrs results check */
00277 /* Return value: 0 - test is passed, non-zero - test is failed */
00278 static int compare_stptrs( float *b, float *b_i, lapack_int info,
00279                            lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00280 {
00281     lapack_int i;
00282     int failed = 0;
00283     for( i = 0; i < ldb*nrhs; i++ ) {
00284         failed += compare_floats(b[i],b_i[i]);
00285     }
00286     failed += (info == info_i) ? 0 : 1;
00287     if( info != 0 || info_i != 0 ) {
00288         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00289     }
00290 
00291     return failed;
00292 }


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