LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
lapacke_sgejsv.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 high-level C interface to LAPACK function sgejsv
30 * Author: Intel Corporation
31 * Generated June 2016
32 *****************************************************************************/
33 
34 #include "lapacke_utils.h"
35 
36 lapack_int LAPACKE_sgejsv( int matrix_layout, char joba, char jobu, char jobv,
37  char jobr, char jobt, char jobp, lapack_int m,
38  lapack_int n, float* a, lapack_int lda, float* sva,
39  float* u, lapack_int ldu, float* v, lapack_int ldv,
40  float* stat, lapack_int* istat )
41 {
42  lapack_int info = 0;
43  lapack_int lwork = (!( LAPACKE_lsame( jobu, 'u' ) ||
44  LAPACKE_lsame( jobu, 'f' ) ||
45  LAPACKE_lsame( jobv, 'v' ) ||
46  LAPACKE_lsame( jobv, 'j' ) ||
47  LAPACKE_lsame( joba, 'e' ) ||
48  LAPACKE_lsame( joba, 'g' ) ) ? MAX3(7,4*n+1,2*m+n) :
49  ( (!( LAPACKE_lsame( jobu, 'u' ) ||
50  LAPACKE_lsame( jobu, 'f' ) ||
51  LAPACKE_lsame( jobv, 'v' ) ||
52  LAPACKE_lsame( jobv, 'j' ) ) &&
53  ( LAPACKE_lsame( joba, 'e' ) ||
54  LAPACKE_lsame( joba, 'g' ) ) ) ? MAX3(7,4*n+n*n,2*m+n) :
55  ( ( LAPACKE_lsame( jobu, 'u' ) ||
56  LAPACKE_lsame( jobu, 'f' ) ) &&
57  (!( LAPACKE_lsame( jobv, 'v' ) ||
58  LAPACKE_lsame( jobv, 'j' ) ) ) ? MAX(7,2*n+m) :
59  ( ( LAPACKE_lsame( jobv, 'v' ) ||
60  LAPACKE_lsame( jobv, 'j' ) ) &&
61  (!( LAPACKE_lsame( jobu, 'u' ) ||
62  LAPACKE_lsame( jobu, 'f' ) ) ) ? MAX(7,2*n+m) :
63  ( ( LAPACKE_lsame( jobu, 'u' ) ||
64  LAPACKE_lsame( jobu, 'f' ) ) &&
65  ( LAPACKE_lsame( jobv, 'v' ) ||
66  LAPACKE_lsame( jobv, 'j' ) ) &&
67  !LAPACKE_lsame( jobv, 'j' ) ? MAX(1,6*n+2*n*n) :
68  ( ( LAPACKE_lsame( jobu, 'u' ) ||
69  LAPACKE_lsame( jobu, 'f' ) ) &&
70  ( LAPACKE_lsame( jobv, 'v' ) ||
71  LAPACKE_lsame( jobv, 'j' ) ) &&
72  LAPACKE_lsame( jobv, 'j' ) ? MAX(7,m+3*n+n*n) :
73  7) ) ) ) ) );
74  lapack_int* iwork = NULL;
75  float* work = NULL;
76  lapack_int i;
77  lapack_int nu, nv;
78  if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) {
79  LAPACKE_xerbla( "LAPACKE_sgejsv", -1 );
80  return -1;
81  }
82 #ifndef LAPACK_DISABLE_NAN_CHECK
83  /* Optionally check input matrices for NaNs */
84  nu = LAPACKE_lsame( jobu, 'n' ) ? 1 : m;
85  nv = LAPACKE_lsame( jobv, 'n' ) ? 1 : n;
86  if( LAPACKE_sge_nancheck( matrix_layout, m, n, a, lda ) ) {
87  return -10;
88  }
89 #endif
90  /* Allocate memory for working array(s) */
91  iwork = (lapack_int*)LAPACKE_malloc( sizeof(lapack_int) * MAX(3,m+3*n) );
92  if( iwork == NULL ) {
94  goto exit_level_0;
95  }
96  lwork = MAX3( lwork, 7, 2*m+n );
97  { /* FIXUP LWORK */
98  int want_u = LAPACKE_lsame( jobu, 'u' ) || LAPACKE_lsame( jobu, 'f' );
99  int want_v = LAPACKE_lsame( jobv, 'v' ) || LAPACKE_lsame( jobv, 'j' );
100  int want_sce = LAPACKE_lsame( joba, 'e' ) || LAPACKE_lsame( joba, 'g' );
101  if( !want_u && !want_v && !want_sce ) lwork = MAX( lwork, 4*n+1 ); // 1.1
102  if( !want_u && !want_v && want_sce ) lwork = MAX( lwork, n*n+4*n ); // 1.2
103  if( !want_u && want_v ) lwork = MAX( lwork, 4*n+1 ); // 2
104  if( want_u && !want_v ) lwork = MAX( lwork, 4*n+1 ); // 3
105  if( want_u && LAPACKE_lsame( jobv, 'v' ) ) lwork = MAX( lwork, 6*n+2*n*n ); // 4.1
106  if( want_u && LAPACKE_lsame( jobv, 'j' ) ) lwork = MAX3( lwork, 4*n+n*n, 2*n+n*n+6 ); // 4.2
107  }
108  work = (float*)LAPACKE_malloc( sizeof(float) * lwork );
109  if( work == NULL ) {
111  goto exit_level_1;
112  }
113  /* Call middle-level interface */
114  info = LAPACKE_sgejsv_work( matrix_layout, joba, jobu, jobv, jobr, jobt,
115  jobp, m, n, a, lda, sva, u, ldu, v, ldv, work,
116  lwork, iwork );
117  /* Backup significant data from working array(s) */
118  for( i=0; i<7; i++ ) {
119  stat[i] = work[i];
120  }
121  for( i=0; i<3; i++ ) {
122  istat[i] = iwork[i];
123  }
124  /* Release memory and exit */
125  LAPACKE_free( work );
126 exit_level_1:
127  LAPACKE_free( iwork );
128 exit_level_0:
129  if( info == LAPACK_WORK_MEMORY_ERROR ) {
130  LAPACKE_xerbla( "LAPACKE_sgejsv", info );
131  }
132  return info;
133 }
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:119
#define LAPACK_WORK_MEMORY_ERROR
Definition: lapacke.h:122
lapack_int LAPACKE_sgejsv(int matrix_layout, char joba, char jobu, char jobv, char jobr, char jobt, char jobp, lapack_int m, lapack_int n, float *a, lapack_int lda, float *sva, float *u, lapack_int ldu, float *v, lapack_int ldv, float *stat, lapack_int *istat)
lapack_logical LAPACKE_sge_nancheck(int matrix_layout, lapack_int m, lapack_int n, const float *a, lapack_int lda)
#define MAX3(x, y, z)
Definition: lapacke_utils.h:53
#define MAX(x, y)
Definition: lapacke_utils.h:47
#define LAPACKE_free(p)
Definition: lapacke.h:113
#define LAPACKE_malloc(size)
Definition: lapacke.h:110
lapack_int LAPACKE_sgejsv_work(int matrix_layout, char joba, char jobu, char jobv, char jobr, char jobt, char jobp, lapack_int m, lapack_int n, float *a, lapack_int lda, float *sva, float *u, lapack_int ldu, float *v, lapack_int ldv, float *work, lapack_int lwork, lapack_int *iwork)
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:36
#define LAPACK_COL_MAJOR
Definition: lapacke.h:120
void LAPACKE_xerbla(const char *name, lapack_int info)
#define lapack_int
Definition: lapacke.h:47