1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/potrs.h
4 //  \brief Header file for the CLAPACK potrs 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_POTRS_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_POTRS_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 spotrs_( char* uplo, blaze::blas_int_t* n, blaze::blas_int_t* nrhs, float* A,
61               blaze::blas_int_t* lda, float* B, blaze::blas_int_t* ldb,
62               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo );
63 void dpotrs_( char* uplo, blaze::blas_int_t* n, blaze::blas_int_t* nrhs, double* A,
64               blaze::blas_int_t* lda, double* B, blaze::blas_int_t* ldb,
65               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo );
66 void cpotrs_( char* uplo, blaze::blas_int_t* n, blaze::blas_int_t* nrhs, float* A,
67               blaze::blas_int_t* lda, float* B, blaze::blas_int_t* ldb,
68               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo );
69 void zpotrs_( char* uplo, blaze::blas_int_t* n, blaze::blas_int_t* nrhs, double* A,
70               blaze::blas_int_t* lda, double* B, blaze::blas_int_t* ldb,
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 LLH-BASED SUBSTITUTION FUNCTIONS (POTRS)
86 //
87 //=================================================================================================
88 
89 //*************************************************************************************************
90 /*!\name LAPACK LLH-based substitution functions (potrs) */
91 //@{
92 void potrs( char uplo, blas_int_t n, blas_int_t nrhs, const float* A, blas_int_t lda,
93             float* B, blas_int_t ldb, blas_int_t* info );
94 
95 void potrs( char uplo, blas_int_t n, blas_int_t nrhs, const double* A, blas_int_t lda,
96             double* B, blas_int_t ldb, blas_int_t* info );
97 
98 void potrs( char uplo, blas_int_t n, blas_int_t nrhs, const complex<float>* A, blas_int_t lda,
99             complex<float>* B, blas_int_t ldb, blas_int_t* info );
100 
101 void potrs( char uplo, blas_int_t n, blas_int_t nrhs, const complex<double>* A, blas_int_t lda,
102             complex<double>* B, blas_int_t ldb, blas_int_t* info );
103 //@}
104 //*************************************************************************************************
105 
106 
107 //*************************************************************************************************
108 /*!\brief LAPACK kernel for the substitution step of solving a positive definite single precision
109 //        linear system of equations (\f$ A*X=B \f$).
110 // \ingroup lapack_substitution
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 column-major matrix \f$[0..\infty)\f$.
114 // \param nrhs The number of right-hand side vectors \f$[0..\infty)\f$.
115 // \param A Pointer to the first element of the single precision column-major square matrix.
116 // \param lda The total number of elements between two columns of matrix \a A \f$[0..\infty)\f$.
117 // \param B Pointer to the first element of the single precision column-major matrix.
118 // \param ldb The total number of elements between two columns of matrix \a B \f$[0..\infty)\f$.
119 // \param info Return code of the function call.
120 // \return void
121 //
122 // This function uses the LAPACK spotrs() function to perform the substitution step to compute
123 // the solution to the positive definite system of linear equations \f$ A*X=B \f$, where \a A is
124 // a \a n-by-\a n matrix that has already been factorized by the spotrf() function and \a X and
125 // \a B are column-major \a n-by-\a nrhs matrices.
126 //
127 // The \a info argument provides feedback on the success of the function call:
128 //
129 //   - = 0: The function finished successfully.
130 //   - < 0: If info = -i, the i-th argument had an illegal value.
131 //
132 // For more information on the spotrs() function, see the LAPACK online documentation browser:
133 //
134 //        http://www.netlib.org/lapack/explore-html/
135 //
136 // \note This function can only be used if a fitting LAPACK library, which supports this function,
137 // is available and linked to the executable. Otherwise a call to this function will result in a
138 // linker error.
139 */
potrs(char uplo,blas_int_t n,blas_int_t nrhs,const float * A,blas_int_t lda,float * B,blas_int_t ldb,blas_int_t * info)140 inline void potrs( char uplo, blas_int_t n, blas_int_t nrhs, const float* A, blas_int_t lda,
141                    float* B, blas_int_t ldb, blas_int_t* info )
142 {
143 #if defined(INTEL_MKL_VERSION)
144    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
145 #endif
146 
147    spotrs_( &uplo, &n, &nrhs, const_cast<float*>( A ), &lda, B, &ldb, info
148 #if !defined(INTEL_MKL_VERSION)
149           , blaze::fortran_charlen_t(1)
150 #endif
151           );
152 }
153 //*************************************************************************************************
154 
155 
156 //*************************************************************************************************
157 /*!\brief LAPACK kernel for the substitution step of solving a positive definite double precision
158 //        linear system of equations (\f$ A*X=B \f$).
159 // \ingroup lapack_substitution
160 //
161 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
162 // \param n The number of rows/columns of the column-major matrix \f$[0..\infty)\f$.
163 // \param nrhs The number of right-hand side vectors \f$[0..\infty)\f$.
164 // \param A Pointer to the first element of the double precision column-major square matrix.
165 // \param lda The total number of elements between two columns of matrix \a A \f$[0..\infty)\f$.
166 // \param B Pointer to the first element of the double precision column-major matrix.
167 // \param ldb The total number of elements between two columns of matrix \a B \f$[0..\infty)\f$.
168 // \param info Return code of the function call.
169 // \return void
170 //
171 // This function uses the LAPACK dpotrs() function to perform the substitution step to compute
172 // the solution to the positive definite system of linear equations \f$ A*X=B \f$, where \a A is
173 // a \a n-by-\a n matrix that has already been factorized by the dpotrf() function and \a X and
174 // \a B are column-major \a n-by-\a nrhs matrices.
175 //
176 // The \a info argument provides feedback on the success of the function call:
177 //
178 //   - = 0: The function finished successfully.
179 //   - < 0: If info = -i, the i-th argument had an illegal value.
180 //
181 // For more information on the dpotrs() function, see the LAPACK online documentation browser:
182 //
183 //        http://www.netlib.org/lapack/explore-html/
184 //
185 // \note This function can only be used if a fitting LAPACK library, which supports this function,
186 // is available and linked to the executable. Otherwise a call to this function will result in a
187 // linker error.
188 */
potrs(char uplo,blas_int_t n,blas_int_t nrhs,const double * A,blas_int_t lda,double * B,blas_int_t ldb,blas_int_t * info)189 inline void potrs( char uplo, blas_int_t n, blas_int_t nrhs, const double* A, blas_int_t lda,
190                    double* B, blas_int_t ldb, 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    dpotrs_( &uplo, &n, &nrhs, const_cast<double*>( A ), &lda, B, &ldb, info
197 #if !defined(INTEL_MKL_VERSION)
198           , blaze::fortran_charlen_t(1)
199 #endif
200           );
201 }
202 //*************************************************************************************************
203 
204 
205 //*************************************************************************************************
206 /*!\brief LAPACK kernel for the substitution step of solving a positive definite single precision
207 //        complex linear system of equations (\f$ A*X=B \f$).
208 // \ingroup lapack_substitution
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 column-major matrix \f$[0..\infty)\f$.
212 // \param nrhs The number of right-hand side vectors \f$[0..\infty)\f$.
213 // \param A Pointer to the first element of the single precision complex column-major square matrix.
214 // \param lda The total number of elements between two columns of matrix \a A \f$[0..\infty)\f$.
215 // \param B Pointer to the first element of the single precision complex column-major matrix.
216 // \param ldb The total number of elements between two columns of matrix \a B \f$[0..\infty)\f$.
217 // \param info Return code of the function call.
218 // \return void
219 //
220 // This function uses the LAPACK cpotrs() function to perform the substitution step to compute
221 // the solution to the positive definite system of linear equations \f$ A*X=B \f$, where \a A is
222 // a \a n-by-\a n matrix that has already been factorized by the cpotrf() function and \a X and
223 // \a B are column-major \a n-by-\a nrhs matrices.
224 //
225 // The \a info argument provides feedback on the success of the function call:
226 //
227 //   - = 0: The function finished successfully.
228 //   - < 0: If info = -i, the i-th argument had an illegal value.
229 //
230 // For more information on the cpotrs() function, see the LAPACK online documentation browser:
231 //
232 //        http://www.netlib.org/lapack/explore-html/
233 //
234 // \note This function can only be used if a fitting LAPACK library, which supports this function,
235 // is available and linked to the executable. Otherwise a call to this function will result in a
236 // linker error.
237 */
potrs(char uplo,blas_int_t n,blas_int_t nrhs,const complex<float> * A,blas_int_t lda,complex<float> * B,blas_int_t ldb,blas_int_t * info)238 inline void potrs( char uplo, blas_int_t n, blas_int_t nrhs, const complex<float>* A, blas_int_t lda,
239                    complex<float>* B, blas_int_t ldb, blas_int_t* info )
240 {
241    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
242 
243 #if defined(INTEL_MKL_VERSION)
244    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
245    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex8 ) == sizeof( complex<float> ) );
246    using ET = MKL_Complex8;
247 #else
248    using ET = float;
249 #endif
250 
251    cpotrs_( &uplo, &n, &nrhs, const_cast<ET*>( reinterpret_cast<const ET*>( A ) ),
252             &lda, reinterpret_cast<ET*>( B ), &ldb, info
253 #if !defined(INTEL_MKL_VERSION)
254           , blaze::fortran_charlen_t(1)
255 #endif
256           );
257 }
258 //*************************************************************************************************
259 
260 
261 //*************************************************************************************************
262 /*!\brief LAPACK kernel for the substitution step of solving a positive definite double precision
263 //        complex linear system of equations (\f$ A*X=B \f$).
264 // \ingroup lapack_substitution
265 //
266 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
267 // \param n The number of rows/columns of the column-major matrix \f$[0..\infty)\f$.
268 // \param nrhs The number of right-hand side vectors \f$[0..\infty)\f$.
269 // \param A Pointer to the first element of the double precision complex column-major square matrix.
270 // \param lda The total number of elements between two columns of matrix \a A \f$[0..\infty)\f$.
271 // \param B Pointer to the first element of the double precision complex column-major matrix.
272 // \param ldb The total number of elements between two columns of matrix \a B \f$[0..\infty)\f$.
273 // \param info Return code of the function call.
274 // \return void
275 //
276 // This function uses the LAPACK zpotrs() function to perform the substitution step to compute
277 // the solution to the positive definite system of linear equations \f$ A*X=B \f$, where \a A is
278 // a \a n-by-\a n matrix that has already been factorized by the zpotrf() function and \a X and
279 // \a B are column-major \a n-by-\a nrhs matrices.
280 //
281 // The \a info argument provides feedback on the success of the function call:
282 //
283 //   - = 0: The function finished successfully.
284 //   - < 0: If info = -i, the i-th argument had an illegal value.
285 //
286 // For more information on the zpotrs() function, see the LAPACK online documentation browser:
287 //
288 //        http://www.netlib.org/lapack/explore-html/
289 //
290 // \note This function can only be used if a fitting LAPACK library, which supports this function,
291 // is available and linked to the executable. Otherwise a call to this function will result in a
292 // linker error.
293 */
potrs(char uplo,blas_int_t n,blas_int_t nrhs,const complex<double> * A,blas_int_t lda,complex<double> * B,blas_int_t ldb,blas_int_t * info)294 inline void potrs( char uplo, blas_int_t n, blas_int_t nrhs, const complex<double>* A, blas_int_t lda,
295                    complex<double>* B, blas_int_t ldb, blas_int_t* info )
296 {
297    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
298 
299 #if defined(INTEL_MKL_VERSION)
300    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
301    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex16 ) == sizeof( complex<double> ) );
302    using ET = MKL_Complex16;
303 #else
304    using ET = double;
305 #endif
306 
307    zpotrs_( &uplo, &n, &nrhs, const_cast<ET*>( reinterpret_cast<const ET*>( A ) ),
308             &lda, reinterpret_cast<ET*>( B ), &ldb, info
309 #if !defined(INTEL_MKL_VERSION)
310           , blaze::fortran_charlen_t(1)
311 #endif
312           );
313 }
314 //*************************************************************************************************
315 
316 } // namespace blaze
317 
318 #endif
319