LAPACK  3.10.1
LAPACK: Linear Algebra PACKage
lapacke_dggesx_work.c
Go to the documentation of this file.
1 /*****************************************************************************
2  Copyright (c) 2014, Intel Corp.
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of Intel Corporation nor the names of its contributors
14  may be used to endorse or promote products derived from this software
15  without specific prior written permission.
16 
17  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  THE POSSIBILITY OF SUCH DAMAGE.
28 *****************************************************************************
29 * Contents: Native middle-level C interface to LAPACK function dggesx
30 * Author: Intel Corporation
31 *****************************************************************************/
32 
33 #include "lapacke_utils.h"
34 
35 lapack_int LAPACKE_dggesx_work( int matrix_layout, char jobvsl, char jobvsr,
36  char sort, LAPACK_D_SELECT3 selctg, char sense,
37  lapack_int n, double* a, lapack_int lda,
38  double* b, lapack_int ldb, lapack_int* sdim,
39  double* alphar, double* alphai, double* beta,
40  double* vsl, lapack_int ldvsl, double* vsr,
41  lapack_int ldvsr, double* rconde,
42  double* rcondv, double* work, lapack_int lwork,
43  lapack_int* iwork, lapack_int liwork,
44  lapack_logical* bwork )
45 {
46  lapack_int info = 0;
47  if( matrix_layout == LAPACK_COL_MAJOR ) {
48  /* Call LAPACK function and adjust info */
49  LAPACK_dggesx( &jobvsl, &jobvsr, &sort, selctg, &sense, &n, a, &lda, b,
50  &ldb, sdim, alphar, alphai, beta, vsl, &ldvsl, vsr,
51  &ldvsr, rconde, rcondv, work, &lwork, iwork, &liwork,
52  bwork, &info );
53  if( info < 0 ) {
54  info = info - 1;
55  }
56  } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
57  lapack_int lda_t = MAX(1,n);
58  lapack_int ldb_t = MAX(1,n);
59  lapack_int ldvsl_t = MAX(1,n);
60  lapack_int ldvsr_t = MAX(1,n);
61  double* a_t = NULL;
62  double* b_t = NULL;
63  double* vsl_t = NULL;
64  double* vsr_t = NULL;
65  /* Check leading dimension(s) */
66  if( lda < n ) {
67  info = -9;
68  LAPACKE_xerbla( "LAPACKE_dggesx_work", info );
69  return info;
70  }
71  if( ldb < n ) {
72  info = -11;
73  LAPACKE_xerbla( "LAPACKE_dggesx_work", info );
74  return info;
75  }
76  if( ldvsl < n ) {
77  info = -17;
78  LAPACKE_xerbla( "LAPACKE_dggesx_work", info );
79  return info;
80  }
81  if( ldvsr < n ) {
82  info = -19;
83  LAPACKE_xerbla( "LAPACKE_dggesx_work", info );
84  return info;
85  }
86  /* Query optimal working array(s) size if requested */
87  if( liwork == -1 || lwork == -1 ) {
88  LAPACK_dggesx( &jobvsl, &jobvsr, &sort, selctg, &sense, &n, a,
89  &lda_t, b, &ldb_t, sdim, alphar, alphai, beta, vsl,
90  &ldvsl_t, vsr, &ldvsr_t, rconde, rcondv, work,
91  &lwork, iwork, &liwork, bwork, &info );
92  return (info < 0) ? (info - 1) : info;
93  }
94  /* Allocate memory for temporary array(s) */
95  a_t = (double*)LAPACKE_malloc( sizeof(double) * lda_t * MAX(1,n) );
96  if( a_t == NULL ) {
98  goto exit_level_0;
99  }
100  b_t = (double*)LAPACKE_malloc( sizeof(double) * ldb_t * MAX(1,n) );
101  if( b_t == NULL ) {
103  goto exit_level_1;
104  }
105  if( LAPACKE_lsame( jobvsl, 'v' ) ) {
106  vsl_t = (double*)
107  LAPACKE_malloc( sizeof(double) * ldvsl_t * MAX(1,n) );
108  if( vsl_t == NULL ) {
110  goto exit_level_2;
111  }
112  }
113  if( LAPACKE_lsame( jobvsr, 'v' ) ) {
114  vsr_t = (double*)
115  LAPACKE_malloc( sizeof(double) * ldvsr_t * MAX(1,n) );
116  if( vsr_t == NULL ) {
118  goto exit_level_3;
119  }
120  }
121  /* Transpose input matrices */
122  LAPACKE_dge_trans( matrix_layout, n, n, a, lda, a_t, lda_t );
123  LAPACKE_dge_trans( matrix_layout, n, n, b, ldb, b_t, ldb_t );
124  /* Call LAPACK function and adjust info */
125  LAPACK_dggesx( &jobvsl, &jobvsr, &sort, selctg, &sense, &n, a_t, &lda_t,
126  b_t, &ldb_t, sdim, alphar, alphai, beta, vsl_t, &ldvsl_t,
127  vsr_t, &ldvsr_t, rconde, rcondv, work, &lwork, iwork,
128  &liwork, bwork, &info );
129  if( info < 0 ) {
130  info = info - 1;
131  }
132  /* Transpose output matrices */
133  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_t, lda_t, a, lda );
134  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, b_t, ldb_t, b, ldb );
135  if( LAPACKE_lsame( jobvsl, 'v' ) ) {
136  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, vsl_t, ldvsl_t, vsl,
137  ldvsl );
138  }
139  if( LAPACKE_lsame( jobvsr, 'v' ) ) {
140  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, vsr_t, ldvsr_t, vsr,
141  ldvsr );
142  }
143  /* Release memory and exit */
144  if( LAPACKE_lsame( jobvsr, 'v' ) ) {
145  LAPACKE_free( vsr_t );
146  }
147 exit_level_3:
148  if( LAPACKE_lsame( jobvsl, 'v' ) ) {
149  LAPACKE_free( vsl_t );
150  }
151 exit_level_2:
152  LAPACKE_free( b_t );
153 exit_level_1:
154  LAPACKE_free( a_t );
155 exit_level_0:
156  if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
157  LAPACKE_xerbla( "LAPACKE_dggesx_work", info );
158  }
159  } else {
160  info = -1;
161  LAPACKE_xerbla( "LAPACKE_dggesx_work", info );
162  }
163  return info;
164 }
lapack_logical(* LAPACK_D_SELECT3)(const double *, const double *, const double *)
Definition: lapack.h:108
#define lapack_int
Definition: lapack.h:83
#define lapack_logical
Definition: lapack.h:87
#define LAPACK_dggesx(...)
Definition: lapack.h:4585
#define LAPACK_COL_MAJOR
Definition: lapacke.h:53
#define LAPACKE_free(p)
Definition: lapacke.h:46
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:52
#define LAPACKE_malloc(size)
Definition: lapacke.h:43
#define LAPACK_TRANSPOSE_MEMORY_ERROR
Definition: lapacke.h:56
lapack_int LAPACKE_dggesx_work(int matrix_layout, char jobvsl, char jobvsr, char sort, LAPACK_D_SELECT3 selctg, char sense, lapack_int n, double *a, lapack_int lda, double *b, lapack_int ldb, lapack_int *sdim, double *alphar, double *alphai, double *beta, double *vsl, lapack_int ldvsl, double *vsr, lapack_int ldvsr, double *rconde, double *rcondv, double *work, lapack_int lwork, lapack_int *iwork, lapack_int liwork, lapack_logical *bwork)
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:35
void LAPACKE_xerbla(const char *name, lapack_int info)
#define MAX(x, y)
Definition: lapacke_utils.h:46
void LAPACKE_dge_trans(int matrix_layout, lapack_int m, lapack_int n, const double *in, lapack_int ldin, double *out, lapack_int ldout)