1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/trtri.h
4 //  \brief Header file for the CLAPACK trtri 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_TRTRI_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_TRTRI_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) && !defined(BLAS_H)
58 extern "C" {
59 
60 void strtri_( char* uplo, char* diag, blaze::blas_int_t* n, float* A, blaze::blas_int_t* lda,
61               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo, blaze::fortran_charlen_t ndiag );
62 void dtrtri_( char* uplo, char* diag, blaze::blas_int_t* n, double* A, blaze::blas_int_t* lda,
63               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo, blaze::fortran_charlen_t ndiag );
64 void ctrtri_( char* uplo, char* diag, blaze::blas_int_t* n, float* A, blaze::blas_int_t* lda,
65               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo, blaze::fortran_charlen_t ndiag );
66 void ztrtri_( char* uplo, char* diag, blaze::blas_int_t* n, double* A, blaze::blas_int_t* lda,
67               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo, blaze::fortran_charlen_t ndiag );
68 
69 }
70 #endif
71 /*! \endcond */
72 //*************************************************************************************************
73 
74 
75 
76 
77 namespace blaze {
78 
79 //=================================================================================================
80 //
81 //  LAPACK TRIANGULAR MATRIX INVERSION FUNCTIONS (TRTRI)
82 //
83 //=================================================================================================
84 
85 //*************************************************************************************************
86 /*!\name LAPACK triangular matrix inversion functions (trtri) */
87 //@{
88 void trtri( char uplo, char diag, blas_int_t n, float* A, blas_int_t lda,
89             blas_int_t* info );
90 
91 void trtri( char uplo, char diag, blas_int_t n, double* A, blas_int_t lda,
92             blas_int_t* info );
93 
94 void trtri( char uplo, char diag, blas_int_t n, complex<float>* A, blas_int_t lda,
95             blas_int_t* info );
96 
97 void trtri( char uplo, char diag, blas_int_t n, complex<double>* A, blas_int_t lda,
98             blas_int_t* info );
99 //@}
100 //*************************************************************************************************
101 
102 
103 //*************************************************************************************************
104 /*!\brief LAPACK kernel for the inversion of the given dense triangular single precision
105 //        column-major matrix.
106 // \ingroup lapack_inversion
107 //
108 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
109 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
110 // \param n The number of rows/columns of the triangular matrix \f$[0..\infty)\f$.
111 // \param A Pointer to the first element of the single precision column-major matrix.
112 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
113 // \param info Return code of the function call.
114 // \return void
115 //
116 // This function performs the dense matrix inversion based on the LAPACK strtri() function for
117 // lower triangular (\a uplo = \c 'L') or upper triangular (\a uplo = \a 'U') single precision
118 // column-major matrices.
119 //
120 // The \a info argument provides feedback on the success of the function call:
121 //
122 //   - = 0: The inversion finished successfully.
123 //   - < 0: If \a info = -i, the i-th argument had an illegal value.
124 //   - > 0: If \a info = i, element A(i,i) is exactly zero and the inverse could not be computed.
125 //
126 // For more information on the strtri() function, see the LAPACK online documentation browser:
127 //
128 //        http://www.netlib.org/lapack/explore-html/
129 //
130 // \note This function can only be used if a fitting LAPACK library, which supports this function,
131 // is available and linked to the executable. Otherwise a call to this function will result in a
132 // linker error.
133 */
trtri(char uplo,char diag,blas_int_t n,float * A,blas_int_t lda,blas_int_t * info)134 inline void trtri( char uplo, char diag, blas_int_t n, float* A, blas_int_t lda,
135                    blas_int_t* info )
136 {
137 #if defined(INTEL_MKL_VERSION)
138    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
139 #endif
140 
141    strtri_( &uplo, &diag, &n, A, &lda, info
142 #if !defined(INTEL_MKL_VERSION) && !defined(BLAS_H)
143           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
144 #endif
145           );
146 }
147 //*************************************************************************************************
148 
149 
150 //*************************************************************************************************
151 /*!\brief LAPACK kernel for the inversion of the given dense triangular double precision
152 //        column-major matrix.
153 // \ingroup lapack_inversion
154 //
155 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
156 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
157 // \param n The number of rows/columns of the triangular matrix \f$[0..\infty)\f$.
158 // \param A Pointer to the first element of the double precision column-major matrix.
159 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
160 // \param info Return code of the function call.
161 // \return void
162 //
163 // This function performs the dense matrix inversion based on the LAPACK dtrtri() function for
164 // lower triangular (\a uplo = \c 'L') or upper triangular (\a uplo = \a 'U') double precision
165 // column-major matrices.
166 //
167 // The \a info argument provides feedback on the success of the function call:
168 //
169 //   - = 0: The inversion finished successfully.
170 //   - < 0: If \a info = -i, the i-th argument had an illegal value.
171 //   - > 0: If \a info = i, element A(i,i) is exactly zero and the inverse could not be computed.
172 //
173 // For more information on the dtrtri() function, see the LAPACK online documentation browser:
174 //
175 //        http://www.netlib.org/lapack/explore-html/
176 //
177 // \note This function can only be used if a fitting LAPACK library, which supports this function,
178 // is available and linked to the executable. Otherwise a call to this function will result in a
179 // linker error.
180 */
trtri(char uplo,char diag,blas_int_t n,double * A,blas_int_t lda,blas_int_t * info)181 inline void trtri( char uplo, char diag, blas_int_t n, double* A, blas_int_t lda,
182                    blas_int_t* info )
183 {
184 #if defined(INTEL_MKL_VERSION)
185    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
186 #endif
187 
188    dtrtri_( &uplo, &diag, &n, A, &lda, info
189 #if !defined(INTEL_MKL_VERSION) && !defined(BLAS_H)
190           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
191 #endif
192           );
193 }
194 //*************************************************************************************************
195 
196 
197 //*************************************************************************************************
198 /*!\brief LAPACK kernel for the inversion of the given dense triangular single precision complex
199 //        column-major matrix.
200 // \ingroup lapack_inversion
201 //
202 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
203 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
204 // \param n The number of rows/columns of the triangular matrix \f$[0..\infty)\f$.
205 // \param A Pointer to the first element of the single precision complex column-major matrix.
206 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
207 // \param info Return code of the function call.
208 // \return void
209 //
210 // This function performs the dense matrix inversion based on the LAPACK ctrtri() function for
211 // lower triangular (\a uplo = \c 'L') or upper triangular (\a uplo = \a 'U') single precision
212 // complex column-major matrices.
213 //
214 // The \a info argument provides feedback on the success of the function call:
215 //
216 //   - = 0: The inversion finished successfully.
217 //   - < 0: If \a info = -i, the i-th argument had an illegal value.
218 //   - > 0: If \a info = i, element A(i,i) is exactly zero and the inverse could not be computed.
219 //
220 // For more information on the ctrtri() function, see the LAPACK online documentation browser:
221 //
222 //        http://www.netlib.org/lapack/explore-html/
223 //
224 // \note This function can only be used if a fitting LAPACK library, which supports this function,
225 // is available and linked to the executable. Otherwise a call to this function will result in a
226 // linker error.
227 */
trtri(char uplo,char diag,blas_int_t n,complex<float> * A,blas_int_t lda,blas_int_t * info)228 inline void trtri( char uplo, char diag, blas_int_t n, complex<float>* A, blas_int_t lda,
229                    blas_int_t* info )
230 {
231    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
232 
233 #if defined(INTEL_MKL_VERSION)
234    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
235    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex8 ) == sizeof( complex<float> ) );
236    using ET = MKL_Complex8;
237 #else
238    using ET = float;
239 #endif
240 
241    ctrtri_( &uplo, &diag, &n, reinterpret_cast<ET*>( A ), &lda, info
242 #if !defined(INTEL_MKL_VERSION) && !defined(BLAS_H)
243           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
244 #endif
245           );
246 }
247 //*************************************************************************************************
248 
249 
250 //*************************************************************************************************
251 /*!\brief LAPACK kernel for the inversion of the given dense triangular double precision complex
252 //        column-major matrix.
253 // \ingroup lapack_inversion
254 //
255 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
256 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
257 // \param n The number of rows/columns of the triangular matrix \f$[0..\infty)\f$.
258 // \param A Pointer to the first element of the double precision complex column-major matrix.
259 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
260 // \param info Return code of the function call.
261 // \return void
262 //
263 // This function performs the dense matrix inversion based on the LAPACK ztrtri() function for
264 // lower triangular (\a uplo = \c 'L') or upper triangular (\a uplo = \a 'U') double precision
265 // complex column-major matrices.
266 //
267 // The \a info argument provides feedback on the success of the function call:
268 //
269 //   - = 0: The inversion finished successfully.
270 //   - < 0: If \a info = -i, the i-th argument had an illegal value.
271 //   - > 0: If \a info = i, element A(i,i) is exactly zero and the inverse could not be computed.
272 //
273 // For more information on the ztrtri() function, see the LAPACK online documentation browser:
274 //
275 //        http://www.netlib.org/lapack/explore-html/
276 //
277 // \note This function can only be used if a fitting LAPACK library, which supports this function,
278 // is available and linked to the executable. Otherwise a call to this function will result in a
279 // linker error.
280 */
trtri(char uplo,char diag,blas_int_t n,complex<double> * A,blas_int_t lda,blas_int_t * info)281 inline void trtri( char uplo, char diag, blas_int_t n, complex<double>* A, blas_int_t lda,
282                    blas_int_t* info )
283 {
284    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
285 
286 #if defined(INTEL_MKL_VERSION)
287    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
288    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex16 ) == sizeof( complex<double> ) );
289    using ET = MKL_Complex16;
290 #else
291    using ET = double;
292 #endif
293 
294    ztrtri_( &uplo, &diag, &n, reinterpret_cast<ET*>( A ), &lda, info
295 #if !defined(INTEL_MKL_VERSION) && !defined(BLAS_H)
296           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
297 #endif
298           );
299 }
300 //*************************************************************************************************
301 
302 } // namespace blaze
303 
304 #endif
305