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 cgerfsx
30 * Author: Intel Corporation
31 *****************************************************************************/
32 
33 #include "lapacke_utils.h"
34 
LAPACKE_cgerfsx(int matrix_layout,char trans,char equed,lapack_int n,lapack_int nrhs,const lapack_complex_float * a,lapack_int lda,const lapack_complex_float * af,lapack_int ldaf,const lapack_int * ipiv,const float * r,const float * c,const lapack_complex_float * b,lapack_int ldb,lapack_complex_float * x,lapack_int ldx,float * rcond,float * berr,lapack_int n_err_bnds,float * err_bnds_norm,float * err_bnds_comp,lapack_int nparams,float * params)35 lapack_int LAPACKE_cgerfsx( int matrix_layout, char trans, char equed,
36                             lapack_int n, lapack_int nrhs,
37                             const lapack_complex_float* a, lapack_int lda,
38                             const lapack_complex_float* af, lapack_int ldaf,
39                             const lapack_int* ipiv, const float* r,
40                             const float* c, const lapack_complex_float* b,
41                             lapack_int ldb, lapack_complex_float* x,
42                             lapack_int ldx, float* rcond, float* berr,
43                             lapack_int n_err_bnds, float* err_bnds_norm,
44                             float* err_bnds_comp, lapack_int nparams,
45                             float* params )
46 {
47     lapack_int info = 0;
48     float* rwork = NULL;
49     lapack_complex_float* work = NULL;
50     if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) {
51         LAPACKE_xerbla( "LAPACKE_cgerfsx", -1 );
52         return -1;
53     }
54 #ifndef LAPACK_DISABLE_NAN_CHECK
55     if( LAPACKE_get_nancheck() ) {
56         /* Optionally check input matrices for NaNs */
57         if( LAPACKE_cge_nancheck( matrix_layout, n, n, a, lda ) ) {
58             return -6;
59         }
60         if( LAPACKE_cge_nancheck( matrix_layout, n, n, af, ldaf ) ) {
61             return -8;
62         }
63         if( LAPACKE_cge_nancheck( matrix_layout, n, nrhs, b, ldb ) ) {
64             return -13;
65         }
66         if( LAPACKE_lsame( equed, 'b' ) || LAPACKE_lsame( equed, 'c' ) ) {
67             if( LAPACKE_s_nancheck( n, c, 1 ) ) {
68                 return -12;
69             }
70         }
71         if( nparams>0 ) {
72             if( LAPACKE_s_nancheck( nparams, params, 1 ) ) {
73                 return -23;
74             }
75         }
76         if( LAPACKE_lsame( equed, 'b' ) || LAPACKE_lsame( equed, 'r' ) ) {
77             if( LAPACKE_s_nancheck( n, r, 1 ) ) {
78                 return -11;
79             }
80         }
81         if( LAPACKE_cge_nancheck( matrix_layout, n, nrhs, x, ldx ) ) {
82             return -15;
83         }
84     }
85 #endif
86     /* Allocate memory for working array(s) */
87     rwork = (float*)LAPACKE_malloc( sizeof(float) * MAX(1,3*n) );
88     if( rwork == NULL ) {
89         info = LAPACK_WORK_MEMORY_ERROR;
90         goto exit_level_0;
91     }
92     work = (lapack_complex_float*)
93         LAPACKE_malloc( sizeof(lapack_complex_float) * MAX(1,2*n) );
94     if( work == NULL ) {
95         info = LAPACK_WORK_MEMORY_ERROR;
96         goto exit_level_1;
97     }
98     /* Call middle-level interface */
99     info = LAPACKE_cgerfsx_work( matrix_layout, trans, equed, n, nrhs, a, lda,
100                                  af, ldaf, ipiv, r, c, b, ldb, x, ldx, rcond,
101                                  berr, n_err_bnds, err_bnds_norm, err_bnds_comp,
102                                  nparams, params, work, rwork );
103     /* Release memory and exit */
104     LAPACKE_free( work );
105 exit_level_1:
106     LAPACKE_free( rwork );
107 exit_level_0:
108     if( info == LAPACK_WORK_MEMORY_ERROR ) {
109         LAPACKE_xerbla( "LAPACKE_cgerfsx", info );
110     }
111     return info;
112 }
113