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 chbgvx
30 * Author: Intel Corporation
31 *****************************************************************************/
32
33 #include "lapacke_utils.h"
34
LAPACKE_chbgvx_work(int matrix_layout,char jobz,char range,char uplo,lapack_int n,lapack_int ka,lapack_int kb,lapack_complex_float * ab,lapack_int ldab,lapack_complex_float * bb,lapack_int ldbb,lapack_complex_float * q,lapack_int ldq,float vl,float vu,lapack_int il,lapack_int iu,float abstol,lapack_int * m,float * w,lapack_complex_float * z,lapack_int ldz,lapack_complex_float * work,float * rwork,lapack_int * iwork,lapack_int * ifail)35 lapack_int LAPACKE_chbgvx_work( int matrix_layout, char jobz, char range,
36 char uplo, lapack_int n, lapack_int ka,
37 lapack_int kb, lapack_complex_float* ab,
38 lapack_int ldab, lapack_complex_float* bb,
39 lapack_int ldbb, lapack_complex_float* q,
40 lapack_int ldq, float vl, float vu,
41 lapack_int il, lapack_int iu, float abstol,
42 lapack_int* m, float* w,
43 lapack_complex_float* z, lapack_int ldz,
44 lapack_complex_float* work, float* 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_chbgvx( &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_float* ab_t = NULL;
62 lapack_complex_float* bb_t = NULL;
63 lapack_complex_float* q_t = NULL;
64 lapack_complex_float* z_t = NULL;
65 /* Check leading dimension(s) */
66 if( ldab < n ) {
67 info = -9;
68 LAPACKE_xerbla( "LAPACKE_chbgvx_work", info );
69 return info;
70 }
71 if( ldbb < n ) {
72 info = -11;
73 LAPACKE_xerbla( "LAPACKE_chbgvx_work", info );
74 return info;
75 }
76 if( ldq < n ) {
77 info = -13;
78 LAPACKE_xerbla( "LAPACKE_chbgvx_work", info );
79 return info;
80 }
81 if( ldz < n ) {
82 info = -22;
83 LAPACKE_xerbla( "LAPACKE_chbgvx_work", info );
84 return info;
85 }
86 /* Allocate memory for temporary array(s) */
87 ab_t = (lapack_complex_float*)
88 LAPACKE_malloc( sizeof(lapack_complex_float) * ldab_t * MAX(1,n) );
89 if( ab_t == NULL ) {
90 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
91 goto exit_level_0;
92 }
93 bb_t = (lapack_complex_float*)
94 LAPACKE_malloc( sizeof(lapack_complex_float) * ldbb_t * MAX(1,n) );
95 if( bb_t == NULL ) {
96 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
97 goto exit_level_1;
98 }
99 if( LAPACKE_lsame( jobz, 'v' ) ) {
100 q_t = (lapack_complex_float*)
101 LAPACKE_malloc( sizeof(lapack_complex_float) *
102 ldq_t * MAX(1,n) );
103 if( q_t == NULL ) {
104 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
105 goto exit_level_2;
106 }
107 }
108 if( LAPACKE_lsame( jobz, 'v' ) ) {
109 z_t = (lapack_complex_float*)
110 LAPACKE_malloc( sizeof(lapack_complex_float) *
111 ldz_t * MAX(1,n) );
112 if( z_t == NULL ) {
113 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
114 goto exit_level_3;
115 }
116 }
117 /* Transpose input matrices */
118 LAPACKE_chb_trans( matrix_layout, uplo, n, ka, ab, ldab, ab_t, ldab_t );
119 LAPACKE_chb_trans( matrix_layout, uplo, n, kb, bb, ldbb, bb_t, ldbb_t );
120 /* Call LAPACK function and adjust info */
121 LAPACK_chbgvx( &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_chb_trans( LAPACK_COL_MAJOR, uplo, n, ka, ab_t, ldab_t, ab,
129 ldab );
130 LAPACKE_chb_trans( LAPACK_COL_MAJOR, uplo, n, kb, bb_t, ldbb_t, bb,
131 ldbb );
132 if( LAPACKE_lsame( jobz, 'v' ) ) {
133 LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, q_t, ldq_t, q, ldq );
134 }
135 if( LAPACKE_lsame( jobz, 'v' ) ) {
136 LAPACKE_cge_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_chbgvx_work", info );
153 }
154 } else {
155 info = -1;
156 LAPACKE_xerbla( "LAPACKE_chbgvx_work", info );
157 }
158 return info;
159 }
160