zupgtr_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 * zupgtr_1 is the test program for the C interface to LAPACK
00036 * routine zupgtr
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_zupgtr( char *uplo, lapack_int *n, lapack_int *ldq );
00055 static void init_ap( lapack_int size, lapack_complex_double *ap );
00056 static void init_tau( lapack_int size, lapack_complex_double *tau );
00057 static void init_q( lapack_int size, lapack_complex_double *q );
00058 static void init_work( lapack_int size, lapack_complex_double *work );
00059 static int compare_zupgtr( lapack_complex_double *q, lapack_complex_double *q_i,
00060                            lapack_int info, lapack_int info_i, lapack_int ldq,
00061                            lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char uplo, uplo_i;
00067     lapack_int n, n_i;
00068     lapack_int ldq, ldq_i;
00069     lapack_int ldq_r;
00070     lapack_int info, info_i;
00071     lapack_int i;
00072     int failed;
00073 
00074     /* Local arrays */
00075     lapack_complex_double *ap = NULL, *ap_i = NULL;
00076     lapack_complex_double *tau = NULL, *tau_i = NULL;
00077     lapack_complex_double *q = NULL, *q_i = NULL;
00078     lapack_complex_double *work = NULL, *work_i = NULL;
00079     lapack_complex_double *q_save = NULL;
00080     lapack_complex_double *ap_r = NULL;
00081     lapack_complex_double *q_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_zupgtr( &uplo, &n, &ldq );
00085     ldq_r = n+2;
00086     uplo_i = uplo;
00087     n_i = n;
00088     ldq_i = ldq;
00089 
00090     /* Allocate memory for the LAPACK routine arrays */
00091     ap = (lapack_complex_double *)
00092         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00093     tau = (lapack_complex_double *)
00094         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00095     q = (lapack_complex_double *)
00096         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );
00097     work = (lapack_complex_double *)
00098         LAPACKE_malloc( (n-1) * 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     tau_i = (lapack_complex_double *)
00104         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00105     q_i = (lapack_complex_double *)
00106         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );
00107     work_i = (lapack_complex_double *)
00108         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00109 
00110     /* Allocate memory for the backup arrays */
00111     q_save = (lapack_complex_double *)
00112         LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );
00113 
00114     /* Allocate memory for the row-major arrays */
00115     ap_r = (lapack_complex_double *)
00116         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00117     q_r = (lapack_complex_double *)
00118         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00119 
00120     /* Initialize input arrays */
00121     init_ap( (n*(n+1)/2), ap );
00122     init_tau( (n-1), tau );
00123     init_q( ldq*n, q );
00124     init_work( (n-1), work );
00125 
00126     /* Backup the ouptut arrays */
00127     for( i = 0; i < ldq*n; i++ ) {
00128         q_save[i] = q[i];
00129     }
00130 
00131     /* Call the LAPACK routine */
00132     zupgtr_( &uplo, &n, ap, tau, q, &ldq, work, &info );
00133 
00134     /* Initialize input data, call the column-major middle-level
00135      * interface to LAPACK routine and check the results */
00136     for( i = 0; i < (n*(n+1)/2); i++ ) {
00137         ap_i[i] = ap[i];
00138     }
00139     for( i = 0; i < (n-1); i++ ) {
00140         tau_i[i] = tau[i];
00141     }
00142     for( i = 0; i < ldq*n; i++ ) {
00143         q_i[i] = q_save[i];
00144     }
00145     for( i = 0; i < (n-1); i++ ) {
00146         work_i[i] = work[i];
00147     }
00148     info_i = LAPACKE_zupgtr_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, tau_i,
00149                                   q_i, ldq_i, work_i );
00150 
00151     failed = compare_zupgtr( q, q_i, info, info_i, ldq, n );
00152     if( failed == 0 ) {
00153         printf( "PASSED: column-major middle-level interface to zupgtr\n" );
00154     } else {
00155         printf( "FAILED: column-major middle-level interface to zupgtr\n" );
00156     }
00157 
00158     /* Initialize input data, call the column-major high-level
00159      * interface to LAPACK routine and check the results */
00160     for( i = 0; i < (n*(n+1)/2); i++ ) {
00161         ap_i[i] = ap[i];
00162     }
00163     for( i = 0; i < (n-1); i++ ) {
00164         tau_i[i] = tau[i];
00165     }
00166     for( i = 0; i < ldq*n; i++ ) {
00167         q_i[i] = q_save[i];
00168     }
00169     for( i = 0; i < (n-1); i++ ) {
00170         work_i[i] = work[i];
00171     }
00172     info_i = LAPACKE_zupgtr( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, tau_i, q_i,
00173                              ldq_i );
00174 
00175     failed = compare_zupgtr( q, q_i, info, info_i, ldq, n );
00176     if( failed == 0 ) {
00177         printf( "PASSED: column-major high-level interface to zupgtr\n" );
00178     } else {
00179         printf( "FAILED: column-major high-level interface to zupgtr\n" );
00180     }
00181 
00182     /* Initialize input data, call the row-major middle-level
00183      * interface to LAPACK routine and check the results */
00184     for( i = 0; i < (n*(n+1)/2); i++ ) {
00185         ap_i[i] = ap[i];
00186     }
00187     for( i = 0; i < (n-1); i++ ) {
00188         tau_i[i] = tau[i];
00189     }
00190     for( i = 0; i < ldq*n; i++ ) {
00191         q_i[i] = q_save[i];
00192     }
00193     for( i = 0; i < (n-1); i++ ) {
00194         work_i[i] = work[i];
00195     }
00196 
00197     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00199     info_i = LAPACKE_zupgtr_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, tau_i,
00200                                   q_r, ldq_r, work_i );
00201 
00202     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00203 
00204     failed = compare_zupgtr( q, q_i, info, info_i, ldq, n );
00205     if( failed == 0 ) {
00206         printf( "PASSED: row-major middle-level interface to zupgtr\n" );
00207     } else {
00208         printf( "FAILED: row-major middle-level interface to zupgtr\n" );
00209     }
00210 
00211     /* Initialize input data, call the row-major high-level
00212      * interface to LAPACK routine and check the results */
00213     for( i = 0; i < (n*(n+1)/2); i++ ) {
00214         ap_i[i] = ap[i];
00215     }
00216     for( i = 0; i < (n-1); i++ ) {
00217         tau_i[i] = tau[i];
00218     }
00219     for( i = 0; i < ldq*n; i++ ) {
00220         q_i[i] = q_save[i];
00221     }
00222     for( i = 0; i < (n-1); i++ ) {
00223         work_i[i] = work[i];
00224     }
00225 
00226     /* Init row_major arrays */
00227     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00228     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00229     info_i = LAPACKE_zupgtr( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, tau_i, q_r,
00230                              ldq_r );
00231 
00232     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00233 
00234     failed = compare_zupgtr( q, q_i, info, info_i, ldq, n );
00235     if( failed == 0 ) {
00236         printf( "PASSED: row-major high-level interface to zupgtr\n" );
00237     } else {
00238         printf( "FAILED: row-major high-level interface to zupgtr\n" );
00239     }
00240 
00241     /* Release memory */
00242     if( ap != NULL ) {
00243         LAPACKE_free( ap );
00244     }
00245     if( ap_i != NULL ) {
00246         LAPACKE_free( ap_i );
00247     }
00248     if( ap_r != NULL ) {
00249         LAPACKE_free( ap_r );
00250     }
00251     if( tau != NULL ) {
00252         LAPACKE_free( tau );
00253     }
00254     if( tau_i != NULL ) {
00255         LAPACKE_free( tau_i );
00256     }
00257     if( q != NULL ) {
00258         LAPACKE_free( q );
00259     }
00260     if( q_i != NULL ) {
00261         LAPACKE_free( q_i );
00262     }
00263     if( q_r != NULL ) {
00264         LAPACKE_free( q_r );
00265     }
00266     if( q_save != NULL ) {
00267         LAPACKE_free( q_save );
00268     }
00269     if( work != NULL ) {
00270         LAPACKE_free( work );
00271     }
00272     if( work_i != NULL ) {
00273         LAPACKE_free( work_i );
00274     }
00275 
00276     return 0;
00277 }
00278 
00279 /* Auxiliary function: zupgtr scalar parameters initialization */
00280 static void init_scalars_zupgtr( char *uplo, lapack_int *n, lapack_int *ldq )
00281 {
00282     *uplo = 'L';
00283     *n = 4;
00284     *ldq = 8;
00285 
00286     return;
00287 }
00288 
00289 /* Auxiliary functions: zupgtr array parameters initialization */
00290 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00291     lapack_int i;
00292     for( i = 0; i < size; i++ ) {
00293         ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00294     }
00295     ap[0] = lapack_make_complex_double( -2.27999999999999980e+000,
00296                                         0.00000000000000000e+000 );
00297     ap[1] = lapack_make_complex_double( -4.33845594653212970e+000,
00298                                         0.00000000000000000e+000 );
00299     ap[2] = lapack_make_complex_double( 3.27860676092192380e-001,
00300                                         -1.25122609226443690e-001 );
00301     ap[3] = lapack_make_complex_double( -1.41256563750694670e-001,
00302                                         -3.66636483973957040e-001 );
00303     ap[4] = lapack_make_complex_double( -1.28456981649329280e-001,
00304                                         0.00000000000000000e+000 );
00305     ap[5] = lapack_make_complex_double( -2.02259457862261720e+000,
00306                                         0.00000000000000000e+000 );
00307     ap[6] = lapack_make_complex_double( -3.08321908008089010e-001,
00308                                         1.76322636472677850e-001 );
00309     ap[7] = lapack_make_complex_double( -1.66593253752407190e-001,
00310                                         0.00000000000000000e+000 );
00311     ap[8] = lapack_make_complex_double( -1.80232297833873440e+000,
00312                                         0.00000000000000000e+000 );
00313     ap[9] = lapack_make_complex_double( -1.92494976459826360e+000,
00314                                         0.00000000000000000e+000 );
00315 }
00316 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00317     lapack_int i;
00318     for( i = 0; i < size; i++ ) {
00319         tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00320     }
00321     tau[0] = lapack_make_complex_double( 1.41028421676675380e+000,
00322                                          4.67908404514893240e-001 );
00323     tau[1] = lapack_make_complex_double( 1.30242036943477490e+000,
00324                                          7.85332074252958030e-001 );
00325     tau[2] = lapack_make_complex_double( 1.09397371592308160e+000,
00326                                          -9.95574678623159850e-001 );
00327 }
00328 static void init_q( lapack_int size, lapack_complex_double *q ) {
00329     lapack_int i;
00330     for( i = 0; i < size; i++ ) {
00331         q[i] = lapack_make_complex_double( 0.0, 0.0 );
00332     }
00333 }
00334 static void init_work( lapack_int size, lapack_complex_double *work ) {
00335     lapack_int i;
00336     for( i = 0; i < size; i++ ) {
00337         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00338     }
00339 }
00340 
00341 /* Auxiliary function: C interface to zupgtr results check */
00342 /* Return value: 0 - test is passed, non-zero - test is failed */
00343 static int compare_zupgtr( lapack_complex_double *q, lapack_complex_double *q_i,
00344                            lapack_int info, lapack_int info_i, lapack_int ldq,
00345                            lapack_int n )
00346 {
00347     lapack_int i;
00348     int failed = 0;
00349     for( i = 0; i < ldq*n; i++ ) {
00350         failed += compare_complex_doubles(q[i],q_i[i]);
00351     }
00352     failed += (info == info_i) ? 0 : 1;
00353     if( info != 0 || info_i != 0 ) {
00354         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00355     }
00356 
00357     return failed;
00358 }


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