lapacke_dggev_work.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: Native middle-level C interface to LAPACK function dggev
00030 * Author: Intel Corporation
00031 * Generated October, 2010
00032 *****************************************************************************/
00033 
00034 #include "lapacke.h"
00035 #include "lapacke_utils.h"
00036 
00037 lapack_int LAPACKE_dggev_work( int matrix_order, char jobvl, char jobvr,
00038                                lapack_int n, double* a, lapack_int lda,
00039                                double* b, lapack_int ldb, double* alphar,
00040                                double* alphai, double* beta, double* vl,
00041                                lapack_int ldvl, double* vr, lapack_int ldvr,
00042                                double* work, lapack_int lwork )
00043 {
00044     lapack_int info = 0;
00045     if( matrix_order == LAPACK_COL_MAJOR ) {
00046         /* Call LAPACK function and adjust info */
00047         LAPACK_dggev( &jobvl, &jobvr, &n, a, &lda, b, &ldb, alphar, alphai,
00048                       beta, vl, &ldvl, vr, &ldvr, work, &lwork, &info );
00049         if( info < 0 ) {
00050             info = info - 1;
00051         }
00052     } else if( matrix_order == LAPACK_ROW_MAJOR ) {
00053         lapack_int nrows_vl = LAPACKE_lsame( jobvl, 'v' ) ? n : 1;
00054         lapack_int ncols_vl = LAPACKE_lsame( jobvl, 'v' ) ? n : 1;
00055         lapack_int nrows_vr = LAPACKE_lsame( jobvr, 'v' ) ? n : 1;
00056         lapack_int ncols_vr = LAPACKE_lsame( jobvr, 'v' ) ? n : 1;
00057         lapack_int lda_t = MAX(1,n);
00058         lapack_int ldb_t = MAX(1,n);
00059         lapack_int ldvl_t = MAX(1,nrows_vl);
00060         lapack_int ldvr_t = MAX(1,nrows_vr);
00061         double* a_t = NULL;
00062         double* b_t = NULL;
00063         double* vl_t = NULL;
00064         double* vr_t = NULL;
00065         /* Check leading dimension(s) */
00066         if( lda < n ) {
00067             info = -6;
00068             LAPACKE_xerbla( "LAPACKE_dggev_work", info );
00069             return info;
00070         }
00071         if( ldb < n ) {
00072             info = -8;
00073             LAPACKE_xerbla( "LAPACKE_dggev_work", info );
00074             return info;
00075         }
00076         if( ldvl < ncols_vl ) {
00077             info = -13;
00078             LAPACKE_xerbla( "LAPACKE_dggev_work", info );
00079             return info;
00080         }
00081         if( ldvr < ncols_vr ) {
00082             info = -15;
00083             LAPACKE_xerbla( "LAPACKE_dggev_work", info );
00084             return info;
00085         }
00086         /* Query optimal working array(s) size if requested */
00087         if( lwork == -1 ) {
00088             LAPACK_dggev( &jobvl, &jobvr, &n, a, &lda_t, b, &ldb_t, alphar,
00089                           alphai, beta, vl, &ldvl_t, vr, &ldvr_t, work, &lwork,
00090                           &info );
00091             return (info < 0) ? (info - 1) : info;
00092         }
00093         /* Allocate memory for temporary array(s) */
00094         a_t = (double*)LAPACKE_malloc( sizeof(double) * lda_t * MAX(1,n) );
00095         if( a_t == NULL ) {
00096             info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00097             goto exit_level_0;
00098         }
00099         b_t = (double*)LAPACKE_malloc( sizeof(double) * ldb_t * MAX(1,n) );
00100         if( b_t == NULL ) {
00101             info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00102             goto exit_level_1;
00103         }
00104         if( LAPACKE_lsame( jobvl, 'v' ) ) {
00105             vl_t = (double*)
00106                 LAPACKE_malloc( sizeof(double) * ldvl_t * MAX(1,ncols_vl) );
00107             if( vl_t == NULL ) {
00108                 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00109                 goto exit_level_2;
00110             }
00111         }
00112         if( LAPACKE_lsame( jobvr, 'v' ) ) {
00113             vr_t = (double*)
00114                 LAPACKE_malloc( sizeof(double) * ldvr_t * MAX(1,ncols_vr) );
00115             if( vr_t == NULL ) {
00116                 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00117                 goto exit_level_3;
00118             }
00119         }
00120         /* Transpose input matrices */
00121         LAPACKE_dge_trans( matrix_order, n, n, a, lda, a_t, lda_t );
00122         LAPACKE_dge_trans( matrix_order, n, n, b, ldb, b_t, ldb_t );
00123         /* Call LAPACK function and adjust info */
00124         LAPACK_dggev( &jobvl, &jobvr, &n, a_t, &lda_t, b_t, &ldb_t, alphar,
00125                       alphai, beta, vl_t, &ldvl_t, vr_t, &ldvr_t, work, &lwork,
00126                       &info );
00127         if( info < 0 ) {
00128             info = info - 1;
00129         }
00130         /* Transpose output matrices */
00131         LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_t, lda_t, a, lda );
00132         LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, b_t, ldb_t, b, ldb );
00133         if( LAPACKE_lsame( jobvl, 'v' ) ) {
00134             LAPACKE_dge_trans( LAPACK_COL_MAJOR, nrows_vl, ncols_vl, vl_t,
00135                                ldvl_t, vl, ldvl );
00136         }
00137         if( LAPACKE_lsame( jobvr, 'v' ) ) {
00138             LAPACKE_dge_trans( LAPACK_COL_MAJOR, nrows_vr, ncols_vr, vr_t,
00139                                ldvr_t, vr, ldvr );
00140         }
00141         /* Release memory and exit */
00142         if( LAPACKE_lsame( jobvr, 'v' ) ) {
00143             LAPACKE_free( vr_t );
00144         }
00145 exit_level_3:
00146         if( LAPACKE_lsame( jobvl, 'v' ) ) {
00147             LAPACKE_free( vl_t );
00148         }
00149 exit_level_2:
00150         LAPACKE_free( b_t );
00151 exit_level_1:
00152         LAPACKE_free( a_t );
00153 exit_level_0:
00154         if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
00155             LAPACKE_xerbla( "LAPACKE_dggev_work", info );
00156         }
00157     } else {
00158         info = -1;
00159         LAPACKE_xerbla( "LAPACKE_dggev_work", info );
00160     }
00161     return info;
00162 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:52