1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/sytrf.h
4 //  \brief Header file for the CLAPACK sytrf 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_SYTRF_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_SYTRF_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 ssytrf_( 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* lwork,
62               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo );
63 void dsytrf_( 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* lwork,
65               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo );
66 void csytrf_( 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* lwork,
68               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo );
69 void zsytrf_( 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* lwork,
71               blaze::blas_int_t* info, 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 DECOMPOSITION FUNCTIONS (SYTRF)
86 //
87 //=================================================================================================
88 
89 //*************************************************************************************************
90 /*!\name LAPACK LDLT decomposition functions (sytrf) */
91 //@{
92 void sytrf( char uplo, blas_int_t n, float* A, blas_int_t lda, blas_int_t* ipiv,
93             float* work, blas_int_t lwork, blas_int_t* info );
94 
95 void sytrf( char uplo, blas_int_t n, double* A, blas_int_t lda, blas_int_t* ipiv,
96             double* work, blas_int_t lwork, blas_int_t* info );
97 
98 void sytrf( char uplo, blas_int_t n, complex<float>* A, blas_int_t lda, blas_int_t* ipiv,
99             complex<float>* work, blas_int_t lwork, blas_int_t* info );
100 
101 void sytrf( char uplo, blas_int_t n, complex<double>* A, blas_int_t lda, blas_int_t* ipiv,
102             complex<double>* work, blas_int_t lwork, blas_int_t* info );
103 //@}
104 //*************************************************************************************************
105 
106 
107 //*************************************************************************************************
108 /*!\brief LAPACK kernel for the decomposition of the given dense symmetric indefinite single
109 //        precision column-major matrix.
110 // \ingroup lapack_decomposition
111 //
112 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
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; size >= max( 1, \a lwork ).
118 // \param lwork The dimension of the array \a work; size >= max( 1, \a n ).
119 // \param info Return code of the function call.
120 // \return void
121 //
122 // This function performs the dense matrix decomposition of a symmetric indefinite single precision
123 // column-major matrix based on the LAPACK ssytrf() function, which uses the Bunch-Kaufman diagonal
124 // pivoting method. The decomposition has the form
125 
126                       \f[ A = U D U^{T} \texttt{ (if uplo = 'U'), or }
127                           A = L D L^{T} \texttt{ (if uplo = 'L'), } \f]
128 
129 // where \c U (or \c L) is a product of permutation and unit upper (lower) triangular matrices,
130 // and \c D is symmetric and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. The resulting
131 // decomposition is stored within \a A: In case \a uplo is set to \c 'L' the result is stored in
132 // the lower part of the matrix and the upper part remains untouched, in case \a uplo is set to
133 // \c 'U' the result is stored in the upper part and the lower part remains untouched.
134 //
135 // The \a info argument provides feedback on the success of the function call:
136 //
137 //   - = 0: The decomposition finished successfully.
138 //   - < 0: If info = -i, the i-th argument had an illegal value.
139 //   - > 0: If info = i, the decomposition has been completed, but D(i,i) is exactly zero.
140 //
141 // If the function exits successfully (i.e. \a info = 0) then the first element of the \a work
142 // array returns the optimal \a lwork. For optimal performance \a lwork >= \a n*NB, where NB
143 // is the optimal blocksize returned by the LAPACK function ilaenv(). If \a lwork = -1 then a
144 // workspace query is assumed. The function only calculates the optimal size of the \a work
145 // array and returns this value as the first entry of the \a work array.
146 //
147 // For more information on the ssytrf() function, see the LAPACK online documentation browser:
148 //
149 //        http://www.netlib.org/lapack/explore-html/
150 //
151 // \note This function can only be used if a fitting LAPACK library, which supports this function,
152 // is available and linked to the executable. Otherwise a call to this function will result in a
153 // linker error.
154 */
sytrf(char uplo,blas_int_t n,float * A,blas_int_t lda,blas_int_t * ipiv,float * work,blas_int_t lwork,blas_int_t * info)155 inline void sytrf( char uplo, blas_int_t n, float* A, blas_int_t lda, blas_int_t* ipiv,
156                    float* work, blas_int_t lwork, blas_int_t* info )
157 {
158 #if defined(INTEL_MKL_VERSION)
159    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
160 #endif
161 
162    ssytrf_( &uplo, &n, A, &lda, ipiv, work, &lwork, info
163 #if !defined(INTEL_MKL_VERSION)
164           , blaze::fortran_charlen_t(1)
165 #endif
166           );
167 }
168 //*************************************************************************************************
169 
170 
171 //*************************************************************************************************
172 /*!\brief LAPACK kernel for the decomposition of the given dense symmetric indefinite double
173 //        precision column-major matrix.
174 // \ingroup lapack_decomposition
175 //
176 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
177 // \param n The number of rows/columns of the symmetric matrix \f$[0..\infty)\f$.
178 // \param A Pointer to the first element of the double precision column-major matrix.
179 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
180 // \param ipiv Auxiliary array of size \a n for the pivot indices.
181 // \param work Auxiliary array; size >= max( 1, \a lwork ).
182 // \param lwork The dimension of the array \a work; size >= max( 1, \a n ).
183 // \param info Return code of the function call.
184 // \return void
185 //
186 // This function performs the dense matrix decomposition of a symmetric indefinite double precision
187 // column-major matrix based on the LAPACK dsytrf() function, which uses the Bunch-Kaufman diagonal
188 // pivoting method. The decomposition has the form
189 
190                       \f[ A = U D U^{T} \texttt{ (if uplo = 'U'), or }
191                           A = L D L^{T} \texttt{ (if uplo = 'L'), } \f]
192 
193 // where \c U (or \c L) is a product of permutation and unit upper (lower) triangular matrices,
194 // and \c D is symmetric and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. The resulting
195 // decomposition is stored within \a A: In case \a uplo is set to \c 'L' the result is stored in
196 // the lower part of the matrix and the upper part remains untouched, in case \a uplo is set to
197 // \c 'U' the result is stored in the upper part and the lower part remains untouched.
198 //
199 // The \a info argument provides feedback on the success of the function call:
200 //
201 //   - = 0: The decomposition finished successfully.
202 //   - < 0: If info = -i, the i-th argument had an illegal value.
203 //   - > 0: If info = i, the decomposition has been completed, but D(i,i) is exactly zero.
204 //
205 // If the function exits successfully (i.e. \a info = 0) then the first element of the \a work
206 // array returns the optimal \a lwork. For optimal performance \a lwork >= \a n*NB, where NB
207 // is the optimal blocksize returned by the LAPACK function ilaenv(). If \a lwork = -1 then a
208 // workspace query is assumed. The function only calculates the optimal size of the \a work
209 // array and returns this value as the first entry of the \a work array.
210 //
211 // For more information on the dsytrf() function, see the LAPACK online documentation browser:
212 //
213 //        http://www.netlib.org/lapack/explore-html/
214 //
215 // \note This function can only be used if a fitting LAPACK library, which supports this function,
216 // is available and linked to the executable. Otherwise a call to this function will result in a
217 // linker error.
218 */
sytrf(char uplo,blas_int_t n,double * A,blas_int_t lda,blas_int_t * ipiv,double * work,blas_int_t lwork,blas_int_t * info)219 inline void sytrf( char uplo, blas_int_t n, double* A, blas_int_t lda, blas_int_t* ipiv,
220                    double* work, blas_int_t lwork, blas_int_t* info )
221 {
222 #if defined(INTEL_MKL_VERSION)
223    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
224 #endif
225 
226    dsytrf_( &uplo, &n, A, &lda, ipiv, work, &lwork, info
227 #if !defined(INTEL_MKL_VERSION)
228           , blaze::fortran_charlen_t(1)
229 #endif
230           );
231 }
232 //*************************************************************************************************
233 
234 
235 //*************************************************************************************************
236 /*!\brief LAPACK kernel for the decomposition of the given dense symmetric indefinite single
237 //        precision complex column-major matrix.
238 // \ingroup lapack_decomposition
239 //
240 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
241 // \param n The number of rows/columns of the symmetric matrix \f$[0..\infty)\f$.
242 // \param A Pointer to the first element of the single precision complex column-major matrix.
243 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
244 // \param ipiv Auxiliary array of size \a n for the pivot indices.
245 // \param work Auxiliary array; size >= max( 1, \a lwork ).
246 // \param lwork The dimension of the array \a work; size >= max( 1, \a n ).
247 // \param info Return code of the function call.
248 // \return void
249 //
250 // This function performs the dense matrix decomposition of a symmetric indefinite single precision
251 // column-major matrix based on the LAPACK csytrf() function, which uses the Bunch-Kaufman diagonal
252 // pivoting method. The decomposition has the form
253 
254                       \f[ A = U D U^{T} \texttt{ (if uplo = 'U'), or }
255                           A = L D L^{T} \texttt{ (if uplo = 'L'), } \f]
256 
257 // where \c U (or \c L) is a product of permutation and unit upper (lower) triangular matrices,
258 // and \c D is symmetric and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. The resulting
259 // decomposition is stored within \a A: In case \a uplo is set to \c 'L' the result is stored in
260 // the lower part of the matrix and the upper part remains untouched, in case \a uplo is set to
261 // \c 'U' the result is stored in the upper part and the lower part remains untouched.
262 //
263 // The \a info argument provides feedback on the success of the function call:
264 //
265 //   - = 0: The decomposition finished successfully.
266 //   - < 0: If info = -i, the i-th argument had an illegal value.
267 //   - > 0: If info = i, the decomposition has been completed, but D(i,i) is exactly zero.
268 //
269 // If the function exits successfully (i.e. \a info = 0) then the first element of the \a work
270 // array returns the optimal \a lwork. For optimal performance \a lwork >= \a n*NB, where NB
271 // is the optimal blocksize returned by the LAPACK function ilaenv(). If \a lwork = -1 then a
272 // workspace query is assumed. The function only calculates the optimal size of the \a work
273 // array and returns this value as the first entry of the \a work array.
274 //
275 // For more information on the csytrf() function, see the LAPACK online documentation browser:
276 //
277 //        http://www.netlib.org/lapack/explore-html/
278 //
279 // \note This function can only be used if a fitting LAPACK library, which supports this function,
280 // is available and linked to the executable. Otherwise a call to this function will result in a
281 // linker error.
282 */
sytrf(char uplo,blas_int_t n,complex<float> * A,blas_int_t lda,blas_int_t * ipiv,complex<float> * work,blas_int_t lwork,blas_int_t * info)283 inline void sytrf( char uplo, blas_int_t n, complex<float>* A, blas_int_t lda, blas_int_t* ipiv,
284                    complex<float>* work, blas_int_t lwork, blas_int_t* info )
285 {
286    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
287 
288 #if defined(INTEL_MKL_VERSION)
289    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
290    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex8 ) == sizeof( complex<float> ) );
291    using ET = MKL_Complex8;
292 #else
293    using ET = float;
294 #endif
295 
296    csytrf_( &uplo, &n, reinterpret_cast<ET*>( A ), &lda, ipiv,
297             reinterpret_cast<ET*>( work ), &lwork, info
298 #if !defined(INTEL_MKL_VERSION)
299           , blaze::fortran_charlen_t(1)
300 #endif
301           );
302 }
303 //*************************************************************************************************
304 
305 
306 //*************************************************************************************************
307 /*!\brief LAPACK kernel for the decomposition of the given dense symmetric indefinite double
308 //        precision complex column-major matrix.
309 // \ingroup lapack_decomposition
310 //
311 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
312 // \param n The number of rows/columns of the symmetric matrix \f$[0..\infty)\f$.
313 // \param A Pointer to the first element of the double precision complex column-major matrix.
314 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
315 // \param ipiv Auxiliary array of size \a n for the pivot indices.
316 // \param work Auxiliary array; size >= max( 1, \a lwork ).
317 // \param lwork The dimension of the array \a work; size >= max( 1, \a n ).
318 // \param info Return code of the function call.
319 // \return void
320 //
321 // This function performs the dense matrix decomposition of a symmetric indefinite double precision
322 // column-major matrix based on the LAPACK zsytrf() function, which uses the Bunch-Kaufman diagonal
323 // pivoting method. The decomposition has the form
324 
325                       \f[ A = U D U^{T} \texttt{ (if uplo = 'U'), or }
326                           A = L D L^{T} \texttt{ (if uplo = 'L'), } \f]
327 
328 // where \c U (or \c L) is a product of permutation and unit upper (lower) triangular matrices,
329 // and \c D is symmetric and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. The resulting
330 // decomposition is stored within \a A: In case \a uplo is set to \c 'L' the result is stored in
331 // the lower part of the matrix and the upper part remains untouched, in case \a uplo is set to
332 // \c 'U' the result is stored in the upper part and the lower part remains untouched.
333 //
334 // The \a info argument provides feedback on the success of the function call:
335 //
336 //   - = 0: The decomposition finished successfully.
337 //   - < 0: If info = -i, the i-th argument had an illegal value.
338 //   - > 0: If info = i, the decomposition has been completed, but D(i,i) is exactly zero.
339 //
340 // If the function exits successfully (i.e. \a info = 0) then the first element of the \a work
341 // array returns the optimal \a lwork. For optimal performance \a lwork >= \a n*NB, where NB
342 // is the optimal blocksize returned by the LAPACK function ilaenv(). If \a lwork = -1 then a
343 // workspace query is assumed. The function only calculates the optimal size of the \a work
344 // array and returns this value as the first entry of the \a work array.
345 //
346 // For more information on the zsytrf() function, see the LAPACK online documentation browser:
347 //
348 //        http://www.netlib.org/lapack/explore-html/
349 //
350 // \note This function can only be used if a fitting LAPACK library, which supports this function,
351 // is available and linked to the executable. Otherwise a call to this function will result in a
352 // linker error.
353 */
sytrf(char uplo,blas_int_t n,complex<double> * A,blas_int_t lda,blas_int_t * ipiv,complex<double> * work,blas_int_t lwork,blas_int_t * info)354 inline void sytrf( char uplo, blas_int_t n, complex<double>* A, blas_int_t lda, blas_int_t* ipiv,
355                    complex<double>* work, blas_int_t lwork, blas_int_t* info )
356 {
357    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
358 
359 #if defined(INTEL_MKL_VERSION)
360    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
361    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex16 ) == sizeof( complex<double> ) );
362    using ET = MKL_Complex16;
363 #else
364    using ET = double;
365 #endif
366 
367    zsytrf_( &uplo, &n, reinterpret_cast<ET*>( A ), &lda, ipiv,
368             reinterpret_cast<ET*>( work ), &lwork, info
369 #if !defined(INTEL_MKL_VERSION)
370           , blaze::fortran_charlen_t(1)
371 #endif
372           );
373 }
374 //*************************************************************************************************
375 
376 } // namespace blaze
377 
378 #endif
379