LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
lapacke_sgges_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 sgges
30* Author: Intel Corporation
31*****************************************************************************/
32
33#include "lapacke_utils.h"
34
35lapack_int LAPACKE_sgges_work( int matrix_layout, char jobvsl, char jobvsr,
36 char sort, LAPACK_S_SELECT3 selctg, lapack_int n,
37 float* a, lapack_int lda, float* b,
38 lapack_int ldb, lapack_int* sdim, float* alphar,
39 float* alphai, float* beta, float* vsl,
40 lapack_int ldvsl, float* vsr, lapack_int ldvsr,
41 float* work, lapack_int lwork,
42 lapack_logical* bwork )
43{
44 lapack_int info = 0;
45 if( matrix_layout == LAPACK_COL_MAJOR ) {
46 /* Call LAPACK function and adjust info */
47 LAPACK_sgges( &jobvsl, &jobvsr, &sort, selctg, &n, a, &lda, b, &ldb,
48 sdim, alphar, alphai, beta, vsl, &ldvsl, vsr, &ldvsr,
49 work, &lwork, bwork, &info );
50 if( info < 0 ) {
51 info = info - 1;
52 }
53 } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
54 lapack_int lda_t = MAX(1,n);
55 lapack_int ldb_t = MAX(1,n);
56 lapack_int ldvsl_t = MAX(1,n);
57 lapack_int ldvsr_t = MAX(1,n);
58 float* a_t = NULL;
59 float* b_t = NULL;
60 float* vsl_t = NULL;
61 float* vsr_t = NULL;
62 /* Check leading dimension(s) */
63 if( lda < n ) {
64 info = -8;
65 LAPACKE_xerbla( "LAPACKE_sgges_work", info );
66 return info;
67 }
68 if( ldb < n ) {
69 info = -10;
70 LAPACKE_xerbla( "LAPACKE_sgges_work", info );
71 return info;
72 }
73 if( ldvsl < 1 || ( LAPACKE_lsame( jobvsl, 'v' ) && ldvsl < n ) ) {
74 info = -16;
75 LAPACKE_xerbla( "LAPACKE_sgges_work", info );
76 return info;
77 }
78 if( ldvsr < 1 || ( LAPACKE_lsame( jobvsr, 'v' ) && ldvsr < n ) ) {
79 info = -18;
80 LAPACKE_xerbla( "LAPACKE_sgges_work", info );
81 return info;
82 }
83 /* Query optimal working array(s) size if requested */
84 if( lwork == -1 ) {
85 LAPACK_sgges( &jobvsl, &jobvsr, &sort, selctg, &n, a, &lda_t, b,
86 &ldb_t, sdim, alphar, alphai, beta, vsl, &ldvsl_t,
87 vsr, &ldvsr_t, work, &lwork, bwork, &info );
88 return (info < 0) ? (info - 1) : info;
89 }
90 /* Allocate memory for temporary array(s) */
91 a_t = (float*)LAPACKE_malloc( sizeof(float) * lda_t * MAX(1,n) );
92 if( a_t == NULL ) {
94 goto exit_level_0;
95 }
96 b_t = (float*)LAPACKE_malloc( sizeof(float) * ldb_t * MAX(1,n) );
97 if( b_t == NULL ) {
99 goto exit_level_1;
100 }
101 if( LAPACKE_lsame( jobvsl, 'v' ) ) {
102 vsl_t = (float*)
103 LAPACKE_malloc( sizeof(float) * ldvsl_t * MAX(1,n) );
104 if( vsl_t == NULL ) {
106 goto exit_level_2;
107 }
108 }
109 if( LAPACKE_lsame( jobvsr, 'v' ) ) {
110 vsr_t = (float*)
111 LAPACKE_malloc( sizeof(float) * ldvsr_t * MAX(1,n) );
112 if( vsr_t == NULL ) {
114 goto exit_level_3;
115 }
116 }
117 /* Transpose input matrices */
118 LAPACKE_sge_trans( matrix_layout, n, n, a, lda, a_t, lda_t );
119 LAPACKE_sge_trans( matrix_layout, n, n, b, ldb, b_t, ldb_t );
120 /* Call LAPACK function and adjust info */
121 LAPACK_sgges( &jobvsl, &jobvsr, &sort, selctg, &n, a_t, &lda_t, b_t,
122 &ldb_t, sdim, alphar, alphai, beta, vsl_t, &ldvsl_t,
123 vsr_t, &ldvsr_t, work, &lwork, bwork, &info );
124 if( info < 0 ) {
125 info = info - 1;
126 }
127 /* Transpose output matrices */
128 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_t, lda_t, a, lda );
129 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, b_t, ldb_t, b, ldb );
130 if( LAPACKE_lsame( jobvsl, 'v' ) ) {
131 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, vsl_t, ldvsl_t, vsl,
132 ldvsl );
133 }
134 if( LAPACKE_lsame( jobvsr, 'v' ) ) {
135 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, vsr_t, ldvsr_t, vsr,
136 ldvsr );
137 }
138 /* Release memory and exit */
139 if( LAPACKE_lsame( jobvsr, 'v' ) ) {
140 LAPACKE_free( vsr_t );
141 }
142exit_level_3:
143 if( LAPACKE_lsame( jobvsl, 'v' ) ) {
144 LAPACKE_free( vsl_t );
145 }
146exit_level_2:
147 LAPACKE_free( b_t );
148exit_level_1:
149 LAPACKE_free( a_t );
150exit_level_0:
151 if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
152 LAPACKE_xerbla( "LAPACKE_sgges_work", info );
153 }
154 } else {
155 info = -1;
156 LAPACKE_xerbla( "LAPACKE_sgges_work", info );
157 }
158 return info;
159}
#define LAPACK_sgges(...)
Definition: lapack.h:4434
#define lapack_int
Definition: lapack.h:87
lapack_logical(* LAPACK_S_SELECT3)(const float *, const float *, const float *)
Definition: lapack.h:121
#define lapack_logical
Definition: lapack.h:103
#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_sgges_work(int matrix_layout, char jobvsl, char jobvsr, char sort, LAPACK_S_SELECT3 selctg, lapack_int n, float *a, lapack_int lda, float *b, lapack_int ldb, lapack_int *sdim, float *alphar, float *alphai, float *beta, float *vsl, lapack_int ldvsl, float *vsr, lapack_int ldvsr, float *work, lapack_int lwork, lapack_logical *bwork)
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:35
void LAPACKE_xerbla(const char *name, 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:46