gemv.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_BLAS_GEMV_H_
36 #define _BLAZE_MATH_BLAS_GEMV_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
50 #include <blaze/system/BLAS.h>
51 #include <blaze/system/Inline.h>
52 #include <blaze/util/Assert.h>
53 #include <blaze/util/Complex.h>
54 #include <blaze/util/NumericCast.h>
56 
57 
58 namespace blaze {
59 
60 //=================================================================================================
61 //
62 // BLAS WRAPPER FUNCTIONS (GEMV)
63 //
64 //=================================================================================================
65 
66 //*************************************************************************************************
69 #if BLAZE_BLAS_MODE
70 
71 BLAZE_ALWAYS_INLINE void gemv( CBLAS_ORDER layout, CBLAS_TRANSPOSE transA, int m, int n,
72  float alpha, const float* A, int lda, const float* x, int incX,
73  float beta, float* y, int incY );
74 
75 BLAZE_ALWAYS_INLINE void gemv( CBLAS_ORDER layout, CBLAS_TRANSPOSE transA, int m, int n,
76  double alpha, const double* A, int lda, const double* x, int incX,
77  double beta, double* y, int incY );
78 
79 BLAZE_ALWAYS_INLINE void gemv( CBLAS_ORDER layout, CBLAS_TRANSPOSE transA, int m, int n,
80  complex<float> alpha, const complex<float>* A, int lda,
81  const complex<float>* x, int incX, complex<float> beta,
82  complex<float>* y, int incY );
83 
84 BLAZE_ALWAYS_INLINE void gemv( CBLAS_ORDER layout, CBLAS_TRANSPOSE transA, int m, int n,
85  complex<double> alpha, const complex<double>* A, int lda,
86  const complex<double>* x, int incX, complex<double> beta,
87  complex<double>* y, int incY );
88 
89 template< typename VT1, typename MT1, bool SO, typename VT2, typename ST >
90 BLAZE_ALWAYS_INLINE void gemv( DenseVector<VT1,false>& y, const DenseMatrix<MT1,SO>& A,
91  const DenseVector<VT2,false>& x, ST alpha, ST beta );
92 
93 template< typename VT1, typename VT2, typename MT1, bool SO, typename ST >
94 BLAZE_ALWAYS_INLINE void gemv( DenseVector<VT1,true>& y, const DenseVector<VT2,true>& x,
95  const DenseMatrix<MT1,SO>& A, ST alpha, ST beta );
96 
97 #endif
98 
99 //*************************************************************************************************
100 
101 
102 //*************************************************************************************************
103 #if BLAZE_BLAS_MODE
104 
125 BLAZE_ALWAYS_INLINE void gemv( CBLAS_ORDER order, CBLAS_TRANSPOSE transA, int m, int n,
126  float alpha, const float* A, int lda, const float* x, int incX,
127  float beta, float* y, int incY )
128 {
129  cblas_sgemv( order, transA, m, n, alpha, A, lda, x, incX, beta, y, incY );
130 }
131 #endif
132 //*************************************************************************************************
133 
134 
135 //*************************************************************************************************
136 #if BLAZE_BLAS_MODE
137 
158 BLAZE_ALWAYS_INLINE void gemv( CBLAS_ORDER order, CBLAS_TRANSPOSE transA, int m, int n,
159  double alpha, const double* A, int lda, const double* x, int incX,
160  double beta, double* y, int incY )
161 {
162  cblas_dgemv( order, transA, m, n, alpha, A, lda, x, incX, beta, y, incY );
163 }
164 #endif
165 //*************************************************************************************************
166 
167 
168 //*************************************************************************************************
169 #if BLAZE_BLAS_MODE
170 
191 BLAZE_ALWAYS_INLINE void gemv( CBLAS_ORDER order, CBLAS_TRANSPOSE transA, int m, int n,
192  complex<float> alpha, const complex<float>* A, int lda,
193  const complex<float>* x, int incX, complex<float> beta,
194  complex<float>* y, int incY )
195 {
196  BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
197 
198  cblas_cgemv( order, transA, m, n, reinterpret_cast<const float*>( &alpha ),
199  reinterpret_cast<const float*>( A ), lda, reinterpret_cast<const float*>( x ),
200  incX, reinterpret_cast<const float*>( &beta ), reinterpret_cast<float*>( y ), incY );
201 }
202 #endif
203 //*************************************************************************************************
204 
205 
206 //*************************************************************************************************
207 #if BLAZE_BLAS_MODE
208 
229 BLAZE_ALWAYS_INLINE void gemv( CBLAS_ORDER order, CBLAS_TRANSPOSE transA, int m, int n,
230  complex<double> alpha, const complex<double>* A, int lda,
231  const complex<double>* x, int incX, complex<double> beta,
232  complex<double>* y, int incY )
233 {
234  BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
235 
236  cblas_zgemv( order, transA, m, n, reinterpret_cast<const double*>( &alpha ),
237  reinterpret_cast<const double*>( A ), lda, reinterpret_cast<const double*>( x ),
238  incX, reinterpret_cast<const double*>( &beta ), reinterpret_cast<double*>( y ), incY );
239 }
240 #endif
241 //*************************************************************************************************
242 
243 
244 //*************************************************************************************************
245 #if BLAZE_BLAS_MODE
246 
262 template< typename VT1 // Type of the left-hand side target vector
263  , typename MT1 // Type of the left-hand side matrix operand
264  , bool SO // Storage order of the left-hand side matrix operand
265  , typename VT2 // Type of the right-hand side vector operand
266  , typename ST > // Type of the scalar factors
267 BLAZE_ALWAYS_INLINE void gemv( DenseVector<VT1,false>& y, const DenseMatrix<MT1,SO>& A,
268  const DenseVector<VT2,false>& x, ST alpha, ST beta )
269 {
273 
277 
281 
282  const int m ( numeric_cast<int>( (~A).rows() ) );
283  const int n ( numeric_cast<int>( (~A).columns() ) );
284  const int lda( numeric_cast<int>( (~A).spacing() ) );
285 
286  gemv( ( SO )?( CblasColMajor ):( CblasRowMajor ), CblasNoTrans, m, n, alpha,
287  (~A).data(), lda, (~x).data(), 1, beta, (~y).data(), 1 );
288 }
289 #endif
290 //*************************************************************************************************
291 
292 
293 //*************************************************************************************************
294 #if BLAZE_BLAS_MODE
295 
311 template< typename VT1 // Type of the left-hand side target vector
312  , typename VT2 // Type of the left-hand side vector operand
313  , typename MT1 // Type of the right-hand side matrix operand
314  , bool SO // Storage order of the right-hand side matrix operand
315  , typename ST > // Type of the scalar factors
316 BLAZE_ALWAYS_INLINE void gemv( DenseVector<VT1,true>& y, const DenseVector<VT2,true>& x,
317  const DenseMatrix<MT1,SO>& A, ST alpha, ST beta )
318 {
322 
326 
330 
331  const int m ( numeric_cast<int>( (~A).rows() ) );
332  const int n ( numeric_cast<int>( (~A).columns() ) );
333  const int lda( numeric_cast<int>( (~A).spacing() ) );
334 
335  gemv( ( SO )?( CblasColMajor ):( CblasRowMajor ), CblasTrans, m, n, alpha,
336  (~A).data(), lda, (~x).data(), 1, beta, (~y).data(), 1 );
337 }
338 #endif
339 //*************************************************************************************************
340 
341 } // namespace blaze
342 
343 #endif
Constraint on the data type.
Header file for auxiliary alias declarations.
#define BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS(T)
Constraint on the data type.In case the given data type T does not provide low-level data access to m...
Definition: MutableDataAccess.h:61
#define BLAZE_CONSTRAINT_MUST_HAVE_CONST_DATA_ACCESS(T)
Constraint on the data type.In case the given data type T does not provide low-level data access to c...
Definition: ConstDataAccess.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:81
Header file for the DenseVector base class.
Cast operators for numeric types.
BLAZE_ALWAYS_INLINE size_t spacing(const DenseMatrix< MT, SO > &dm) noexcept
Returns the spacing between the beginning of two rows/columns.
Definition: DenseMatrix.h:110
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Compile time assertion.
Header file for the DenseMatrix base class.
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:340
Constraint on the data type.
System settings for the BLAS mode.
Header file for run time assertion macros.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE(T)
Constraint on the data type.In case the given data type T is not a BLAS compatible data type (i...
Definition: BLASCompatible.h:61
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:324
Header file for the complex data type.
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:112
System settings for the inline keywords.