1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/trsv.h
4 //  \brief Header file for the CLAPACK trsv 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_TRSV_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_TRSV_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(BLAS_H)
58 extern "C" {
59 
60 void strsv_( char* uplo, char* trans, char* diag, blaze::blas_int_t* n, float* A,
61              blaze::blas_int_t* lda, float* x, blaze::blas_int_t* incX,
62              blaze::fortran_charlen_t nuplo, blaze::fortran_charlen_t ntrans,
63              blaze::fortran_charlen_t ndiag );
64 void dtrsv_( char* uplo, char* trans, char* diag, blaze::blas_int_t* n, double* A,
65              blaze::blas_int_t* lda, double* x, blaze::blas_int_t* incX,
66              blaze::fortran_charlen_t nuplo, blaze::fortran_charlen_t ntrans,
67              blaze::fortran_charlen_t ndiag );
68 void ctrsv_( char* uplo, char* trans, char* diag, blaze::blas_int_t* n, float* A,
69              blaze::blas_int_t* lda, float* x, blaze::blas_int_t* incX,
70              blaze::fortran_charlen_t nuplo, blaze::fortran_charlen_t ntrans,
71              blaze::fortran_charlen_t ndiag );
72 void ztrsv_( char* uplo, char* trans, char* diag, blaze::blas_int_t* n, double* A,
73              blaze::blas_int_t* lda, double* x, blaze::blas_int_t* incX,
74              blaze::fortran_charlen_t nuplo, blaze::fortran_charlen_t ntrans,
75              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 LINEAR SYSTEM FUNCTIONS (TRSV)
90 //
91 //=================================================================================================
92 
93 //*************************************************************************************************
94 /*!\name LAPACK triangular linear system functions (trsv) */
95 //@{
96 void trsv( char uplo, char trans, char diag, blas_int_t n, const float* A,
97            blas_int_t lda, float* x, blas_int_t incX );
98 
99 void trsv( char uplo, char trans, char diag, blas_int_t n, const double* A,
100            blas_int_t lda, double* x, blas_int_t incX );
101 
102 void trsv( char uplo, char trans, char diag, blas_int_t n, const complex<float>* A,
103            blas_int_t lda, complex<float>* x, blas_int_t incX );
104 
105 void trsv( char uplo, char trans, char diag, blas_int_t n, const complex<double>* A,
106            blas_int_t lda, complex<double>* x, blas_int_t incX );
107 //@}
108 //*************************************************************************************************
109 
110 
111 //*************************************************************************************************
112 /*!\brief LAPACK kernel for solving a triangular single precision linear system of equations
113 //        (\f$ A*X=B \f$).
114 // \ingroup lapack_solver
115 //
116 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
117 // \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$.
118 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
119 // \param n The number of rows/columns of the column-major triangular matrix \f$[0..\infty)\f$.
120 // \param A Pointer to the first element of the single precision column-major square matrix.
121 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
122 // \param x Pointer to the first element of vector \a x.
123 // \param incX The stride within vector \a x.
124 // \return void
125 //
126 // This function uses the LAPACK strsv() function to compute the solution to the triangular system
127 // of linear equations \f$ A*x=b \f$, where \a A is a \a n-by-\a n triangular matrix and \a x and
128 // \a b are n-dimensional vectors. The \a trans argument specifies the form of the linear system
129 // of equations:
130 //
131 //   - 'N': \f$ A*x=b \f$ (no transpose)
132 //   - 'T': \f$ A^{T}*x=b \f$ (transpose)
133 //   - 'C': \f$ A^{H}*x=b \f$ (conjugate transpose)
134 //
135 // For more information on the strsv() function, see the LAPACK online documentation browser:
136 //
137 //        http://www.netlib.org/lapack/explore-html/
138 //
139 // \note This function can only be used if a fitting LAPACK library, which supports this function,
140 // is available and linked to the executable. Otherwise a call to this function will result in a
141 // linker error.
142 //
143 // \note The function does not perform any test for singularity or near-singularity. Such tests
144 // must be performed prior to calling this function!
145 */
trsv(char uplo,char trans,char diag,blas_int_t n,const float * A,blas_int_t lda,float * x,blas_int_t incX)146 inline void trsv( char uplo, char trans, char diag, blas_int_t n, const float* A,
147                   blas_int_t lda, float* x, blas_int_t incX )
148 {
149    strsv_( &uplo, &trans, &diag, &n, const_cast<float*>( A ), &lda, x, &incX
150 #if !defined(BLAS_H)
151          , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
152 #endif
153          );
154 }
155 //*************************************************************************************************
156 
157 
158 //*************************************************************************************************
159 /*!\brief LAPACK kernel for solving a triangular double precision linear system of equations
160 //        (\f$ A*x=b \f$).
161 // \ingroup lapack_solver
162 //
163 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
164 // \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$.
165 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
166 // \param n The number of rows/columns of the column-major triangular matrix \f$[0..\infty)\f$.
167 // \param A Pointer to the first element of the double precision column-major square matrix.
168 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
169 // \param x Pointer to the first element of vector \a x.
170 // \param incX The stride within vector \a x.
171 // \return void
172 //
173 // This function uses the LAPACK dtrsv() function to compute the solution to the triangular system
174 // of linear equations \f$ A*x=b \f$, where \a A is a \a n-by-\a n triangular matrix and \a x and
175 // \a b are n-dimensional vectors. The \a trans argument specifies the form of the linear system
176 // of equations:
177 //
178 //   - 'N': \f$ A*x=b \f$ (no transpose)
179 //   - 'T': \f$ A^{T}*x=b \f$ (transpose)
180 //   - 'C': \f$ A^{H}*x=b \f$ (conjugate transpose)
181 //
182 // For more information on the dtrsv() 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 //
190 // \note The function does not perform any test for singularity or near-singularity. Such tests
191 // must be performed prior to calling this function!
192 */
trsv(char uplo,char trans,char diag,blas_int_t n,const double * A,blas_int_t lda,double * x,blas_int_t incX)193 inline void trsv( char uplo, char trans, char diag, blas_int_t n, const double* A,
194                   blas_int_t lda, double* x, blas_int_t incX )
195 {
196    dtrsv_( &uplo, &trans, &diag, &n, const_cast<double*>( A ), &lda, x, &incX
197 #if !defined(BLAS_H)
198          , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
199 #endif
200          );
201 }
202 //*************************************************************************************************
203 
204 
205 //*************************************************************************************************
206 /*!\brief LAPACK kernel for solving a triangular single precision complex linear system of
207 //        equations (\f$ A*x=b \f$).
208 // \ingroup lapack_solver
209 //
210 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
211 // \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$.
212 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
213 // \param n The number of rows/columns of the column-major triangular matrix \f$[0..\infty)\f$.
214 // \param A Pointer to the first element of the single precision complex column-major square matrix.
215 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
216 // \param x Pointer to the first element of vector \a x.
217 // \param incX The stride within vector \a x.
218 // \return void
219 //
220 // This function uses the LAPACK ctrsv() function to compute the solution to the triangular system
221 // of linear equations \f$ A*x=b \f$, where \a A is a \a n-by-\a n triangular matrix and \a x and
222 // \a b are n-dimensional vectors. The \a trans argument specifies the form of the linear system
223 // of equations:
224 //
225 //   - 'N': \f$ A*x=b \f$ (no transpose)
226 //   - 'T': \f$ A^{T}*x=b \f$ (transpose)
227 //   - 'C': \f$ A^{H}*x=b \f$ (conjugate transpose)
228 //
229 // For more information on the ctrsv() function, see the LAPACK online documentation browser:
230 //
231 //        http://www.netlib.org/lapack/explore-html/
232 //
233 // \note This function can only be used if a fitting LAPACK library, which supports this function,
234 // is available and linked to the executable. Otherwise a call to this function will result in a
235 // linker error.
236 //
237 // \note The function does not perform any test for singularity or near-singularity. Such tests
238 // must be performed prior to calling this function!
239 */
trsv(char uplo,char trans,char diag,blas_int_t n,const complex<float> * A,blas_int_t lda,complex<float> * x,blas_int_t incX)240 inline void trsv( char uplo, char trans, char diag, blas_int_t n, const complex<float>* A,
241                   blas_int_t lda, complex<float>* x, blas_int_t incX )
242 {
243    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
244 
245    ctrsv_( &uplo, &trans, &diag, &n, const_cast<float*>( reinterpret_cast<const float*>( A ) ),
246            &lda, reinterpret_cast<float*>( x ), &incX
247 #if !defined(BLAS_H)
248          , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
249 #endif
250          );
251 }
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
256 /*!\brief LAPACK kernel for solving a triangular double precision complex linear system of
257 //        equations (\f$ A*x=b \f$).
258 // \ingroup lapack_solver
259 //
260 // \param uplo \c 'L' in case of a lower matrix, \c 'U' in case of an upper matrix.
261 // \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$.
262 // \param diag \c 'U' in case of a unitriangular matrix, \c 'N' otherwise.
263 // \param n The number of rows/columns of the column-major triangular matrix \f$[0..\infty)\f$.
264 // \param A Pointer to the first element of the double precision complex column-major square matrix.
265 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
266 // \param x Pointer to the first element of vector \a x.
267 // \param incX The stride within vector \a x.
268 // \return void
269 //
270 // This function uses the LAPACK ztrsv() function to compute the solution to the triangular system
271 // of linear equations \f$ A*x=b \f$, where \a A is a \a n-by-\a n triangular matrix and \a x and
272 // \a b are n-dimensional vectors. The \a trans argument specifies the form of the linear system
273 // of equations:
274 //
275 //   - 'N': \f$ A*x=b \f$ (no transpose)
276 //   - 'T': \f$ A^{T}*x=b \f$ (transpose)
277 //   - 'C': \f$ A^{H}*x=b \f$ (conjugate transpose)
278 //
279 // For more information on the ztrsv() function, see the LAPACK online documentation browser:
280 //
281 //        http://www.netlib.org/lapack/explore-html/
282 //
283 // \note This function can only be used if a fitting LAPACK library, which supports this function,
284 // is available and linked to the executable. Otherwise a call to this function will result in a
285 // linker error.
286 //
287 // \note The function does not perform any test for singularity or near-singularity. Such tests
288 // must be performed prior to calling this function!
289 */
trsv(char uplo,char trans,char diag,blas_int_t n,const complex<double> * A,blas_int_t lda,complex<double> * x,blas_int_t incX)290 inline void trsv( char uplo, char trans, char diag, blas_int_t n, const complex<double>* A,
291                   blas_int_t lda, complex<double>* x, blas_int_t incX )
292 {
293    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
294 
295    ztrsv_( &uplo, &trans, &diag, &n, const_cast<double*>( reinterpret_cast<const double*>( A ) ),
296            &lda, reinterpret_cast<double*>( x ), &incX
297 #if !defined(BLAS_H)
298          , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
299 #endif
300          );
301 }
302 //*************************************************************************************************
303 
304 } // namespace blaze
305 
306 #endif
307