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 strevc
30 * Author: Intel Corporation
31 *****************************************************************************/
32
33 #include "lapacke_utils.h"
34
LAPACKE_strevc_work(int matrix_layout,char side,char howmny,lapack_logical * select,lapack_int n,const float * t,lapack_int ldt,float * vl,lapack_int ldvl,float * vr,lapack_int ldvr,lapack_int mm,lapack_int * m,float * work)35 lapack_int LAPACKE_strevc_work( int matrix_layout, char side, char howmny,
36 lapack_logical* select, lapack_int n,
37 const float* t, lapack_int ldt, float* vl,
38 lapack_int ldvl, float* vr, lapack_int ldvr,
39 lapack_int mm, lapack_int* m, float* work )
40 {
41 lapack_int info = 0;
42 if( matrix_layout == LAPACK_COL_MAJOR ) {
43 /* Call LAPACK function and adjust info */
44 LAPACK_strevc( &side, &howmny, select, &n, t, &ldt, vl, &ldvl, vr,
45 &ldvr, &mm, m, work, &info );
46 if( info < 0 ) {
47 info = info - 1;
48 }
49 } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
50 lapack_int ldt_t = MAX(1,n);
51 lapack_int ldvl_t = MAX(1,n);
52 lapack_int ldvr_t = MAX(1,n);
53 float* t_t = NULL;
54 float* vl_t = NULL;
55 float* vr_t = NULL;
56 /* Check leading dimension(s) */
57 if( ldt < n ) {
58 info = -7;
59 LAPACKE_xerbla( "LAPACKE_strevc_work", info );
60 return info;
61 }
62 if( ldvl < mm ) {
63 info = -9;
64 LAPACKE_xerbla( "LAPACKE_strevc_work", info );
65 return info;
66 }
67 if( ldvr < mm ) {
68 info = -11;
69 LAPACKE_xerbla( "LAPACKE_strevc_work", info );
70 return info;
71 }
72 /* Allocate memory for temporary array(s) */
73 t_t = (float*)LAPACKE_malloc( sizeof(float) * ldt_t * MAX(1,n) );
74 if( t_t == NULL ) {
75 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
76 goto exit_level_0;
77 }
78 if( LAPACKE_lsame( side, 'b' ) || LAPACKE_lsame( side, 'l' ) ) {
79 vl_t = (float*)LAPACKE_malloc( sizeof(float) * ldvl_t * MAX(1,mm) );
80 if( vl_t == NULL ) {
81 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
82 goto exit_level_1;
83 }
84 }
85 if( LAPACKE_lsame( side, 'b' ) || LAPACKE_lsame( side, 'r' ) ) {
86 vr_t = (float*)LAPACKE_malloc( sizeof(float) * ldvr_t * MAX(1,mm) );
87 if( vr_t == NULL ) {
88 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
89 goto exit_level_2;
90 }
91 }
92 /* Transpose input matrices */
93 LAPACKE_sge_trans( matrix_layout, n, n, t, ldt, t_t, ldt_t );
94 if( ( LAPACKE_lsame( side, 'l' ) || LAPACKE_lsame( side, 'b' ) ) &&
95 LAPACKE_lsame( howmny, 'b' ) ) {
96 LAPACKE_sge_trans( matrix_layout, n, mm, vl, ldvl, vl_t, ldvl_t );
97 }
98 if( ( LAPACKE_lsame( side, 'r' ) || LAPACKE_lsame( side, 'b' ) ) &&
99 LAPACKE_lsame( howmny, 'b' ) ) {
100 LAPACKE_sge_trans( matrix_layout, n, mm, vr, ldvr, vr_t, ldvr_t );
101 }
102 /* Call LAPACK function and adjust info */
103 LAPACK_strevc( &side, &howmny, select, &n, t_t, &ldt_t, vl_t, &ldvl_t,
104 vr_t, &ldvr_t, &mm, m, work, &info );
105 if( info < 0 ) {
106 info = info - 1;
107 }
108 /* Transpose output matrices */
109 if( LAPACKE_lsame( side, 'b' ) || LAPACKE_lsame( side, 'l' ) ) {
110 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, mm, vl_t, ldvl_t, vl,
111 ldvl );
112 }
113 if( LAPACKE_lsame( side, 'b' ) || LAPACKE_lsame( side, 'r' ) ) {
114 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, mm, vr_t, ldvr_t, vr,
115 ldvr );
116 }
117 /* Release memory and exit */
118 if( LAPACKE_lsame( side, 'b' ) || LAPACKE_lsame( side, 'r' ) ) {
119 LAPACKE_free( vr_t );
120 }
121 exit_level_2:
122 if( LAPACKE_lsame( side, 'b' ) || LAPACKE_lsame( side, 'l' ) ) {
123 LAPACKE_free( vl_t );
124 }
125 exit_level_1:
126 LAPACKE_free( t_t );
127 exit_level_0:
128 if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
129 LAPACKE_xerbla( "LAPACKE_strevc_work", info );
130 }
131 } else {
132 info = -1;
133 LAPACKE_xerbla( "LAPACKE_strevc_work", info );
134 }
135 return info;
136 }
137