LAPACK  3.10.1
LAPACK: Linear Algebra PACKage
lapacke_zhbgvx_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 zhbgvx
30 * Author: Intel Corporation
31 *****************************************************************************/
32 
33 #include "lapacke_utils.h"
34 
35 lapack_int LAPACKE_zhbgvx_work( int matrix_layout, char jobz, char range,
36  char uplo, lapack_int n, lapack_int ka,
40  lapack_int ldq, double vl, double vu,
41  lapack_int il, lapack_int iu, double abstol,
42  lapack_int* m, double* w,
44  lapack_complex_double* work, double* rwork,
45  lapack_int* iwork, lapack_int* ifail )
46 {
47  lapack_int info = 0;
48  if( matrix_layout == LAPACK_COL_MAJOR ) {
49  /* Call LAPACK function and adjust info */
50  LAPACK_zhbgvx( &jobz, &range, &uplo, &n, &ka, &kb, ab, &ldab, bb, &ldbb,
51  q, &ldq, &vl, &vu, &il, &iu, &abstol, m, w, z, &ldz,
52  work, rwork, iwork, ifail, &info );
53  if( info < 0 ) {
54  info = info - 1;
55  }
56  } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
57  lapack_int ldab_t = MAX(1,ka+1);
58  lapack_int ldbb_t = MAX(1,kb+1);
59  lapack_int ldq_t = MAX(1,n);
60  lapack_int ldz_t = MAX(1,n);
61  lapack_complex_double* ab_t = NULL;
62  lapack_complex_double* bb_t = NULL;
63  lapack_complex_double* q_t = NULL;
64  lapack_complex_double* z_t = NULL;
65  /* Check leading dimension(s) */
66  if( ldab < n ) {
67  info = -9;
68  LAPACKE_xerbla( "LAPACKE_zhbgvx_work", info );
69  return info;
70  }
71  if( ldbb < n ) {
72  info = -11;
73  LAPACKE_xerbla( "LAPACKE_zhbgvx_work", info );
74  return info;
75  }
76  if( ldq < n ) {
77  info = -13;
78  LAPACKE_xerbla( "LAPACKE_zhbgvx_work", info );
79  return info;
80  }
81  if( ldz < n ) {
82  info = -22;
83  LAPACKE_xerbla( "LAPACKE_zhbgvx_work", info );
84  return info;
85  }
86  /* Allocate memory for temporary array(s) */
87  ab_t = (lapack_complex_double*)
88  LAPACKE_malloc( sizeof(lapack_complex_double) * ldab_t * MAX(1,n) );
89  if( ab_t == NULL ) {
91  goto exit_level_0;
92  }
93  bb_t = (lapack_complex_double*)
94  LAPACKE_malloc( sizeof(lapack_complex_double) * ldbb_t * MAX(1,n) );
95  if( bb_t == NULL ) {
97  goto exit_level_1;
98  }
99  if( LAPACKE_lsame( jobz, 'v' ) ) {
100  q_t = (lapack_complex_double*)
102  ldq_t * MAX(1,n) );
103  if( q_t == NULL ) {
105  goto exit_level_2;
106  }
107  }
108  if( LAPACKE_lsame( jobz, 'v' ) ) {
109  z_t = (lapack_complex_double*)
111  ldz_t * MAX(1,n) );
112  if( z_t == NULL ) {
114  goto exit_level_3;
115  }
116  }
117  /* Transpose input matrices */
118  LAPACKE_zhb_trans( matrix_layout, uplo, n, ka, ab, ldab, ab_t, ldab_t );
119  LAPACKE_zhb_trans( matrix_layout, uplo, n, kb, bb, ldbb, bb_t, ldbb_t );
120  /* Call LAPACK function and adjust info */
121  LAPACK_zhbgvx( &jobz, &range, &uplo, &n, &ka, &kb, ab_t, &ldab_t, bb_t,
122  &ldbb_t, q_t, &ldq_t, &vl, &vu, &il, &iu, &abstol, m, w,
123  z_t, &ldz_t, work, rwork, iwork, ifail, &info );
124  if( info < 0 ) {
125  info = info - 1;
126  }
127  /* Transpose output matrices */
128  LAPACKE_zhb_trans( LAPACK_COL_MAJOR, uplo, n, ka, ab_t, ldab_t, ab,
129  ldab );
130  LAPACKE_zhb_trans( LAPACK_COL_MAJOR, uplo, n, kb, bb_t, ldbb_t, bb,
131  ldbb );
132  if( LAPACKE_lsame( jobz, 'v' ) ) {
133  LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_t, ldq_t, q, ldq );
134  }
135  if( LAPACKE_lsame( jobz, 'v' ) ) {
136  LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, z_t, ldz_t, z, ldz );
137  }
138  /* Release memory and exit */
139  if( LAPACKE_lsame( jobz, 'v' ) ) {
140  LAPACKE_free( z_t );
141  }
142 exit_level_3:
143  if( LAPACKE_lsame( jobz, 'v' ) ) {
144  LAPACKE_free( q_t );
145  }
146 exit_level_2:
147  LAPACKE_free( bb_t );
148 exit_level_1:
149  LAPACKE_free( ab_t );
150 exit_level_0:
151  if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
152  LAPACKE_xerbla( "LAPACKE_zhbgvx_work", info );
153  }
154  } else {
155  info = -1;
156  LAPACKE_xerbla( "LAPACKE_zhbgvx_work", info );
157  }
158  return info;
159 }
#define lapack_int
Definition: lapack.h:83
#define lapack_complex_double
Definition: lapack.h:63
#define LAPACK_zhbgvx(...)
Definition: lapack.h:6557
#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_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:35
void LAPACKE_xerbla(const char *name, lapack_int info)
void LAPACKE_zge_trans(int matrix_layout, lapack_int m, lapack_int n, const lapack_complex_double *in, lapack_int ldin, lapack_complex_double *out, lapack_int ldout)
#define MAX(x, y)
Definition: lapacke_utils.h:46
void LAPACKE_zhb_trans(int matrix_layout, char uplo, lapack_int n, lapack_int kd, const lapack_complex_double *in, lapack_int ldin, lapack_complex_double *out, lapack_int ldout)
lapack_int LAPACKE_zhbgvx_work(int matrix_layout, char jobz, char range, char uplo, lapack_int n, lapack_int ka, lapack_int kb, lapack_complex_double *ab, lapack_int ldab, lapack_complex_double *bb, lapack_int ldbb, lapack_complex_double *q, lapack_int ldq, double vl, double vu, lapack_int il, lapack_int iu, double abstol, lapack_int *m, double *w, lapack_complex_double *z, lapack_int ldz, lapack_complex_double *work, double *rwork, lapack_int *iwork, lapack_int *ifail)