LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
lapacke_dggsvp_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 dggsvp
30* Author: Intel Corporation
31*****************************************************************************/
32
33#include "lapacke_utils.h"
34
35lapack_int LAPACKE_dggsvp_work( int matrix_layout, char jobu, char jobv,
36 char jobq, lapack_int m, lapack_int p,
37 lapack_int n, double* a, lapack_int lda,
38 double* b, lapack_int ldb, double tola,
39 double tolb, lapack_int* k, lapack_int* l,
40 double* u, lapack_int ldu, double* v,
41 lapack_int ldv, double* q, lapack_int ldq,
42 lapack_int* iwork, double* tau, double* work )
43{
44 lapack_int info = 0;
45 if( matrix_layout == LAPACK_COL_MAJOR ) {
46 /* Call LAPACK function and adjust info */
47 LAPACK_dggsvp( &jobu, &jobv, &jobq, &m, &p, &n, a, &lda, b, &ldb, &tola,
48 &tolb, k, l, u, &ldu, v, &ldv, q, &ldq, iwork, tau, work,
49 &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,m);
55 lapack_int ldb_t = MAX(1,p);
56 lapack_int ldq_t = MAX(1,n);
57 lapack_int ldu_t = MAX(1,m);
58 lapack_int ldv_t = MAX(1,p);
59 double* a_t = NULL;
60 double* b_t = NULL;
61 double* u_t = NULL;
62 double* v_t = NULL;
63 double* q_t = NULL;
64 /* Check leading dimension(s) */
65 if( lda < n ) {
66 info = -9;
67 LAPACKE_xerbla( "LAPACKE_dggsvp_work", info );
68 return info;
69 }
70 if( ldb < n ) {
71 info = -11;
72 LAPACKE_xerbla( "LAPACKE_dggsvp_work", info );
73 return info;
74 }
75 if( ldq < n ) {
76 info = -21;
77 LAPACKE_xerbla( "LAPACKE_dggsvp_work", info );
78 return info;
79 }
80 if( ldu < m ) {
81 info = -17;
82 LAPACKE_xerbla( "LAPACKE_dggsvp_work", info );
83 return info;
84 }
85 if( ldv < m ) {
86 info = -19;
87 LAPACKE_xerbla( "LAPACKE_dggsvp_work", info );
88 return info;
89 }
90 /* Allocate memory for temporary array(s) */
91 a_t = (double*)LAPACKE_malloc( sizeof(double) * lda_t * MAX(1,n) );
92 if( a_t == NULL ) {
94 goto exit_level_0;
95 }
96 b_t = (double*)LAPACKE_malloc( sizeof(double) * ldb_t * MAX(1,n) );
97 if( b_t == NULL ) {
99 goto exit_level_1;
100 }
101 if( LAPACKE_lsame( jobu, 'u' ) ) {
102 u_t = (double*)LAPACKE_malloc( sizeof(double) * ldu_t * MAX(1,m) );
103 if( u_t == NULL ) {
105 goto exit_level_2;
106 }
107 }
108 if( LAPACKE_lsame( jobv, 'v' ) ) {
109 v_t = (double*)LAPACKE_malloc( sizeof(double) * ldv_t * MAX(1,m) );
110 if( v_t == NULL ) {
112 goto exit_level_3;
113 }
114 }
115 if( LAPACKE_lsame( jobq, 'q' ) ) {
116 q_t = (double*)LAPACKE_malloc( sizeof(double) * ldq_t * MAX(1,n) );
117 if( q_t == NULL ) {
119 goto exit_level_4;
120 }
121 }
122 /* Transpose input matrices */
123 LAPACKE_dge_trans( matrix_layout, m, n, a, lda, a_t, lda_t );
124 LAPACKE_dge_trans( matrix_layout, p, n, b, ldb, b_t, ldb_t );
125 /* Call LAPACK function and adjust info */
126 LAPACK_dggsvp( &jobu, &jobv, &jobq, &m, &p, &n, a_t, &lda_t, b_t,
127 &ldb_t, &tola, &tolb, k, l, u_t, &ldu_t, v_t, &ldv_t,
128 q_t, &ldq_t, iwork, tau, work, &info );
129 if( info < 0 ) {
130 info = info - 1;
131 }
132 /* Transpose output matrices */
133 LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_t, lda_t, a, lda );
134 LAPACKE_dge_trans( LAPACK_COL_MAJOR, p, n, b_t, ldb_t, b, ldb );
135 if( LAPACKE_lsame( jobu, 'u' ) ) {
136 LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, m, u_t, ldu_t, u, ldu );
137 }
138 if( LAPACKE_lsame( jobv, 'v' ) ) {
139 LAPACKE_dge_trans( LAPACK_COL_MAJOR, p, m, v_t, ldv_t, v, ldv );
140 }
141 if( LAPACKE_lsame( jobq, 'q' ) ) {
142 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, q_t, ldq_t, q, ldq );
143 }
144 /* Release memory and exit */
145 if( LAPACKE_lsame( jobq, 'q' ) ) {
146 LAPACKE_free( q_t );
147 }
148exit_level_4:
149 if( LAPACKE_lsame( jobv, 'v' ) ) {
150 LAPACKE_free( v_t );
151 }
152exit_level_3:
153 if( LAPACKE_lsame( jobu, 'u' ) ) {
154 LAPACKE_free( u_t );
155 }
156exit_level_2:
157 LAPACKE_free( b_t );
158exit_level_1:
159 LAPACKE_free( a_t );
160exit_level_0:
161 if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
162 LAPACKE_xerbla( "LAPACKE_dggsvp_work", info );
163 }
164 } else {
165 info = -1;
166 LAPACKE_xerbla( "LAPACKE_dggsvp_work", info );
167 }
168 return info;
169}
#define LAPACK_dggsvp(...)
Definition: lapack.h:5515
#define lapack_int
Definition: lapack.h:87
#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_dggsvp_work(int matrix_layout, char jobu, char jobv, char jobq, lapack_int m, lapack_int p, lapack_int n, double *a, lapack_int lda, double *b, lapack_int ldb, double tola, double tolb, lapack_int *k, lapack_int *l, double *u, lapack_int ldu, double *v, lapack_int ldv, double *q, lapack_int ldq, lapack_int *iwork, double *tau, double *work)
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:35
void LAPACKE_xerbla(const char *name, lapack_int info)
#define MAX(x, y)
Definition: lapacke_utils.h:46
void LAPACKE_dge_trans(int matrix_layout, lapack_int m, lapack_int n, const double *in, lapack_int ldin, double *out, lapack_int ldout)