ztptri_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 * ztptri_1 is the test program for the C interface to LAPACK
00036 * routine ztptri
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_ztptri( char *uplo, char *diag, lapack_int *n );
00055 static void init_ap( lapack_int size, lapack_complex_double *ap );
00056 static int compare_ztptri( lapack_complex_double *ap,
00057                            lapack_complex_double *ap_i, lapack_int info,
00058                            lapack_int info_i, lapack_int n );
00059 
00060 int main(void)
00061 {
00062     /* Local scalars */
00063     char uplo, uplo_i;
00064     char diag, diag_i;
00065     lapack_int n, n_i;
00066     lapack_int info, info_i;
00067     lapack_int i;
00068     int failed;
00069 
00070     /* Local arrays */
00071     lapack_complex_double *ap = NULL, *ap_i = NULL;
00072     lapack_complex_double *ap_save = NULL;
00073     lapack_complex_double *ap_r = NULL;
00074 
00075     /* Iniitialize the scalar parameters */
00076     init_scalars_ztptri( &uplo, &diag, &n );
00077     uplo_i = uplo;
00078     diag_i = diag;
00079     n_i = n;
00080 
00081     /* Allocate memory for the LAPACK routine arrays */
00082     ap = (lapack_complex_double *)
00083         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00084 
00085     /* Allocate memory for the C interface function arrays */
00086     ap_i = (lapack_complex_double *)
00087         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00088 
00089     /* Allocate memory for the backup arrays */
00090     ap_save = (lapack_complex_double *)
00091         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00092 
00093     /* Allocate memory for the row-major arrays */
00094     ap_r = (lapack_complex_double *)
00095         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00096 
00097     /* Initialize input arrays */
00098     init_ap( (n*(n+1)/2), ap );
00099 
00100     /* Backup the ouptut arrays */
00101     for( i = 0; i < (n*(n+1)/2); i++ ) {
00102         ap_save[i] = ap[i];
00103     }
00104 
00105     /* Call the LAPACK routine */
00106     ztptri_( &uplo, &diag, &n, ap, &info );
00107 
00108     /* Initialize input data, call the column-major middle-level
00109      * interface to LAPACK routine and check the results */
00110     for( i = 0; i < (n*(n+1)/2); i++ ) {
00111         ap_i[i] = ap_save[i];
00112     }
00113     info_i = LAPACKE_ztptri_work( LAPACK_COL_MAJOR, uplo_i, diag_i, n_i, ap_i );
00114 
00115     failed = compare_ztptri( ap, ap_i, info, info_i, n );
00116     if( failed == 0 ) {
00117         printf( "PASSED: column-major middle-level interface to ztptri\n" );
00118     } else {
00119         printf( "FAILED: column-major middle-level interface to ztptri\n" );
00120     }
00121 
00122     /* Initialize input data, call the column-major high-level
00123      * interface to LAPACK routine and check the results */
00124     for( i = 0; i < (n*(n+1)/2); i++ ) {
00125         ap_i[i] = ap_save[i];
00126     }
00127     info_i = LAPACKE_ztptri( LAPACK_COL_MAJOR, uplo_i, diag_i, n_i, ap_i );
00128 
00129     failed = compare_ztptri( ap, ap_i, info, info_i, n );
00130     if( failed == 0 ) {
00131         printf( "PASSED: column-major high-level interface to ztptri\n" );
00132     } else {
00133         printf( "FAILED: column-major high-level interface to ztptri\n" );
00134     }
00135 
00136     /* Initialize input data, call the row-major middle-level
00137      * interface to LAPACK routine and check the results */
00138     for( i = 0; i < (n*(n+1)/2); i++ ) {
00139         ap_i[i] = ap_save[i];
00140     }
00141 
00142     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00143     info_i = LAPACKE_ztptri_work( LAPACK_ROW_MAJOR, uplo_i, diag_i, n_i, ap_r );
00144 
00145     LAPACKE_zpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00146 
00147     failed = compare_ztptri( ap, ap_i, info, info_i, n );
00148     if( failed == 0 ) {
00149         printf( "PASSED: row-major middle-level interface to ztptri\n" );
00150     } else {
00151         printf( "FAILED: row-major middle-level interface to ztptri\n" );
00152     }
00153 
00154     /* Initialize input data, call the row-major high-level
00155      * interface to LAPACK routine and check the results */
00156     for( i = 0; i < (n*(n+1)/2); i++ ) {
00157         ap_i[i] = ap_save[i];
00158     }
00159 
00160     /* Init row_major arrays */
00161     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00162     info_i = LAPACKE_ztptri( LAPACK_ROW_MAJOR, uplo_i, diag_i, n_i, ap_r );
00163 
00164     LAPACKE_zpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00165 
00166     failed = compare_ztptri( ap, ap_i, info, info_i, n );
00167     if( failed == 0 ) {
00168         printf( "PASSED: row-major high-level interface to ztptri\n" );
00169     } else {
00170         printf( "FAILED: row-major high-level interface to ztptri\n" );
00171     }
00172 
00173     /* Release memory */
00174     if( ap != NULL ) {
00175         LAPACKE_free( ap );
00176     }
00177     if( ap_i != NULL ) {
00178         LAPACKE_free( ap_i );
00179     }
00180     if( ap_r != NULL ) {
00181         LAPACKE_free( ap_r );
00182     }
00183     if( ap_save != NULL ) {
00184         LAPACKE_free( ap_save );
00185     }
00186 
00187     return 0;
00188 }
00189 
00190 /* Auxiliary function: ztptri scalar parameters initialization */
00191 static void init_scalars_ztptri( char *uplo, char *diag, lapack_int *n )
00192 {
00193     *uplo = 'L';
00194     *diag = 'N';
00195     *n = 4;
00196 
00197     return;
00198 }
00199 
00200 /* Auxiliary functions: ztptri array parameters initialization */
00201 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00202     lapack_int i;
00203     for( i = 0; i < size; i++ ) {
00204         ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00205     }
00206     ap[0] = lapack_make_complex_double( 4.78000000000000020e+000,
00207                                         4.55999999999999960e+000 );
00208     ap[1] = lapack_make_complex_double( 2.00000000000000000e+000,
00209                                         -2.99999999999999990e-001 );
00210     ap[2] = lapack_make_complex_double( 2.89000000000000010e+000,
00211                                         -1.34000000000000010e+000 );
00212     ap[3] = lapack_make_complex_double( -1.88999999999999990e+000,
00213                                         1.14999999999999990e+000 );
00214     ap[4] = lapack_make_complex_double( -4.11000000000000030e+000,
00215                                         1.25000000000000000e+000 );
00216     ap[5] = lapack_make_complex_double( 2.35999999999999990e+000,
00217                                         -4.25000000000000000e+000 );
00218     ap[6] = lapack_make_complex_double( 4.00000000000000010e-002,
00219                                         -3.68999999999999990e+000 );
00220     ap[7] = lapack_make_complex_double( 4.15000000000000040e+000,
00221                                         8.00000000000000040e-001 );
00222     ap[8] = lapack_make_complex_double( -2.00000000000000000e-002,
00223                                         4.60000000000000020e-001 );
00224     ap[9] = lapack_make_complex_double( 3.30000000000000020e-001,
00225                                         -2.60000000000000010e-001 );
00226 }
00227 
00228 /* Auxiliary function: C interface to ztptri results check */
00229 /* Return value: 0 - test is passed, non-zero - test is failed */
00230 static int compare_ztptri( lapack_complex_double *ap,
00231                            lapack_complex_double *ap_i, lapack_int info,
00232                            lapack_int info_i, lapack_int n )
00233 {
00234     lapack_int i;
00235     int failed = 0;
00236     for( i = 0; i < (n*(n+1)/2); i++ ) {
00237         failed += compare_complex_doubles(ap[i],ap_i[i]);
00238     }
00239     failed += (info == info_i) ? 0 : 1;
00240     if( info != 0 || info_i != 0 ) {
00241         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00242     }
00243 
00244     return failed;
00245 }


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