LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
lapacke_shgeqz_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 shgeqz
30 * Author: Intel Corporation
31 * Generated November 2015
32 *****************************************************************************/
33 
34 #include "lapacke_utils.h"
35 
36 lapack_int LAPACKE_shgeqz_work( int matrix_layout, char job, char compq,
37  char compz, lapack_int n, lapack_int ilo,
38  lapack_int ihi, float* h, lapack_int ldh,
39  float* t, lapack_int ldt, float* alphar,
40  float* alphai, float* beta, float* q,
41  lapack_int ldq, float* z, lapack_int ldz,
42  float* work, lapack_int lwork )
43 {
44  lapack_int info = 0;
45  if( matrix_layout == LAPACK_COL_MAJOR ) {
46  /* Call LAPACK function and adjust info */
47  LAPACK_shgeqz( &job, &compq, &compz, &n, &ilo, &ihi, h, &ldh, t, &ldt,
48  alphar, alphai, beta, q, &ldq, z, &ldz, work, &lwork,
49  &info );
50  if( info < 0 ) {
51  info = info - 1;
52  }
53  } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
54  lapack_int ldh_t = MAX(1,n);
55  lapack_int ldq_t = MAX(1,n);
56  lapack_int ldt_t = MAX(1,n);
57  lapack_int ldz_t = MAX(1,n);
58  float* h_t = NULL;
59  float* t_t = NULL;
60  float* q_t = NULL;
61  float* z_t = NULL;
62  /* Check leading dimension(s) */
63  if( ldh < n ) {
64  info = -9;
65  LAPACKE_xerbla( "LAPACKE_shgeqz_work", info );
66  return info;
67  }
68  if( ldq < n ) {
69  info = -16;
70  LAPACKE_xerbla( "LAPACKE_shgeqz_work", info );
71  return info;
72  }
73  if( ldt < n ) {
74  info = -11;
75  LAPACKE_xerbla( "LAPACKE_shgeqz_work", info );
76  return info;
77  }
78  if( ldz < n ) {
79  info = -18;
80  LAPACKE_xerbla( "LAPACKE_shgeqz_work", info );
81  return info;
82  }
83  /* Query optimal working array(s) size if requested */
84  if( lwork == -1 ) {
85  LAPACK_shgeqz( &job, &compq, &compz, &n, &ilo, &ihi, h, &ldh_t, t,
86  &ldt_t, alphar, alphai, beta, q, &ldq_t, z, &ldz_t,
87  work, &lwork, &info );
88  return (info < 0) ? (info - 1) : info;
89  }
90  /* Allocate memory for temporary array(s) */
91  h_t = (float*)LAPACKE_malloc( sizeof(float) * ldh_t * MAX(1,n) );
92  if( h_t == NULL ) {
94  goto exit_level_0;
95  }
96  t_t = (float*)LAPACKE_malloc( sizeof(float) * ldt_t * MAX(1,n) );
97  if( t_t == NULL ) {
99  goto exit_level_1;
100  }
101  if( LAPACKE_lsame( compq, 'i' ) || LAPACKE_lsame( compq, 'v' ) ) {
102  q_t = (float*)LAPACKE_malloc( sizeof(float) * ldq_t * MAX(1,n) );
103  if( q_t == NULL ) {
105  goto exit_level_2;
106  }
107  }
108  if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
109  z_t = (float*)LAPACKE_malloc( sizeof(float) * ldz_t * MAX(1,n) );
110  if( z_t == NULL ) {
112  goto exit_level_3;
113  }
114  }
115  /* Transpose input matrices */
116  LAPACKE_sge_trans( matrix_layout, n, n, h, ldh, h_t, ldh_t );
117  LAPACKE_sge_trans( matrix_layout, n, n, t, ldt, t_t, ldt_t );
118  if( LAPACKE_lsame( compq, 'v' ) ) {
119  LAPACKE_sge_trans( matrix_layout, n, n, q, ldq, q_t, ldq_t );
120  }
121  if( LAPACKE_lsame( compz, 'v' ) ) {
122  LAPACKE_sge_trans( matrix_layout, n, n, z, ldz, z_t, ldz_t );
123  }
124  /* Call LAPACK function and adjust info */
125  LAPACK_shgeqz( &job, &compq, &compz, &n, &ilo, &ihi, h_t, &ldh_t, t_t,
126  &ldt_t, alphar, alphai, beta, q_t, &ldq_t, z_t, &ldz_t,
127  work, &lwork, &info );
128  if( info < 0 ) {
129  info = info - 1;
130  }
131  /* Transpose output matrices */
132  LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, h_t, ldh_t, h, ldh );
133  LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, t_t, ldt_t, t, ldt );
134  if( LAPACKE_lsame( compq, 'i' ) || LAPACKE_lsame( compq, 'v' ) ) {
135  LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, q_t, ldq_t, q, ldq );
136  }
137  if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
138  LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, z_t, ldz_t, z, ldz );
139  }
140  /* Release memory and exit */
141  if( LAPACKE_lsame( compz, 'i' ) || LAPACKE_lsame( compz, 'v' ) ) {
142  LAPACKE_free( z_t );
143  }
144 exit_level_3:
145  if( LAPACKE_lsame( compq, 'i' ) || LAPACKE_lsame( compq, 'v' ) ) {
146  LAPACKE_free( q_t );
147  }
148 exit_level_2:
149  LAPACKE_free( t_t );
150 exit_level_1:
151  LAPACKE_free( h_t );
152 exit_level_0:
153  if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
154  LAPACKE_xerbla( "LAPACKE_shgeqz_work", info );
155  }
156  } else {
157  info = -1;
158  LAPACKE_xerbla( "LAPACKE_shgeqz_work", info );
159  }
160  return info;
161 }
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:119
void LAPACK_shgeqz(char *job, char *compq, char *compz, lapack_int *n, lapack_int *ilo, lapack_int *ihi, float *h, lapack_int *ldh, float *t, lapack_int *ldt, float *alphar, float *alphai, float *beta, float *q, lapack_int *ldq, float *z, lapack_int *ldz, float *work, lapack_int *lwork, lapack_int *info)
void LAPACKE_sge_trans(int matrix_layout, lapack_int m, lapack_int n, const float *in, lapack_int ldin, float *out, lapack_int ldout)
#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_shgeqz_work(int matrix_layout, char job, char compq, char compz, lapack_int n, lapack_int ilo, lapack_int ihi, float *h, lapack_int ldh, float *t, lapack_int ldt, float *alphar, float *alphai, float *beta, float *q, lapack_int ldq, float *z, lapack_int ldz, float *work, lapack_int lwork)
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:36
#define LAPACK_COL_MAJOR
Definition: lapacke.h:120
void LAPACKE_xerbla(const char *name, lapack_int info)
#define lapack_int
Definition: lapacke.h:47
#define LAPACK_TRANSPOSE_MEMORY_ERROR
Definition: lapacke.h:123