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