LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
lapacke_dtgsen_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 dtgsen
30 * Author: Intel Corporation
31 * Generated November 2015
32 *****************************************************************************/
33 
34 #include "lapacke_utils.h"
35 
36 lapack_int LAPACKE_dtgsen_work( int matrix_layout, lapack_int ijob,
37  lapack_logical wantq, lapack_logical wantz,
38  const lapack_logical* select, lapack_int n,
39  double* a, lapack_int lda, double* b,
40  lapack_int ldb, double* alphar, double* alphai,
41  double* beta, double* q, lapack_int ldq,
42  double* z, lapack_int ldz, lapack_int* m,
43  double* pl, double* pr, double* dif,
44  double* work, lapack_int lwork,
45  lapack_int* iwork, lapack_int liwork )
46 {
47  lapack_int info = 0;
48  if( matrix_layout == LAPACK_COL_MAJOR ) {
49  /* Call LAPACK function and adjust info */
50  LAPACK_dtgsen( &ijob, &wantq, &wantz, select, &n, a, &lda, b, &ldb,
51  alphar, alphai, beta, q, &ldq, z, &ldz, m, pl, pr, dif,
52  work, &lwork, iwork, &liwork, &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 ldq_t = MAX(1,n);
60  lapack_int ldz_t = MAX(1,n);
61  double* a_t = NULL;
62  double* b_t = NULL;
63  double* q_t = NULL;
64  double* z_t = NULL;
65  /* Check leading dimension(s) */
66  if( lda < n ) {
67  info = -8;
68  LAPACKE_xerbla( "LAPACKE_dtgsen_work", info );
69  return info;
70  }
71  if( ldb < n ) {
72  info = -10;
73  LAPACKE_xerbla( "LAPACKE_dtgsen_work", info );
74  return info;
75  }
76  if( ldq < n ) {
77  info = -15;
78  LAPACKE_xerbla( "LAPACKE_dtgsen_work", info );
79  return info;
80  }
81  if( ldz < n ) {
82  info = -17;
83  LAPACKE_xerbla( "LAPACKE_dtgsen_work", info );
84  return info;
85  }
86  /* Query optimal working array(s) size if requested */
87  if( liwork == -1 || lwork == -1 ) {
88  LAPACK_dtgsen( &ijob, &wantq, &wantz, select, &n, a, &lda_t, b,
89  &ldb_t, alphar, alphai, beta, q, &ldq_t, z, &ldz_t,
90  m, pl, pr, dif, work, &lwork, iwork, &liwork,
91  &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( wantq ) {
106  q_t = (double*)LAPACKE_malloc( sizeof(double) * ldq_t * MAX(1,n) );
107  if( q_t == NULL ) {
109  goto exit_level_2;
110  }
111  }
112  if( wantz ) {
113  z_t = (double*)LAPACKE_malloc( sizeof(double) * ldz_t * MAX(1,n) );
114  if( z_t == NULL ) {
116  goto exit_level_3;
117  }
118  }
119  /* Transpose input matrices */
120  LAPACKE_dge_trans( matrix_layout, n, n, a, lda, a_t, lda_t );
121  LAPACKE_dge_trans( matrix_layout, n, n, b, ldb, b_t, ldb_t );
122  if( wantq ) {
123  LAPACKE_dge_trans( matrix_layout, n, n, q, ldq, q_t, ldq_t );
124  }
125  if( wantz ) {
126  LAPACKE_dge_trans( matrix_layout, n, n, z, ldz, z_t, ldz_t );
127  }
128  /* Call LAPACK function and adjust info */
129  LAPACK_dtgsen( &ijob, &wantq, &wantz, select, &n, a_t, &lda_t, b_t,
130  &ldb_t, alphar, alphai, beta, q_t, &ldq_t, z_t, &ldz_t,
131  m, pl, pr, dif, work, &lwork, iwork, &liwork, &info );
132  if( info < 0 ) {
133  info = info - 1;
134  }
135  /* Transpose output matrices */
136  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_t, lda_t, a, lda );
137  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, b_t, ldb_t, b, ldb );
138  if( wantq ) {
139  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, q_t, ldq_t, q, ldq );
140  }
141  if( wantz ) {
142  LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, z_t, ldz_t, z, ldz );
143  }
144  /* Release memory and exit */
145  if( wantz ) {
146  LAPACKE_free( z_t );
147  }
148 exit_level_3:
149  if( wantq ) {
150  LAPACKE_free( q_t );
151  }
152 exit_level_2:
153  LAPACKE_free( b_t );
154 exit_level_1:
155  LAPACKE_free( a_t );
156 exit_level_0:
157  if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
158  LAPACKE_xerbla( "LAPACKE_dtgsen_work", info );
159  }
160  } else {
161  info = -1;
162  LAPACKE_xerbla( "LAPACKE_dtgsen_work", info );
163  }
164  return info;
165 }
#define lapack_logical
Definition: lapacke.h:51
void LAPACKE_dge_trans(int matrix_layout, lapack_int m, lapack_int n, const double *in, lapack_int ldin, double *out, lapack_int ldout)
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:119
#define MAX(x, y)
Definition: lapacke_utils.h:47
#define LAPACKE_free(p)
Definition: lapacke.h:113
#define LAPACKE_malloc(size)
Definition: lapacke.h:110
lapack_int LAPACKE_dtgsen_work(int matrix_layout, lapack_int ijob, lapack_logical wantq, lapack_logical wantz, const lapack_logical *select, lapack_int n, double *a, lapack_int lda, double *b, lapack_int ldb, double *alphar, double *alphai, double *beta, double *q, lapack_int ldq, double *z, lapack_int ldz, lapack_int *m, double *pl, double *pr, double *dif, double *work, lapack_int lwork, lapack_int *iwork, lapack_int liwork)
#define LAPACK_COL_MAJOR
Definition: lapacke.h:120
void LAPACKE_xerbla(const char *name, lapack_int info)
#define lapack_int
Definition: lapacke.h:47
void LAPACK_dtgsen(lapack_int *ijob, lapack_logical *wantq, lapack_logical *wantz, const lapack_logical *select, lapack_int *n, double *a, lapack_int *lda, double *b, lapack_int *ldb, double *alphar, double *alphai, double *beta, double *q, lapack_int *ldq, double *z, lapack_int *ldz, lapack_int *m, double *pl, double *pr, double *dif, double *work, lapack_int *lwork, lapack_int *iwork, lapack_int *liwork, lapack_int *info)
#define LAPACK_TRANSPOSE_MEMORY_ERROR
Definition: lapacke.h:123