ssptrs_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 * ssptrs_1 is the test program for the C interface to LAPACK
00036 * routine ssptrs
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_ssptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00055                                  lapack_int *ldb );
00056 static void init_ap( lapack_int size, float *ap );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_b( lapack_int size, float *b );
00059 static int compare_ssptrs( 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     lapack_int n, n_i;
00067     lapack_int nrhs, nrhs_i;
00068     lapack_int ldb, ldb_i;
00069     lapack_int ldb_r;
00070     lapack_int info, info_i;
00071     lapack_int i;
00072     int failed;
00073 
00074     /* Local arrays */
00075     float *ap = NULL, *ap_i = NULL;
00076     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00077     float *b = NULL, *b_i = NULL;
00078     float *b_save = NULL;
00079     float *ap_r = NULL;
00080     float *b_r = NULL;
00081 
00082     /* Iniitialize the scalar parameters */
00083     init_scalars_ssptrs( &uplo, &n, &nrhs, &ldb );
00084     ldb_r = nrhs+2;
00085     uplo_i = uplo;
00086     n_i = n;
00087     nrhs_i = nrhs;
00088     ldb_i = ldb;
00089 
00090     /* Allocate memory for the LAPACK routine arrays */
00091     ap = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00092     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00093     b = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00094 
00095     /* Allocate memory for the C interface function arrays */
00096     ap_i = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00097     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00098     b_i = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00099 
00100     /* Allocate memory for the backup arrays */
00101     b_save = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00102 
00103     /* Allocate memory for the row-major arrays */
00104     ap_r = (float *)LAPACKE_malloc( n*(n+1)/2 * sizeof(float) );
00105     b_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00106 
00107     /* Initialize input arrays */
00108     init_ap( (n*(n+1)/2), ap );
00109     init_ipiv( n, ipiv );
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     ssptrs_( &uplo, &n, &nrhs, ap, ipiv, 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 < n; i++ ) {
00126         ipiv_i[i] = ipiv[i];
00127     }
00128     for( i = 0; i < ldb*nrhs; i++ ) {
00129         b_i[i] = b_save[i];
00130     }
00131     info_i = LAPACKE_ssptrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00132                                   ipiv_i, b_i, ldb_i );
00133 
00134     failed = compare_ssptrs( b, b_i, info, info_i, ldb, nrhs );
00135     if( failed == 0 ) {
00136         printf( "PASSED: column-major middle-level interface to ssptrs\n" );
00137     } else {
00138         printf( "FAILED: column-major middle-level interface to ssptrs\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 < (n*(n+1)/2); i++ ) {
00144         ap_i[i] = ap[i];
00145     }
00146     for( i = 0; i < n; i++ ) {
00147         ipiv_i[i] = ipiv[i];
00148     }
00149     for( i = 0; i < ldb*nrhs; i++ ) {
00150         b_i[i] = b_save[i];
00151     }
00152     info_i = LAPACKE_ssptrs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00153                              ipiv_i, b_i, ldb_i );
00154 
00155     failed = compare_ssptrs( b, b_i, info, info_i, ldb, nrhs );
00156     if( failed == 0 ) {
00157         printf( "PASSED: column-major high-level interface to ssptrs\n" );
00158     } else {
00159         printf( "FAILED: column-major high-level interface to ssptrs\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 < (n*(n+1)/2); i++ ) {
00165         ap_i[i] = ap[i];
00166     }
00167     for( i = 0; i < n; i++ ) {
00168         ipiv_i[i] = ipiv[i];
00169     }
00170     for( i = 0; i < ldb*nrhs; i++ ) {
00171         b_i[i] = b_save[i];
00172     }
00173 
00174     LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00175     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00176     info_i = LAPACKE_ssptrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00177                                   ipiv_i, b_r, ldb_r );
00178 
00179     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00180 
00181     failed = compare_ssptrs( b, b_i, info, info_i, ldb, nrhs );
00182     if( failed == 0 ) {
00183         printf( "PASSED: row-major middle-level interface to ssptrs\n" );
00184     } else {
00185         printf( "FAILED: row-major middle-level interface to ssptrs\n" );
00186     }
00187 
00188     /* Initialize input data, call the row-major high-level
00189      * interface to LAPACK routine and check the results */
00190     for( i = 0; i < (n*(n+1)/2); i++ ) {
00191         ap_i[i] = ap[i];
00192     }
00193     for( i = 0; i < n; i++ ) {
00194         ipiv_i[i] = ipiv[i];
00195     }
00196     for( i = 0; i < ldb*nrhs; i++ ) {
00197         b_i[i] = b_save[i];
00198     }
00199 
00200     /* Init row_major arrays */
00201     LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00202     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00203     info_i = LAPACKE_ssptrs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00204                              ipiv_i, b_r, ldb_r );
00205 
00206     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00207 
00208     failed = compare_ssptrs( b, b_i, info, info_i, ldb, nrhs );
00209     if( failed == 0 ) {
00210         printf( "PASSED: row-major high-level interface to ssptrs\n" );
00211     } else {
00212         printf( "FAILED: row-major high-level interface to ssptrs\n" );
00213     }
00214 
00215     /* Release memory */
00216     if( ap != NULL ) {
00217         LAPACKE_free( ap );
00218     }
00219     if( ap_i != NULL ) {
00220         LAPACKE_free( ap_i );
00221     }
00222     if( ap_r != NULL ) {
00223         LAPACKE_free( ap_r );
00224     }
00225     if( ipiv != NULL ) {
00226         LAPACKE_free( ipiv );
00227     }
00228     if( ipiv_i != NULL ) {
00229         LAPACKE_free( ipiv_i );
00230     }
00231     if( b != NULL ) {
00232         LAPACKE_free( b );
00233     }
00234     if( b_i != NULL ) {
00235         LAPACKE_free( b_i );
00236     }
00237     if( b_r != NULL ) {
00238         LAPACKE_free( b_r );
00239     }
00240     if( b_save != NULL ) {
00241         LAPACKE_free( b_save );
00242     }
00243 
00244     return 0;
00245 }
00246 
00247 /* Auxiliary function: ssptrs scalar parameters initialization */
00248 static void init_scalars_ssptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00249                                  lapack_int *ldb )
00250 {
00251     *uplo = 'L';
00252     *n = 4;
00253     *nrhs = 2;
00254     *ldb = 8;
00255 
00256     return;
00257 }
00258 
00259 /* Auxiliary functions: ssptrs array parameters initialization */
00260 static void init_ap( lapack_int size, float *ap ) {
00261     lapack_int i;
00262     for( i = 0; i < size; i++ ) {
00263         ap[i] = 0;
00264     }
00265     ap[0] = 2.069999933e+000;
00266     ap[1] = 4.199999809e+000;
00267     ap[2] = 2.230414152e-001;
00268     ap[3] = 6.536583900e-001;
00269     ap[4] = 1.149999976e+000;
00270     ap[5] = 8.115010262e-001;
00271     ap[6] = -5.959697366e-001;
00272     ap[7] = -2.590677261e+000;
00273     ap[8] = 3.030846119e-001;
00274     ap[9] = 4.073850811e-001;
00275 }
00276 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00277     lapack_int i;
00278     for( i = 0; i < size; i++ ) {
00279         ipiv[i] = 0;
00280     }
00281     ipiv[0] = -3;
00282     ipiv[1] = -3;
00283     ipiv[2] = 3;
00284     ipiv[3] = 4;
00285 }
00286 static void init_b( lapack_int size, float *b ) {
00287     lapack_int i;
00288     for( i = 0; i < size; i++ ) {
00289         b[i] = 0;
00290     }
00291     b[0] = -9.500000000e+000;  /* b[0,0] */
00292     b[8] = 2.785000038e+001;  /* b[0,1] */
00293     b[1] = -8.380000114e+000;  /* b[1,0] */
00294     b[9] = 9.899999619e+000;  /* b[1,1] */
00295     b[2] = -6.070000172e+000;  /* b[2,0] */
00296     b[10] = 1.925000000e+001;  /* b[2,1] */
00297     b[3] = -9.599999785e-001;  /* b[3,0] */
00298     b[11] = 3.930000067e+000;  /* b[3,1] */
00299 }
00300 
00301 /* Auxiliary function: C interface to ssptrs results check */
00302 /* Return value: 0 - test is passed, non-zero - test is failed */
00303 static int compare_ssptrs( float *b, float *b_i, lapack_int info,
00304                            lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00305 {
00306     lapack_int i;
00307     int failed = 0;
00308     for( i = 0; i < ldb*nrhs; i++ ) {
00309         failed += compare_floats(b[i],b_i[i]);
00310     }
00311     failed += (info == info_i) ? 0 : 1;
00312     if( info != 0 || info_i != 0 ) {
00313         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00314     }
00315 
00316     return failed;
00317 }


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