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