ztptrs_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 * ztptrs_1 is the test program for the C interface to LAPACK
00036 * routine ztptrs
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_ztptrs( 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, lapack_complex_double *ap );
00058 static void init_b( lapack_int size, lapack_complex_double *b );
00059 static int compare_ztptrs( lapack_complex_double *b, lapack_complex_double *b_i,
00060                            lapack_int info, lapack_int info_i, lapack_int ldb,
00061                            lapack_int nrhs );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char uplo, uplo_i;
00067     char trans, trans_i;
00068     char diag, diag_i;
00069     lapack_int n, n_i;
00070     lapack_int nrhs, nrhs_i;
00071     lapack_int ldb, ldb_i;
00072     lapack_int ldb_r;
00073     lapack_int info, info_i;
00074     lapack_int i;
00075     int failed;
00076 
00077     /* Local arrays */
00078     lapack_complex_double *ap = NULL, *ap_i = NULL;
00079     lapack_complex_double *b = NULL, *b_i = NULL;
00080     lapack_complex_double *b_save = NULL;
00081     lapack_complex_double *ap_r = NULL;
00082     lapack_complex_double *b_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_ztptrs( &uplo, &trans, &diag, &n, &nrhs, &ldb );
00086     ldb_r = nrhs+2;
00087     uplo_i = uplo;
00088     trans_i = trans;
00089     diag_i = diag;
00090     n_i = n;
00091     nrhs_i = nrhs;
00092     ldb_i = ldb;
00093 
00094     /* Allocate memory for the LAPACK routine arrays */
00095     ap = (lapack_complex_double *)
00096         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00097     b = (lapack_complex_double *)
00098         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00099 
00100     /* Allocate memory for the C interface function arrays */
00101     ap_i = (lapack_complex_double *)
00102         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00103     b_i = (lapack_complex_double *)
00104         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00105 
00106     /* Allocate memory for the backup arrays */
00107     b_save = (lapack_complex_double *)
00108         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00109 
00110     /* Allocate memory for the row-major arrays */
00111     ap_r = (lapack_complex_double *)
00112         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00113     b_r = (lapack_complex_double *)
00114         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00115 
00116     /* Initialize input arrays */
00117     init_ap( (n*(n+1)/2), ap );
00118     init_b( ldb*nrhs, b );
00119 
00120     /* Backup the ouptut arrays */
00121     for( i = 0; i < ldb*nrhs; i++ ) {
00122         b_save[i] = b[i];
00123     }
00124 
00125     /* Call the LAPACK routine */
00126     ztptrs_( &uplo, &trans, &diag, &n, &nrhs, ap, b, &ldb, &info );
00127 
00128     /* Initialize input data, call the column-major middle-level
00129      * interface to LAPACK routine and check the results */
00130     for( i = 0; i < (n*(n+1)/2); i++ ) {
00131         ap_i[i] = ap[i];
00132     }
00133     for( i = 0; i < ldb*nrhs; i++ ) {
00134         b_i[i] = b_save[i];
00135     }
00136     info_i = LAPACKE_ztptrs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00137                                   n_i, nrhs_i, ap_i, b_i, ldb_i );
00138 
00139     failed = compare_ztptrs( b, b_i, info, info_i, ldb, nrhs );
00140     if( failed == 0 ) {
00141         printf( "PASSED: column-major middle-level interface to ztptrs\n" );
00142     } else {
00143         printf( "FAILED: column-major middle-level interface to ztptrs\n" );
00144     }
00145 
00146     /* Initialize input data, call the column-major high-level
00147      * interface to LAPACK routine and check the results */
00148     for( i = 0; i < (n*(n+1)/2); i++ ) {
00149         ap_i[i] = ap[i];
00150     }
00151     for( i = 0; i < ldb*nrhs; i++ ) {
00152         b_i[i] = b_save[i];
00153     }
00154     info_i = LAPACKE_ztptrs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00155                              nrhs_i, ap_i, b_i, ldb_i );
00156 
00157     failed = compare_ztptrs( b, b_i, info, info_i, ldb, nrhs );
00158     if( failed == 0 ) {
00159         printf( "PASSED: column-major high-level interface to ztptrs\n" );
00160     } else {
00161         printf( "FAILED: column-major high-level interface to ztptrs\n" );
00162     }
00163 
00164     /* Initialize input data, call the row-major middle-level
00165      * interface to LAPACK routine and check the results */
00166     for( i = 0; i < (n*(n+1)/2); i++ ) {
00167         ap_i[i] = ap[i];
00168     }
00169     for( i = 0; i < ldb*nrhs; i++ ) {
00170         b_i[i] = b_save[i];
00171     }
00172 
00173     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00174     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00175     info_i = LAPACKE_ztptrs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00176                                   n_i, nrhs_i, ap_r, b_r, ldb_r );
00177 
00178     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00179 
00180     failed = compare_ztptrs( b, b_i, info, info_i, ldb, nrhs );
00181     if( failed == 0 ) {
00182         printf( "PASSED: row-major middle-level interface to ztptrs\n" );
00183     } else {
00184         printf( "FAILED: row-major middle-level interface to ztptrs\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 < (n*(n+1)/2); i++ ) {
00190         ap_i[i] = ap[i];
00191     }
00192     for( i = 0; i < ldb*nrhs; i++ ) {
00193         b_i[i] = b_save[i];
00194     }
00195 
00196     /* Init row_major arrays */
00197     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00199     info_i = LAPACKE_ztptrs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00200                              nrhs_i, ap_r, b_r, ldb_r );
00201 
00202     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00203 
00204     failed = compare_ztptrs( b, b_i, info, info_i, ldb, nrhs );
00205     if( failed == 0 ) {
00206         printf( "PASSED: row-major high-level interface to ztptrs\n" );
00207     } else {
00208         printf( "FAILED: row-major high-level interface to ztptrs\n" );
00209     }
00210 
00211     /* Release memory */
00212     if( ap != NULL ) {
00213         LAPACKE_free( ap );
00214     }
00215     if( ap_i != NULL ) {
00216         LAPACKE_free( ap_i );
00217     }
00218     if( ap_r != NULL ) {
00219         LAPACKE_free( ap_r );
00220     }
00221     if( b != NULL ) {
00222         LAPACKE_free( b );
00223     }
00224     if( b_i != NULL ) {
00225         LAPACKE_free( b_i );
00226     }
00227     if( b_r != NULL ) {
00228         LAPACKE_free( b_r );
00229     }
00230     if( b_save != NULL ) {
00231         LAPACKE_free( b_save );
00232     }
00233 
00234     return 0;
00235 }
00236 
00237 /* Auxiliary function: ztptrs scalar parameters initialization */
00238 static void init_scalars_ztptrs( char *uplo, char *trans, char *diag,
00239                                  lapack_int *n, lapack_int *nrhs,
00240                                  lapack_int *ldb )
00241 {
00242     *uplo = 'L';
00243     *trans = 'N';
00244     *diag = 'N';
00245     *n = 4;
00246     *nrhs = 2;
00247     *ldb = 8;
00248 
00249     return;
00250 }
00251 
00252 /* Auxiliary functions: ztptrs array parameters initialization */
00253 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00254     lapack_int i;
00255     for( i = 0; i < size; i++ ) {
00256         ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00257     }
00258     ap[0] = lapack_make_complex_double( 4.78000000000000020e+000,
00259                                         4.55999999999999960e+000 );
00260     ap[1] = lapack_make_complex_double( 2.00000000000000000e+000,
00261                                         -2.99999999999999990e-001 );
00262     ap[2] = lapack_make_complex_double( 2.89000000000000010e+000,
00263                                         -1.34000000000000010e+000 );
00264     ap[3] = lapack_make_complex_double( -1.88999999999999990e+000,
00265                                         1.14999999999999990e+000 );
00266     ap[4] = lapack_make_complex_double( -4.11000000000000030e+000,
00267                                         1.25000000000000000e+000 );
00268     ap[5] = lapack_make_complex_double( 2.35999999999999990e+000,
00269                                         -4.25000000000000000e+000 );
00270     ap[6] = lapack_make_complex_double( 4.00000000000000010e-002,
00271                                         -3.68999999999999990e+000 );
00272     ap[7] = lapack_make_complex_double( 4.15000000000000040e+000,
00273                                         8.00000000000000040e-001 );
00274     ap[8] = lapack_make_complex_double( -2.00000000000000000e-002,
00275                                         4.60000000000000020e-001 );
00276     ap[9] = lapack_make_complex_double( 3.30000000000000020e-001,
00277                                         -2.60000000000000010e-001 );
00278 }
00279 static void init_b( lapack_int size, lapack_complex_double *b ) {
00280     lapack_int i;
00281     for( i = 0; i < size; i++ ) {
00282         b[i] = lapack_make_complex_double( 0.0, 0.0 );
00283     }
00284     b[0] = lapack_make_complex_double( -1.47799999999999990e+001,
00285                                        -3.23599999999999990e+001 );
00286     b[8] = lapack_make_complex_double( -1.80200000000000000e+001,
00287                                        2.84600000000000010e+001 );
00288     b[1] = lapack_make_complex_double( 2.98000000000000000e+000,
00289                                        -2.14000000000000010e+000 );
00290     b[9] = lapack_make_complex_double( 1.42200000000000010e+001,
00291                                        1.54200000000000000e+001 );
00292     b[2] = lapack_make_complex_double( -2.09600000000000010e+001,
00293                                        1.70599999999999990e+001 );
00294     b[10] = lapack_make_complex_double( 5.62000000000000010e+000,
00295                                         3.58900000000000010e+001 );
00296     b[3] = lapack_make_complex_double( 9.53999999999999910e+000,
00297                                        9.91000000000000010e+000 );
00298     b[11] = lapack_make_complex_double( -1.64600000000000010e+001,
00299                                         -1.73000000000000000e+000 );
00300 }
00301 
00302 /* Auxiliary function: C interface to ztptrs results check */
00303 /* Return value: 0 - test is passed, non-zero - test is failed */
00304 static int compare_ztptrs( lapack_complex_double *b, lapack_complex_double *b_i,
00305                            lapack_int info, lapack_int info_i, lapack_int ldb,
00306                            lapack_int nrhs )
00307 {
00308     lapack_int i;
00309     int failed = 0;
00310     for( i = 0; i < ldb*nrhs; i++ ) {
00311         failed += compare_complex_doubles(b[i],b_i[i]);
00312     }
00313     failed += (info == info_i) ? 0 : 1;
00314     if( info != 0 || info_i != 0 ) {
00315         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00316     }
00317 
00318     return failed;
00319 }


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