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


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