LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
lapacke_stgsna_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 stgsna
30* Author: Intel Corporation
31*****************************************************************************/
32
33#include "lapacke_utils.h"
34
35lapack_int LAPACKE_stgsna_work( int matrix_layout, char job, char howmny,
36 const lapack_logical* select, lapack_int n,
37 const float* a, lapack_int lda, const float* b,
38 lapack_int ldb, const float* vl,
39 lapack_int ldvl, const float* vr,
40 lapack_int ldvr, float* s, float* dif,
41 lapack_int mm, lapack_int* m, float* work,
42 lapack_int lwork, lapack_int* iwork )
43{
44 lapack_int info = 0;
45 if( matrix_layout == LAPACK_COL_MAJOR ) {
46 /* Call LAPACK function and adjust info */
47 LAPACK_stgsna( &job, &howmny, select, &n, a, &lda, b, &ldb, vl, &ldvl,
48 vr, &ldvr, s, dif, &mm, m, work, &lwork, iwork, &info );
49 if( info < 0 ) {
50 info = info - 1;
51 }
52 } else if( matrix_layout == LAPACK_ROW_MAJOR ) {
53 lapack_int lda_t = MAX(1,n);
54 lapack_int ldb_t = MAX(1,n);
55 lapack_int ldvl_t = MAX(1,n);
56 lapack_int ldvr_t = MAX(1,n);
57 float* a_t = NULL;
58 float* b_t = NULL;
59 float* vl_t = NULL;
60 float* vr_t = NULL;
61 /* Check leading dimension(s) */
62 if( lda < n ) {
63 info = -7;
64 LAPACKE_xerbla( "LAPACKE_stgsna_work", info );
65 return info;
66 }
67 if( ldb < n ) {
68 info = -9;
69 LAPACKE_xerbla( "LAPACKE_stgsna_work", info );
70 return info;
71 }
72 if( ldvl < mm ) {
73 info = -11;
74 LAPACKE_xerbla( "LAPACKE_stgsna_work", info );
75 return info;
76 }
77 if( ldvr < mm ) {
78 info = -13;
79 LAPACKE_xerbla( "LAPACKE_stgsna_work", info );
80 return info;
81 }
82 /* Query optimal working array(s) size if requested */
83 if( lwork == -1 ) {
84 LAPACK_stgsna( &job, &howmny, select, &n, a, &lda_t, b, &ldb_t, vl,
85 &ldvl_t, vr, &ldvr_t, s, dif, &mm, m, work, &lwork,
86 iwork, &info );
87 return (info < 0) ? (info - 1) : info;
88 }
89 /* Allocate memory for temporary array(s) */
90 a_t = (float*)LAPACKE_malloc( sizeof(float) * lda_t * MAX(1,n) );
91 if( a_t == NULL ) {
93 goto exit_level_0;
94 }
95 b_t = (float*)LAPACKE_malloc( sizeof(float) * ldb_t * MAX(1,n) );
96 if( b_t == NULL ) {
98 goto exit_level_1;
99 }
100 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'e' ) ) {
101 vl_t = (float*)LAPACKE_malloc( sizeof(float) * ldvl_t * MAX(1,mm) );
102 if( vl_t == NULL ) {
104 goto exit_level_2;
105 }
106 }
107 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'e' ) ) {
108 vr_t = (float*)LAPACKE_malloc( sizeof(float) * ldvr_t * MAX(1,mm) );
109 if( vr_t == NULL ) {
111 goto exit_level_3;
112 }
113 }
114 /* Transpose input matrices */
115 LAPACKE_sge_trans( matrix_layout, n, n, a, lda, a_t, lda_t );
116 LAPACKE_sge_trans( matrix_layout, n, n, b, ldb, b_t, ldb_t );
117 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'e' ) ) {
118 LAPACKE_sge_trans( matrix_layout, n, mm, vl, ldvl, vl_t, ldvl_t );
119 }
120 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'e' ) ) {
121 LAPACKE_sge_trans( matrix_layout, n, mm, vr, ldvr, vr_t, ldvr_t );
122 }
123 /* Call LAPACK function and adjust info */
124 LAPACK_stgsna( &job, &howmny, select, &n, a_t, &lda_t, b_t, &ldb_t,
125 vl_t, &ldvl_t, vr_t, &ldvr_t, s, dif, &mm, m, work,
126 &lwork, iwork, &info );
127 if( info < 0 ) {
128 info = info - 1;
129 }
130 /* Release memory and exit */
131 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'e' ) ) {
132 LAPACKE_free( vr_t );
133 }
134exit_level_3:
135 if( LAPACKE_lsame( job, 'b' ) || LAPACKE_lsame( job, 'e' ) ) {
136 LAPACKE_free( vl_t );
137 }
138exit_level_2:
139 LAPACKE_free( b_t );
140exit_level_1:
141 LAPACKE_free( a_t );
142exit_level_0:
143 if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
144 LAPACKE_xerbla( "LAPACKE_stgsna_work", info );
145 }
146 } else {
147 info = -1;
148 LAPACKE_xerbla( "LAPACKE_stgsna_work", info );
149 }
150 return info;
151}
#define lapack_int
Definition: lapack.h:87
#define LAPACK_stgsna(...)
Definition: lapack.h:20414
#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_stgsna_work(int matrix_layout, char job, char howmny, const lapack_logical *select, lapack_int n, const float *a, lapack_int lda, const float *b, lapack_int ldb, const float *vl, lapack_int ldvl, const float *vr, lapack_int ldvr, float *s, float *dif, lapack_int mm, lapack_int *m, float *work, lapack_int lwork, lapack_int *iwork)
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