1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/trtrs.h
4 //  \brief Header file for the CLAPACK trtrs 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_TRTRS_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_TRTRS_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 strtrs_( char* uplo, char* trans, char* diag, blaze::blas_int_t* n, blaze::blas_int_t* nrhs,
61               float* A, blaze::blas_int_t* lda, float* B, blaze::blas_int_t* ldb,
62               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo,
63               blaze::fortran_charlen_t ntrans, blaze::fortran_charlen_t ndiag );
64 void dtrtrs_( char* uplo, char* trans, char* diag, blaze::blas_int_t* n, blaze::blas_int_t* nrhs,
65               double* A, blaze::blas_int_t* lda, double* B, blaze::blas_int_t* ldb,
66               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo,
67               blaze::fortran_charlen_t ntrans, blaze::fortran_charlen_t ndiag );
68 void ctrtrs_( char* uplo, char* trans, char* diag, blaze::blas_int_t* n, blaze::blas_int_t* nrhs,
69               float* A, blaze::blas_int_t* lda, float* B, blaze::blas_int_t* ldb,
70               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo,
71               blaze::fortran_charlen_t ntrans, blaze::fortran_charlen_t ndiag );
72 void ztrtrs_( char* uplo, char* trans, char* diag, blaze::blas_int_t* n, blaze::blas_int_t* nrhs,
73               double* A, blaze::blas_int_t* lda, double* B, blaze::blas_int_t* ldb,
74               blaze::blas_int_t* info, blaze::fortran_charlen_t nuplo,
75               blaze::fortran_charlen_t ntrans, blaze::fortran_charlen_t ndiag );
76 
77 }
78 #endif
79 /*! \endcond */
80 //*************************************************************************************************
81 
82 
83 
84 
85 namespace blaze {
86 
87 //=================================================================================================
88 //
89 //  LAPACK TRIANGULAR SUBSTITUTION FUNCTIONS (TRTRS)
90 //
91 //=================================================================================================
92 
93 //*************************************************************************************************
94 /*!\name LAPACK triangular substitution functions (trtrs) */
95 //@{
96 void trtrs( char uplo, char trans, char diag, blas_int_t n, blas_int_t nrhs,
97             const float* A, blas_int_t lda, float* B, blas_int_t ldb,
98             blas_int_t* info );
99 
100 void trtrs( char uplo, char trans, char diag, blas_int_t n, blas_int_t nrhs,
101             const double* A, blas_int_t lda, double* B, blas_int_t ldb,
102             blas_int_t* info );
103 
104 void trtrs( char uplo, char trans, char diag, blas_int_t n, blas_int_t nrhs,
105             const complex<float>* A, blas_int_t lda, complex<float>* B,
106             blas_int_t ldb, blas_int_t* info );
107 
108 void trtrs( char uplo, char trans, char diag, blas_int_t n, blas_int_t nrhs,
109             const complex<double>* A, blas_int_t lda, complex<double>* B,
110             blas_int_t ldb, blas_int_t* info );
111 //@}
112 //*************************************************************************************************
113 
114 
115 //*************************************************************************************************
116 /*!\brief LAPACK kernel for the substitution step of solving a triangular single precision linear
117 //        system of equations (\f$ A*X=B \f$).
118 // \ingroup lapack_substitution
119 //
120 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
121 // \param trans \c 'N' for \f$ A*X=B \f$, \c 'T' for \f$ A^T*X=B \f$, and \c C for \f$ A^H*X=B \f$.
122 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
123 // \param n The number of rows/columns of the column-major matrix \f$[0..\infty)\f$.
124 // \param nrhs The number of right-hand side vectors \f$[0..\infty)\f$.
125 // \param A Pointer to the first element of the single precision column-major square matrix.
126 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
127 // \param B Pointer to the first element of the column-major matrix.
128 // \param ldb The total number of elements between two columns of matrix \a B \f$[0..\infty)\f$.
129 // \param info Return code of the function call.
130 // \return void
131 //
132 // This function uses the LAPACK strtrs() function to perform the substitution step to compute
133 // the solution to the general system of linear equations \f$ A*X=B \f$, \f$ A^{T}*X=B \f$, or
134 // \f$ A^{H}*X=B \f$, where \a A is a \a n-by-\a n matrix and \a X and \a B are column-major
135 // \a n-by-\a nrhs matrices. The \a trans argument specifies the form of the linear system of
136 // equations:
137 //
138 //   - 'N': \f$ A*X=B \f$ (no transpose)
139 //   - 'T': \f$ A^{T}*X=B \f$ (transpose)
140 //   - 'C': \f$ A^{H}*X=B \f$ (conjugate transpose)
141 //
142 // The \a info argument provides feedback on the success of the function call:
143 //
144 //   - = 0: The function finished successfully.
145 //   - < 0: If info = -i, the i-th argument had an illegal value.
146 //
147 // For more information on the strtrs() 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 */
trtrs(char uplo,char trans,char diag,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)155 inline void trtrs( char uplo, char trans, char diag, blas_int_t n, blas_int_t nrhs,
156                    const float* A, blas_int_t lda, float* B, blas_int_t ldb,
157                    blas_int_t* info )
158 {
159 #if defined(INTEL_MKL_VERSION)
160    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
161 #endif
162 
163    strtrs_( &uplo, &trans, &diag, &n, &nrhs, const_cast<float*>( A ), &lda, B, &ldb, info
164 #if !defined(INTEL_MKL_VERSION)
165           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
166 #endif
167           );
168 }
169 //*************************************************************************************************
170 
171 
172 //*************************************************************************************************
173 /*!\brief LAPACK kernel for the substitution step of solving a triangular double precision linear
174 //        system of equations (\f$ A*X=B \f$).
175 // \ingroup lapack_substitution
176 //
177 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
178 // \param trans \c 'N' for \f$ A*X=B \f$, \c 'T' for \f$ A^T*X=B \f$, and \c C for \f$ A^H*X=B \f$.
179 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
180 // \param n The number of rows/columns of the column-major matrix \f$[0..\infty)\f$.
181 // \param nrhs The number of right-hand side vectors \f$[0..\infty)\f$.
182 // \param A Pointer to the first element of the double precision column-major square matrix.
183 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
184 // \param B Pointer to the first element of the column-major matrix.
185 // \param ldb The total number of elements between two columns of matrix \a B \f$[0..\infty)\f$.
186 // \param info Return code of the function call.
187 // \return void
188 //
189 // This function uses the LAPACK dtrtrs() function to perform the substitution step to compute
190 // the solution to the general system of linear equations \f$ A*X=B \f$, \f$ A^{T}*X=B \f$, or
191 // \f$ A^{H}*X=B \f$, where \a A is a \a n-by-\a n matrix and \a X and \a B are column-major
192 // \a n-by-\a nrhs matrices. The \a trans argument specifies the form of the linear system of
193 // equations:
194 //
195 //   - 'N': \f$ A*X=B \f$ (no transpose)
196 //   - 'T': \f$ A^{T}*X=B \f$ (transpose)
197 //   - 'C': \f$ A^{H}*X=B \f$ (conjugate transpose)
198 //
199 // The \a info argument provides feedback on the success of the function call:
200 //
201 //   - = 0: The function finished successfully.
202 //   - < 0: If info = -i, the i-th argument had an illegal value.
203 //
204 // For more information on the dtrtrs() function, see the LAPACK online documentation browser:
205 //
206 //        http://www.netlib.org/lapack/explore-html/
207 //
208 // \note This function can only be used if a fitting LAPACK library, which supports this function,
209 // is available and linked to the executable. Otherwise a call to this function will result in a
210 // linker error.
211 */
trtrs(char uplo,char trans,char diag,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)212 inline void trtrs( char uplo, char trans, char diag, blas_int_t n, blas_int_t nrhs,
213                    const double* A, blas_int_t lda, double* B, blas_int_t ldb,
214                    blas_int_t* info )
215 {
216 #if defined(INTEL_MKL_VERSION)
217    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
218 #endif
219 
220    dtrtrs_( &uplo, &trans, &diag, &n, &nrhs, const_cast<double*>( A ), &lda, B, &ldb, info
221 #if !defined(INTEL_MKL_VERSION)
222           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
223 #endif
224           );
225 }
226 //*************************************************************************************************
227 
228 
229 //*************************************************************************************************
230 /*!\brief LAPACK kernel for the substitution step of solving a triangular single precision complex
231 //        linear system of equations (\f$ A*X=B \f$).
232 // \ingroup lapack_substitution
233 //
234 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
235 // \param trans \c 'N' for \f$ A*X=B \f$, \c 'T' for \f$ A^T*X=B \f$, and \c C for \f$ A^H*X=B \f$.
236 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
237 // \param n The number of rows/columns of the column-major matrix \f$[0..\infty)\f$.
238 // \param nrhs The number of right-hand side vectors \f$[0..\infty)\f$.
239 // \param A Pointer to the first element of the single precision complex column-major square matrix.
240 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
241 // \param B Pointer to the first element of the column-major matrix.
242 // \param ldb The total number of elements between two columns of matrix \a B \f$[0..\infty)\f$.
243 // \param info Return code of the function call.
244 // \return void
245 //
246 // This function uses the LAPACK ctrtrs() function to perform the substitution step to compute
247 // the solution to the general system of linear equations \f$ A*X=B \f$, \f$ A^{T}*X=B \f$, or
248 // \f$ A^{H}*X=B \f$, where \a A is a \a n-by-\a n matrix and \a X and \a B are column-major
249 // \a n-by-\a nrhs matrices. The \a trans argument specifies the form of the linear system of
250 // equations:
251 //
252 //   - 'N': \f$ A*X=B \f$ (no transpose)
253 //   - 'T': \f$ A^{T}*X=B \f$ (transpose)
254 //   - 'C': \f$ A^{H}*X=B \f$ (conjugate transpose)
255 //
256 // The \a info argument provides feedback on the success of the function call:
257 //
258 //   - = 0: The function finished successfully.
259 //   - < 0: If info = -i, the i-th argument had an illegal value.
260 //
261 // For more information on the ctrtrs() function, see the LAPACK online documentation browser:
262 //
263 //        http://www.netlib.org/lapack/explore-html/
264 //
265 // \note This function can only be used if a fitting LAPACK library, which supports this function,
266 // is available and linked to the executable. Otherwise a call to this function will result in a
267 // linker error.
268 */
trtrs(char uplo,char trans,char diag,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)269 inline void trtrs( char uplo, char trans, char diag, blas_int_t n, blas_int_t nrhs,
270                    const complex<float>* A, blas_int_t lda, complex<float>* B,
271                    blas_int_t ldb, blas_int_t* info )
272 {
273    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
274 
275 #if defined(INTEL_MKL_VERSION)
276    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
277    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex8 ) == sizeof( complex<float> ) );
278    using ET = MKL_Complex8;
279 #else
280    using ET = float;
281 #endif
282 
283    ctrtrs_( &uplo, &trans, &diag, &n, &nrhs, const_cast<ET*>( reinterpret_cast<const ET*>( A ) ),
284             &lda, reinterpret_cast<ET*>( B ), &ldb, info
285 #if !defined(INTEL_MKL_VERSION)
286           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
287 #endif
288           );
289 }
290 //*************************************************************************************************
291 
292 
293 //*************************************************************************************************
294 /*!\brief LAPACK kernel for the substitution step of solving a triangular double precision complex
295 //        linear system of equations (\f$ A*X=B \f$).
296 // \ingroup lapack_substitution
297 //
298 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
299 // \param trans \c 'N' for \f$ A*X=B \f$, \c 'T' for \f$ A^T*X=B \f$, and \c C for \f$ A^H*X=B \f$.
300 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
301 // \param n The number of rows/columns of the column-major matrix \f$[0..\infty)\f$.
302 // \param nrhs The number of right-hand side vectors \f$[0..\infty)\f$.
303 // \param A Pointer to the first element of the double precision complex column-major square matrix.
304 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
305 // \param B Pointer to the first element of the column-major matrix.
306 // \param ldb The total number of elements between two columns of matrix \a B \f$[0..\infty)\f$.
307 // \param info Return code of the function call.
308 // \return void
309 //
310 // This function uses the LAPACK ztrtrs() function to perform the substitution step to compute
311 // the solution to the general system of linear equations \f$ A*X=B \f$, \f$ A^{T}*X=B \f$, or
312 // \f$ A^{H}*X=B \f$, where \a A is a \a n-by-\a n matrix and \a X and \a B are column-major
313 // \a n-by-\a nrhs matrices. The \a trans argument specifies the form of the linear system of
314 // equations:
315 //
316 //   - 'N': \f$ A*X=B \f$ (no transpose)
317 //   - 'T': \f$ A^{T}*X=B \f$ (transpose)
318 //   - 'C': \f$ A^{H}*X=B \f$ (conjugate transpose)
319 //
320 // The \a info argument provides feedback on the success of the function call:
321 //
322 //   - = 0: The function finished successfully.
323 //   - < 0: If info = -i, the i-th argument had an illegal value.
324 //
325 // For more information on the ztrtrs() function, see the LAPACK online documentation browser:
326 //
327 //        http://www.netlib.org/lapack/explore-html/
328 //
329 // \note This function can only be used if a fitting LAPACK library, which supports this function,
330 // is available and linked to the executable. Otherwise a call to this function will result in a
331 // linker error.
332 */
trtrs(char uplo,char trans,char diag,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)333 inline void trtrs( char uplo, char trans, char diag, blas_int_t n, blas_int_t nrhs,
334                    const complex<double>* A, blas_int_t lda, complex<double>* B,
335                    blas_int_t ldb, blas_int_t* info )
336 {
337    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
338 
339 #if defined(INTEL_MKL_VERSION)
340    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
341    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex16 ) == sizeof( complex<double> ) );
342    using ET = MKL_Complex16;
343 #else
344    using ET = double;
345 #endif
346 
347    ztrtrs_( &uplo, &trans, &diag, &n, &nrhs, const_cast<ET*>( reinterpret_cast<const ET*>( A ) ),
348             &lda, reinterpret_cast<ET*>( B ), &ldb, info
349 #if !defined(INTEL_MKL_VERSION)
350           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
351 #endif
352           );
353 }
354 //*************************************************************************************************
355 
356 } // namespace blaze
357 
358 #endif
359