sopgtr_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 * sopgtr_1 is the test program for the C interface to LAPACK
00036 * routine sopgtr
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_sopgtr( char *uplo, lapack_int *n, lapack_int *ldq );
00055 static void init_ap( lapack_int size, float *ap );
00056 static void init_tau( lapack_int size, float *tau );
00057 static void init_q( lapack_int size, float *q );
00058 static void init_work( lapack_int size, float *work );
00059 static int compare_sopgtr( float *q, float *q_i, lapack_int info,
00060                            lapack_int info_i, lapack_int ldq, lapack_int n );
00061 
00062 int main(void)
00063 {
00064     /* Local scalars */
00065     char uplo, uplo_i;
00066     lapack_int n, n_i;
00067     lapack_int ldq, ldq_i;
00068     lapack_int ldq_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 *tau = NULL, *tau_i = NULL;
00076     float *q = NULL, *q_i = NULL;
00077     float *work = NULL, *work_i = NULL;
00078     float *q_save = NULL;
00079     float *ap_r = NULL;
00080     float *q_r = NULL;
00081 
00082     /* Iniitialize the scalar parameters */
00083     init_scalars_sopgtr( &uplo, &n, &ldq );
00084     ldq_r = n+2;
00085     uplo_i = uplo;
00086     n_i = n;
00087     ldq_i = ldq;
00088 
00089     /* Allocate memory for the LAPACK routine arrays */
00090     ap = (float *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(float) );
00091     tau = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00092     q = (float *)LAPACKE_malloc( ldq*n * sizeof(float) );
00093     work = (float *)LAPACKE_malloc( (n-1) * 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     tau_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00098     q_i = (float *)LAPACKE_malloc( ldq*n * sizeof(float) );
00099     work_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00100 
00101     /* Allocate memory for the backup arrays */
00102     q_save = (float *)LAPACKE_malloc( ldq*n * sizeof(float) );
00103 
00104     /* Allocate memory for the row-major arrays */
00105     ap_r = (float *)LAPACKE_malloc( n*(n+1)/2 * sizeof(float) );
00106     q_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00107 
00108     /* Initialize input arrays */
00109     init_ap( (n*(n+1)/2), ap );
00110     init_tau( (n-1), tau );
00111     init_q( ldq*n, q );
00112     init_work( (n-1), work );
00113 
00114     /* Backup the ouptut arrays */
00115     for( i = 0; i < ldq*n; i++ ) {
00116         q_save[i] = q[i];
00117     }
00118 
00119     /* Call the LAPACK routine */
00120     sopgtr_( &uplo, &n, ap, tau, q, &ldq, work, &info );
00121 
00122     /* Initialize input data, call the column-major middle-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[i];
00126     }
00127     for( i = 0; i < (n-1); i++ ) {
00128         tau_i[i] = tau[i];
00129     }
00130     for( i = 0; i < ldq*n; i++ ) {
00131         q_i[i] = q_save[i];
00132     }
00133     for( i = 0; i < (n-1); i++ ) {
00134         work_i[i] = work[i];
00135     }
00136     info_i = LAPACKE_sopgtr_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, tau_i,
00137                                   q_i, ldq_i, work_i );
00138 
00139     failed = compare_sopgtr( q, q_i, info, info_i, ldq, n );
00140     if( failed == 0 ) {
00141         printf( "PASSED: column-major middle-level interface to sopgtr\n" );
00142     } else {
00143         printf( "FAILED: column-major middle-level interface to sopgtr\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 < (n-1); i++ ) {
00152         tau_i[i] = tau[i];
00153     }
00154     for( i = 0; i < ldq*n; i++ ) {
00155         q_i[i] = q_save[i];
00156     }
00157     for( i = 0; i < (n-1); i++ ) {
00158         work_i[i] = work[i];
00159     }
00160     info_i = LAPACKE_sopgtr( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, tau_i, q_i,
00161                              ldq_i );
00162 
00163     failed = compare_sopgtr( q, q_i, info, info_i, ldq, n );
00164     if( failed == 0 ) {
00165         printf( "PASSED: column-major high-level interface to sopgtr\n" );
00166     } else {
00167         printf( "FAILED: column-major high-level interface to sopgtr\n" );
00168     }
00169 
00170     /* Initialize input data, call the row-major middle-level
00171      * interface to LAPACK routine and check the results */
00172     for( i = 0; i < (n*(n+1)/2); i++ ) {
00173         ap_i[i] = ap[i];
00174     }
00175     for( i = 0; i < (n-1); i++ ) {
00176         tau_i[i] = tau[i];
00177     }
00178     for( i = 0; i < ldq*n; i++ ) {
00179         q_i[i] = q_save[i];
00180     }
00181     for( i = 0; i < (n-1); i++ ) {
00182         work_i[i] = work[i];
00183     }
00184 
00185     LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00186     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00187     info_i = LAPACKE_sopgtr_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, tau_i,
00188                                   q_r, ldq_r, work_i );
00189 
00190     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00191 
00192     failed = compare_sopgtr( q, q_i, info, info_i, ldq, n );
00193     if( failed == 0 ) {
00194         printf( "PASSED: row-major middle-level interface to sopgtr\n" );
00195     } else {
00196         printf( "FAILED: row-major middle-level interface to sopgtr\n" );
00197     }
00198 
00199     /* Initialize input data, call the row-major high-level
00200      * interface to LAPACK routine and check the results */
00201     for( i = 0; i < (n*(n+1)/2); i++ ) {
00202         ap_i[i] = ap[i];
00203     }
00204     for( i = 0; i < (n-1); i++ ) {
00205         tau_i[i] = tau[i];
00206     }
00207     for( i = 0; i < ldq*n; i++ ) {
00208         q_i[i] = q_save[i];
00209     }
00210     for( i = 0; i < (n-1); i++ ) {
00211         work_i[i] = work[i];
00212     }
00213 
00214     /* Init row_major arrays */
00215     LAPACKE_spp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00216     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
00217     info_i = LAPACKE_sopgtr( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, tau_i, q_r,
00218                              ldq_r );
00219 
00220     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
00221 
00222     failed = compare_sopgtr( q, q_i, info, info_i, ldq, n );
00223     if( failed == 0 ) {
00224         printf( "PASSED: row-major high-level interface to sopgtr\n" );
00225     } else {
00226         printf( "FAILED: row-major high-level interface to sopgtr\n" );
00227     }
00228 
00229     /* Release memory */
00230     if( ap != NULL ) {
00231         LAPACKE_free( ap );
00232     }
00233     if( ap_i != NULL ) {
00234         LAPACKE_free( ap_i );
00235     }
00236     if( ap_r != NULL ) {
00237         LAPACKE_free( ap_r );
00238     }
00239     if( tau != NULL ) {
00240         LAPACKE_free( tau );
00241     }
00242     if( tau_i != NULL ) {
00243         LAPACKE_free( tau_i );
00244     }
00245     if( q != NULL ) {
00246         LAPACKE_free( q );
00247     }
00248     if( q_i != NULL ) {
00249         LAPACKE_free( q_i );
00250     }
00251     if( q_r != NULL ) {
00252         LAPACKE_free( q_r );
00253     }
00254     if( q_save != NULL ) {
00255         LAPACKE_free( q_save );
00256     }
00257     if( work != NULL ) {
00258         LAPACKE_free( work );
00259     }
00260     if( work_i != NULL ) {
00261         LAPACKE_free( work_i );
00262     }
00263 
00264     return 0;
00265 }
00266 
00267 /* Auxiliary function: sopgtr scalar parameters initialization */
00268 static void init_scalars_sopgtr( char *uplo, lapack_int *n, lapack_int *ldq )
00269 {
00270     *uplo = 'L';
00271     *n = 4;
00272     *ldq = 8;
00273 
00274     return;
00275 }
00276 
00277 /* Auxiliary functions: sopgtr array parameters initialization */
00278 static void init_ap( lapack_int size, float *ap ) {
00279     lapack_int i;
00280     for( i = 0; i < size; i++ ) {
00281         ap[i] = 0;
00282     }
00283     ap[0] = 2.069999933e+000;
00284     ap[1] = -5.825753212e+000;
00285     ap[2] = 4.331793189e-001;
00286     ap[3] = -1.186086312e-001;
00287     ap[4] = 1.474093199e+000;
00288     ap[5] = 2.624044895e+000;
00289     ap[6] = 8.062880635e-001;
00290     ap[7] = -6.491593122e-001;
00291     ap[8] = 9.162727594e-001;
00292     ap[9] = -1.694934368e+000;
00293 }
00294 static void init_tau( lapack_int size, float *tau ) {
00295     lapack_int i;
00296     for( i = 0; i < size; i++ ) {
00297         tau[i] = 0;
00298     }
00299     tau[0] = 1.664291739e+000;
00300     tau[1] = 1.212047458e+000;
00301     tau[2] = 0.000000000e+000;
00302 }
00303 static void init_q( lapack_int size, float *q ) {
00304     lapack_int i;
00305     for( i = 0; i < size; i++ ) {
00306         q[i] = 0;
00307     }
00308 }
00309 static void init_work( lapack_int size, float *work ) {
00310     lapack_int i;
00311     for( i = 0; i < size; i++ ) {
00312         work[i] = 0;
00313     }
00314 }
00315 
00316 /* Auxiliary function: C interface to sopgtr results check */
00317 /* Return value: 0 - test is passed, non-zero - test is failed */
00318 static int compare_sopgtr( float *q, float *q_i, lapack_int info,
00319                            lapack_int info_i, lapack_int ldq, lapack_int n )
00320 {
00321     lapack_int i;
00322     int failed = 0;
00323     for( i = 0; i < ldq*n; i++ ) {
00324         failed += compare_floats(q[i],q_i[i]);
00325     }
00326     failed += (info == info_i) ? 0 : 1;
00327     if( info != 0 || info_i != 0 ) {
00328         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00329     }
00330 
00331     return failed;
00332 }


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