1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/ungl2.h
4 //  \brief Header file for the CLAPACK ungl2 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_UNGL2_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_UNGL2_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 
47 
48 //=================================================================================================
49 //
50 //  LAPACK FORWARD DECLARATIONS
51 //
52 //=================================================================================================
53 
54 //*************************************************************************************************
55 /*! \cond BLAZE_INTERNAL */
56 #if !defined(INTEL_MKL_VERSION)
57 extern "C" {
58 
59 void cungl2_( blaze::blas_int_t* m, blaze::blas_int_t* n, blaze::blas_int_t* k, float* A,
60               blaze::blas_int_t* lda, float* tau, float* work, blaze::blas_int_t* info );
61 void zungl2_( blaze::blas_int_t* m, blaze::blas_int_t* n, blaze::blas_int_t* k, double* A,
62               blaze::blas_int_t* lda, double* tau, double* work, blaze::blas_int_t* info );
63 
64 }
65 #endif
66 /*! \endcond */
67 //*************************************************************************************************
68 
69 
70 
71 
72 namespace blaze {
73 
74 //=================================================================================================
75 //
76 //  LAPACK FUNCTIONS TO RECONSTRUCT Q FROM A LQ DECOMPOSITION (UNGL2)
77 //
78 //=================================================================================================
79 
80 //*************************************************************************************************
81 /*!\name LAPACK functions to reconstruct Q from a LQ decomposition (ungl2) */
82 //@{
83 void ungl2( blas_int_t m, blas_int_t n, blas_int_t k, complex<float>* A, blas_int_t lda,
84             const complex<float>* tau, complex<float>* work, blas_int_t* info );
85 
86 void ungl2( blas_int_t m, blas_int_t n, blas_int_t k, complex<double>* A, blas_int_t lda,
87             const complex<double>* tau, complex<double>* work, blas_int_t* info );
88 //@}
89 //*************************************************************************************************
90 
91 
92 //*************************************************************************************************
93 /*!\brief LAPACK kernel for the reconstruction of the orthogonal matrix Q from a LQ decomposition.
94 // \ingroup lapack_decomposition
95 //
96 // \param m The number of rows of the given matrix \f$[0..n)\f$.
97 // \param n The number of columns of the given matrix \f$[0..\infty)\f$.
98 // \param k The number of elementary reflectors, whose product defines the matrix \f$[0..m)\f$.
99 // \param A Pointer to the first element of the single precision complex column-major matrix.
100 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
101 // \param tau Array for the scalar factors of the elementary reflectors; size >= min( \a m, \a n ).
102 // \param work Auxiliary array; size == \a m.
103 // \param info Return code of the function call.
104 // \return void
105 //
106 // This function generates all or part of the orthogonal matrix Q from a LQ decomposition based on
107 // the LAPACK cungl2() function for single precision complex column-major matrices that have already
108 // been factorized by the cgelqf() function. The \a info argument provides feedback on the success
109 // of the function call:
110 //
111 //   - = 0: The decomposition finished successfully.
112 //   - < 0: The i-th argument had an illegal value.
113 //
114 // For more information on the cungl2() function, see the LAPACK online documentation browser:
115 //
116 //        http://www.netlib.org/lapack/explore-html/
117 //
118 // \note This function can only be used if a fitting LAPACK library, which supports this function,
119 // is available and linked to the executable. Otherwise a call to this function will result in a
120 // linker error.
121 */
ungl2(blas_int_t m,blas_int_t n,blas_int_t k,complex<float> * A,blas_int_t lda,const complex<float> * tau,complex<float> * work,blas_int_t * info)122 inline void ungl2( blas_int_t m, blas_int_t n, blas_int_t k, complex<float>* A, blas_int_t lda,
123                    const complex<float>* tau, complex<float>* work, blas_int_t* info )
124 {
125    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
126 
127 #if defined(INTEL_MKL_VERSION)
128    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
129    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex8 ) == sizeof( complex<float> ) );
130    using ET = MKL_Complex8;
131 #else
132    using ET = float;
133 #endif
134 
135    cungl2_( &m, &n, &k, reinterpret_cast<ET*>( A ), &lda,
136             const_cast<ET*>( reinterpret_cast<const ET*>( tau ) ),
137             reinterpret_cast<ET*>( work ), info );
138 }
139 //*************************************************************************************************
140 
141 
142 //*************************************************************************************************
143 /*!\brief LAPACK kernel for the reconstruction of the orthogonal matrix Q from a LQ decomposition.
144 // \ingroup lapack_decomposition
145 //
146 // \param m The number of rows of the given matrix \f$[0..n)\f$.
147 // \param n The number of columns of the given matrix \f$[0..\infty)\f$.
148 // \param k The number of elementary reflectors, whose product defines the matrix \f$[0..m)\f$.
149 // \param A Pointer to the first element of the double precision complex column-major matrix.
150 // \param lda The total number of elements between two columns of the matrix \f$[0..\infty)\f$.
151 // \param tau Array for the scalar factors of the elementary reflectors; size >= min( \a m, \a n ).
152 // \param work Auxiliary array; size == \a m.
153 // \param info Return code of the function call.
154 // \return void
155 //
156 // This function generates all or part of the orthogonal matrix Q from a LQ decomposition based on
157 // the LAPACK zungl2() function for double precision complex column-major matrices that have already
158 // been factorized by the zgelqf() function. The \a info argument provides feedback on the success
159 // of the function call:
160 //
161 //   - = 0: The decomposition finished successfully.
162 //   - < 0: The i-th argument had an illegal value.
163 //
164 // For more information on the zungl2() function, see the LAPACK online documentation browser:
165 //
166 //        http://www.netlib.org/lapack/explore-html/
167 //
168 // \note This function can only be used if a fitting LAPACK library, which supports this function,
169 // is available and linked to the executable. Otherwise a call to this function will result in a
170 // linker error.
171 */
ungl2(blas_int_t m,blas_int_t n,blas_int_t k,complex<double> * A,blas_int_t lda,const complex<double> * tau,complex<double> * work,blas_int_t * info)172 inline void ungl2( blas_int_t m, blas_int_t n, blas_int_t k, complex<double>* A, blas_int_t lda,
173                    const complex<double>* tau, complex<double>* work, blas_int_t* info )
174 {
175    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
176 
177 #if defined(INTEL_MKL_VERSION)
178    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
179    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex16 ) == sizeof( complex<double> ) );
180    using ET = MKL_Complex16;
181 #else
182    using ET = double;
183 #endif
184 
185    zungl2_( &m, &n, &k, reinterpret_cast<ET*>( A ), &lda,
186             const_cast<ET*>( reinterpret_cast<const ET*>( tau ) ),
187             reinterpret_cast<ET*>( work ), info );
188 }
189 //*************************************************************************************************
190 
191 } // namespace blaze
192 
193 #endif
194