1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/sytri.h
4 //  \brief Header file for the CLAPACK sytri wrapper functions
5 //
6 //  Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 //  This file is part of the Blaze library. You can redistribute it and/or modify it under
9 //  the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 //  forms, with or without modification, are permitted provided that the following conditions
11 //  are met:
12 //
13 //  1. Redistributions of source code must retain the above copyright notice, this list of
14 //     conditions and the following disclaimer.
15 //  2. Redistributions in binary form must reproduce the above copyright notice, this list
16 //     of conditions and the following disclaimer in the documentation and/or other materials
17 //     provided with the distribution.
18 //  3. Neither the names of the Blaze development group nor the names of its contributors
19 //     may be used to endorse or promote products derived from this software without specific
20 //     prior written permission.
21 //
22 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 //  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 //  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 //  SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 //  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 //  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 //  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 //  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 //  DAMAGE.
32 */
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_LAPACK_CLAPACK_SYTRI_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_SYTRI_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/blas/Types.h>
44 #include <blaze/util/Complex.h>
45 #include <blaze/util/StaticAssert.h>
46 #include <blaze/util/Types.h>
47 
48 
49 //=================================================================================================
50 //
51 //  LAPACK FORWARD DECLARATIONS
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
56 /*! \cond BLAZE_INTERNAL */
57 #if !defined(INTEL_MKL_VERSION)
58 extern "C" {
59 
60 void ssytri_( char* uplo, blaze::blas_int_t* n, float* A, blaze::blas_int_t* lda,
61               blaze::blas_int_t* ipiv, float* work, blaze::blas_int_t* info,
62               blaze::fortran_charlen_t nuplo );
63 void dsytri_( char* uplo, blaze::blas_int_t* n, double* A, blaze::blas_int_t* lda,
64               blaze::blas_int_t* ipiv, double* work, blaze::blas_int_t* info,
65               blaze::fortran_charlen_t nuplo );
66 void csytri_( char* uplo, blaze::blas_int_t* n, float* A, blaze::blas_int_t* lda,
67               blaze::blas_int_t* ipiv, float* work, blaze::blas_int_t* info,
68               blaze::fortran_charlen_t nuplo );
69 void zsytri_( char* uplo, blaze::blas_int_t* n, double* A, blaze::blas_int_t* lda,
70               blaze::blas_int_t* ipiv, double* work, blaze::blas_int_t* info,
71               blaze::fortran_charlen_t nuplo );
72 
73 }
74 #endif
75 /*! \endcond */
76 //*************************************************************************************************
77 
78 
79 
80 
81 namespace blaze {
82 
83 //=================================================================================================
84 //
85 //  LAPACK LDLT-BASED INVERSION FUNCTIONS (SYTRI)
86 //
87 //=================================================================================================
88 
89 //*************************************************************************************************
90 /*!\name LAPACK LDLT-based inversion functions (sytri) */
91 //@{
92 void sytri( char uplo, blas_int_t n, float* A, blas_int_t lda,
93             const blas_int_t* ipiv, float* work, blas_int_t* info );
94 
95 void sytri( char uplo, blas_int_t n, double* A, blas_int_t lda,
96             const blas_int_t* ipiv, double* work, blas_int_t* info );
97 
98 void sytri( char uplo, blas_int_t n, complex<float>* A, blas_int_t lda,
99             const blas_int_t* ipiv, complex<float>* work, blas_int_t* info );
100 
101 void sytri( char uplo, blas_int_t n, complex<double>* A, blas_int_t lda,
102             const blas_int_t* ipiv, complex<double>* work, blas_int_t* info );
103 //@}
104 //*************************************************************************************************
105 
106 
107 //*************************************************************************************************
108 /*!\brief LAPACK kernel for the inversion of the given dense symmetric indefinite single precision
109 //        column-major square matrix.
110 // \ingroup lapack_inversion
111 //
112 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
113 // \param n The number of rows/columns of the symmetric matrix \f$[0..\infty)\f$.
114 // \param A Pointer to the first element of the single precision column-major matrix.
115 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
116 // \param ipiv Auxiliary array of size \a n for the pivot indices.
117 // \param work Auxiliary array of size \a n.
118 // \param info Return code of the function call.
119 // \return void
120 //
121 // This function performs the dense matrix inversion based on the LAPACK ssytri() function for
122 // symmetric indefinite single precision column-major matrices that have already been factorized
123 // by the ssytrf() function.
124 //
125 // The \a info argument provides feedback on the success of the function call:
126 //
127 //   - = 0: The inversion finished successfully.
128 //   - < 0: If \a info = -i, the i-th argument had an illegal value.
129 //   - > 0: If \a info = i, element D(i,i) is exactly zero and the inverse could not be computed.
130 //
131 // For more information on the ssytri() function, see the LAPACK online documentation browser:
132 //
133 //        http://www.netlib.org/lapack/explore-html/
134 //
135 // \note This function can only be used if a fitting LAPACK library, which supports this function,
136 // is available and linked to the executable. Otherwise a call to this function will result in a
137 // linker error.
138 */
sytri(char uplo,blas_int_t n,float * A,blas_int_t lda,const blas_int_t * ipiv,float * work,blas_int_t * info)139 inline void sytri( char uplo, blas_int_t n, float* A, blas_int_t lda,
140                    const blas_int_t* ipiv, float* work, blas_int_t* info )
141 {
142 #if defined(INTEL_MKL_VERSION)
143    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
144 #endif
145 
146    ssytri_( &uplo, &n, A, &lda, const_cast<blas_int_t*>( ipiv ), work, info
147 #if !defined(INTEL_MKL_VERSION)
148           , blaze::fortran_charlen_t(1)
149 #endif
150           );
151 }
152 //*************************************************************************************************
153 
154 
155 //*************************************************************************************************
156 /*!\brief LAPACK kernel for the inversion of the given dense symmetric indefinite double precision
157 //        column-major square matrix.
158 // \ingroup lapack_inversion
159 //
160 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
161 // \param n The number of rows/columns of the symmetric matrix \f$[0..\infty)\f$.
162 // \param A Pointer to the first element of the double precision column-major matrix.
163 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
164 // \param ipiv Auxiliary array of size \a n for the pivot indices.
165 // \param work Auxiliary array of size \a n.
166 // \param info Return code of the function call.
167 // \return void
168 //
169 // This function performs the dense matrix inversion based on the LAPACK dsytri() function for
170 // symmetric indefinite double precision column-major matrices that have already been factorized
171 // by the dsytrf() function.
172 //
173 // The \a info argument provides feedback on the success of the function call:
174 //
175 //   - = 0: The inversion finished successfully.
176 //   - < 0: If \a info = -i, the i-th argument had an illegal value.
177 //   - > 0: If \a info = i, element D(i,i) is exactly zero and the inverse could not be computed.
178 //
179 // For more information on the dsytri() function, see the LAPACK online documentation browser:
180 //
181 //        http://www.netlib.org/lapack/explore-html/
182 //
183 // \note This function can only be used if a fitting LAPACK library, which supports this function,
184 // is available and linked to the executable. Otherwise a call to this function will result in a
185 // linker error.
186 */
sytri(char uplo,blas_int_t n,double * A,blas_int_t lda,const blas_int_t * ipiv,double * work,blas_int_t * info)187 inline void sytri( char uplo, blas_int_t n, double* A, blas_int_t lda,
188                    const blas_int_t* ipiv, double* work, blas_int_t* info )
189 {
190 #if defined(INTEL_MKL_VERSION)
191    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
192 #endif
193 
194    dsytri_( &uplo, &n, A, &lda, const_cast<blas_int_t*>( ipiv ), work, info
195 #if !defined(INTEL_MKL_VERSION)
196           , blaze::fortran_charlen_t(1)
197 #endif
198           );
199 }
200 //*************************************************************************************************
201 
202 
203 //*************************************************************************************************
204 /*!\brief LAPACK kernel for the inversion of the given dense symmetric indefinite single precision
205 //        complex column-major square matrix.
206 // \ingroup lapack_inversion
207 //
208 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
209 // \param n The number of rows/columns of the symmetric matrix \f$[0..\infty)\f$.
210 // \param A Pointer to the first element of the single precision complex column-major matrix.
211 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
212 // \param ipiv Auxiliary array of size \a n for the pivot indices.
213 // \param work Auxiliary array of size \a n.
214 // \param info Return code of the function call.
215 // \return void
216 //
217 // This function performs the dense matrix inversion based on the LAPACK csytri() function for
218 // symmetric indefinite single precision complex column-major matrices that have already been
219 // factorized by the csytrf() function.
220 //
221 // The \a info argument provides feedback on the success of the function call:
222 //
223 //   - = 0: The inversion finished successfully.
224 //   - < 0: If \a info = -i, the i-th argument had an illegal value.
225 //   - > 0: If \a info = i, element D(i,i) is exactly zero and the inverse could not be computed.
226 //
227 // For more information on the csytri() function, see the LAPACK online documentation browser:
228 //
229 //        http://www.netlib.org/lapack/explore-html/
230 //
231 // \note This function can only be used if a fitting LAPACK library, which supports this function,
232 // is available and linked to the executable. Otherwise a call to this function will result in a
233 // linker error.
234 */
sytri(char uplo,blas_int_t n,complex<float> * A,blas_int_t lda,const blas_int_t * ipiv,complex<float> * work,blas_int_t * info)235 inline void sytri( char uplo, blas_int_t n, complex<float>* A, blas_int_t lda,
236                    const blas_int_t* ipiv, complex<float>* work, blas_int_t* info )
237 {
238    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
239 
240 #if defined(INTEL_MKL_VERSION)
241    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
242    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex8 ) == sizeof( complex<float> ) );
243    using ET = MKL_Complex8;
244 #else
245    using ET = float;
246 #endif
247 
248    csytri_( &uplo, &n, reinterpret_cast<ET*>( A ), &lda,
249             const_cast<blas_int_t*>( ipiv ), reinterpret_cast<ET*>( work ), info
250 #if !defined(INTEL_MKL_VERSION)
251           , blaze::fortran_charlen_t(1)
252 #endif
253           );
254 }
255 //*************************************************************************************************
256 
257 
258 //*************************************************************************************************
259 /*!\brief LAPACK kernel for the inversion of the given dense symmetric indefinite double precision
260 //        complex column-major square matrix.
261 // \ingroup lapack_inversion
262 //
263 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
264 // \param n The number of rows/columns of the symmetric matrix \f$[0..\infty)\f$.
265 // \param A Pointer to the first element of the double precision complex column-major matrix.
266 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
267 // \param ipiv Auxiliary array of size \a n for the pivot indices.
268 // \param work Auxiliary array of size \a n.
269 // \param info Return code of the function call.
270 // \return void
271 //
272 // This function performs the dense matrix inversion based on the LAPACK zsytri() function for
273 // symmetric indefinite double precision complex column-major matrices that have already been
274 // factorized by the zsytrf() function.
275 //
276 // The \a info argument provides feedback on the success of the function call:
277 //
278 //   - = 0: The inversion finished successfully.
279 //   - < 0: If \a info = -i, the i-th argument had an illegal value.
280 //   - > 0: If \a info = i, element D(i,i) is exactly zero and the inverse could not be computed.
281 //
282 // For more information on the zsytri() function, see the LAPACK online documentation browser:
283 //
284 //        http://www.netlib.org/lapack/explore-html/
285 //
286 // \note This function can only be used if a fitting LAPACK library, which supports this function,
287 // is available and linked to the executable. Otherwise a call to this function will result in a
288 // linker error.
289 */
sytri(char uplo,blas_int_t n,complex<double> * A,blas_int_t lda,const blas_int_t * ipiv,complex<double> * work,blas_int_t * info)290 inline void sytri( char uplo, blas_int_t n, complex<double>* A, blas_int_t lda,
291                    const blas_int_t* ipiv, complex<double>* work, blas_int_t* info )
292 {
293    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
294 
295 #if defined(INTEL_MKL_VERSION)
296    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
297    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex16 ) == sizeof( complex<double> ) );
298    using ET = MKL_Complex16;
299 #else
300    using ET = double;
301 #endif
302 
303    zsytri_( &uplo, &n, reinterpret_cast<ET*>( A ), &lda,
304             const_cast<blas_int_t*>( ipiv ), reinterpret_cast<ET*>( work ), info
305 #if !defined(INTEL_MKL_VERSION)
306           , blaze::fortran_charlen_t(1)
307 #endif
308           );
309 }
310 //*************************************************************************************************
311 
312 } // namespace blaze
313 
314 #endif
315