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