Blaze  3.6
DVecDVecKronExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECDVECKRONEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECDVECKRONEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <utility>
44 #include <blaze/math/Aliases.h>
50 #include <blaze/math/Exception.h>
56 #include <blaze/math/shims/Reset.h>
61 #include <blaze/util/Assert.h>
63 #include <blaze/util/MaybeUnused.h>
64 #include <blaze/util/mpl/If.h>
65 #include <blaze/util/TypeList.h>
66 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS DVECDVECKRONEXPR
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
84 template< typename VT1 // Type of the left-hand side dense vector
85  , typename VT2 // Type of the right-hand side dense vector
86  , bool TF > // Transpose flag
88  : public VecVecKronExpr< DenseVector< DVecDVecKronExpr<VT1,VT2,TF>, TF > >
89  , private Computation
90 {
91  private:
92  //**Type definitions****************************************************************************
101  //**********************************************************************************************
102 
103  //**Return type evaluation**********************************************************************
105 
110  static constexpr bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
111 
113  using ExprReturnType = decltype( std::declval<RN1>() + std::declval<RN2>() );
114  //**********************************************************************************************
115 
116  public:
117  //**Type definitions****************************************************************************
123 
126 
128  using CompositeType = const ResultType;
129 
131  using LeftOperand = If_t< IsExpression_v<VT1>, const VT1, const VT1& >;
132 
134  using RightOperand = If_t< IsExpression_v<VT2>, const VT2, const VT2& >;
135  //**********************************************************************************************
136 
137  //**Compilation flags***************************************************************************
139  static constexpr bool simdEnabled = false;
140 
142  static constexpr bool smpAssignable = false;
143  //**********************************************************************************************
144 
145  //**Constructor*********************************************************************************
151  explicit inline DVecDVecKronExpr( const VT1& lhs, const VT2& rhs ) noexcept
152  : lhs_( lhs ) // Left-hand side dense vector of the Kronecker product expression
153  , rhs_( rhs ) // Right-hand side dense vector of the Kronecker product expression
154  {}
155  //**********************************************************************************************
156 
157  //**Subscript operator**************************************************************************
163  inline ReturnType operator[]( size_t index ) const {
164  BLAZE_INTERNAL_ASSERT( index < size(), "Invalid vector access index" );
165  return lhs_[index/rhs_.size()] * rhs_[index%rhs_.size()];
166  }
167  //**********************************************************************************************
168 
169  //**At function*********************************************************************************
176  inline ReturnType at( size_t index ) const {
177  if( index >= lhs_.size() ) {
178  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
179  }
180  return (*this)[index];
181  }
182  //**********************************************************************************************
183 
184  //**Size function*******************************************************************************
189  inline size_t size() const noexcept {
190  return lhs_.size() * rhs_.size();
191  }
192  //**********************************************************************************************
193 
194  //**Left operand access*************************************************************************
199  inline LeftOperand leftOperand() const noexcept {
200  return lhs_;
201  }
202  //**********************************************************************************************
203 
204  //**Right operand access************************************************************************
209  inline RightOperand rightOperand() const noexcept {
210  return rhs_;
211  }
212  //**********************************************************************************************
213 
214  //**********************************************************************************************
220  template< typename T >
221  inline bool canAlias( const T* alias ) const noexcept {
222  return ( lhs_.canAlias( alias ) || rhs_.canAlias( alias ) );
223  }
224  //**********************************************************************************************
225 
226  //**********************************************************************************************
232  template< typename T >
233  inline bool isAliased( const T* alias ) const noexcept {
234  return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
235  }
236  //**********************************************************************************************
237 
238  //**********************************************************************************************
243  inline bool isAligned() const noexcept {
244  return rhs_.isAligned();
245  }
246  //**********************************************************************************************
247 
248  //**********************************************************************************************
253  inline bool canSMPAssign() const noexcept {
254  return false;
255  }
256  //**********************************************************************************************
257 
258  private:
259  //**Member variables****************************************************************************
262  //**********************************************************************************************
263 
264  //**Assignment to dense vectors*****************************************************************
276  template< typename VT > // Type of the target dense vector
277  friend inline void assign( DenseVector<VT,TF>& lhs, const DVecDVecKronExpr& rhs )
278  {
280 
281  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
282 
283  if( rhs.size() == 0UL ) {
284  return;
285  }
286 
287  CT1 x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
288  CT2 y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
289 
290  const size_t N( y.size() );
291 
292  for( size_t i=0UL; i<x.size(); ++i ) {
293  if( !isDefault( x[i] ) ) {
294  for( size_t j=0UL; j<N; ++j )
295  (~lhs)[i*N+j] = x[i] * y[j];
296  }
297  else {
298  for( size_t j=0UL; j<N; ++j )
299  reset( (~lhs)[i*N+j] );
300  }
301  }
302  }
304  //**********************************************************************************************
305 
306  //**Assignment to sparse vectors****************************************************************
318  template< typename VT > // Type of the target sparse vector
319  friend inline void assign( SparseVector<VT,TF>& lhs, const DVecDVecKronExpr& rhs )
320  {
322 
326 
327  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
328 
329  const ResultType tmp( serial( rhs ) );
330  assign( ~lhs, tmp );
331  }
333  //**********************************************************************************************
334 
335  //**Addition assignment to dense vectors********************************************************
347  template< typename VT > // Type of the target dense vector
348  friend inline void addAssign( DenseVector<VT,TF>& lhs, const DVecDVecKronExpr& rhs )
349  {
351 
352  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
353 
354  if( rhs.size() == 0UL ) {
355  return;
356  }
357 
358  CT1 x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
359  CT2 y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
360 
361  const size_t N( y.size() );
362 
363  for( size_t i=0UL; i<x.size(); ++i ) {
364  if( !isDefault( x[i] ) ) {
365  for( size_t j=0UL; j<N; ++j )
366  (~lhs)[i*N+j] += x[i] * y[j];
367  }
368  }
369  }
371  //**********************************************************************************************
372 
373  //**Addition assignment to sparse vectors*******************************************************
374  // No special implementation for the addition assignment to sparse vectors.
375  //**********************************************************************************************
376 
377  //**Subtraction assignment to dense vectors*****************************************************
390  template< typename VT > // Type of the target dense vector
391  friend inline void subAssign( DenseVector<VT,TF>& lhs, const DVecDVecKronExpr& rhs )
392  {
394 
395  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
396 
397  if( rhs.size() == 0UL ) {
398  return;
399  }
400 
401  CT1 x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
402  CT2 y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
403 
404  const size_t N( y.size() );
405 
406  for( size_t i=0UL; i<x.size(); ++i ) {
407  if( !isDefault( x[i] ) ) {
408  for( size_t j=0UL; j<N; ++j )
409  (~lhs)[i*N+j] -= x[i] * y[j];
410  }
411  }
412  }
414  //**********************************************************************************************
415 
416  //**Subtraction assignment to sparse vectors****************************************************
417  // No special implementation for the subtraction assignment to sparse vectors.
418  //**********************************************************************************************
419 
420  //**Multiplication assignment to dense vectors**************************************************
433  template< typename VT > // Type of the target dense vector
434  friend inline void multAssign( DenseVector<VT,TF>& lhs, const DVecDVecKronExpr& rhs )
435  {
437 
438  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
439 
440  if( rhs.size() == 0UL ) {
441  return;
442  }
443 
444  CT1 x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
445  CT2 y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
446 
447  const size_t N( y.size() );
448 
449  for( size_t i=0UL; i<x.size(); ++i ) {
450  if( !isDefault( x[i] ) ) {
451  for( size_t j=0UL; j<N; ++j )
452  (~lhs)[i*N+j] *= x[i] * y[j];
453  }
454  else {
455  for( size_t j=0UL; j<N; ++j )
456  reset( (~lhs)[i*N+j] );
457  }
458  }
459  }
461  //**********************************************************************************************
462 
463  //**Multiplication assignment to sparse vectors*************************************************
464  // No special implementation for the multiplication assignment to sparse vectors.
465  //**********************************************************************************************
466 
467  //**Division assignment to dense vectors********************************************************
479  template< typename VT > // Type of the target dense vector
480  friend inline void divAssign( DenseVector<VT,TF>& lhs, const DVecDVecKronExpr& rhs )
481  {
483 
484  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
485 
486  if( rhs.size() == 0UL ) {
487  return;
488  }
489 
490  CT1 x( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense vector operand
491  CT2 y( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense vector operand
492 
493  const size_t N( y.size() );
494 
495  for( size_t i=0UL; i<x.size(); ++i ) {
496  if( !isDefault( x[i] ) ) {
497  for( size_t j=0UL; j<N; ++j )
498  (~lhs)[i*N+j] /= x[i] * y[j];
499  }
500  }
501  }
503  //**********************************************************************************************
504 
505  //**Division assignment to sparse vectors*******************************************************
506  // No special implementation for the division assignment to sparse vectors.
507  //**********************************************************************************************
508 
509  //**Compile time checks*************************************************************************
517  //**********************************************************************************************
518 };
519 //*************************************************************************************************
520 
521 
522 
523 
524 //=================================================================================================
525 //
526 // GLOBAL FUNCTIONS
527 //
528 //=================================================================================================
529 
530 //*************************************************************************************************
551 template< typename VT1 // Type of the left-hand side dense vector
552  , typename VT2 // Type of the right-hand side dense vector
553  , bool TF > // Transpose flag
554 inline decltype(auto)
555  kron( const DenseVector<VT1,TF>& lhs, const DenseVector<VT2,TF>& rhs )
556 {
558 
559  using ReturnType = const DVecDVecKronExpr<VT1,VT2,TF>;
560  return ReturnType( ~lhs, ~rhs );
561 }
562 //*************************************************************************************************
563 
564 } // namespace blaze
565 
566 #endif
Header file for auxiliary alias declarations.
Header file for the alignment flag values.
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DVecDVecKronExpr.h:142
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
Header file for the serial shim.
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecDVecKronExpr.h:243
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Header file for the DenseVector base class.
Header file for the MAYBE_UNUSED function template.
Constraint on the data type.
ResultType_t< VT1 > RT1
Result type of the left-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:93
Header file for the Computation base class.
decltype(std::declval< RN1 >()+std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: DVecDVecKronExpr.h:113
Header file for the reset shim.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecDVecKronExpr.h:163
decltype(auto) kron(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the Kronecker product of two dense matrices ( ).
Definition: DMatDMatKronExpr.h:954
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DVecDVecKronExpr.h:122
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: DVecDVecKronExpr.h:125
ElementType_t< VT2 > ET2
Element type of the right-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:100
RightOperand rhs_
Right-hand side dense vector of the Kronecker product expression.
Definition: DVecDVecKronExpr.h:261
KronTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: DVecDVecKronExpr.h:120
Header file for the IsTemporary type trait class.
Base class for all vector/vector Kronecker expression templates.The VecVecKronExpr class serves as a ...
Definition: VecVecKronExpr.h:67
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DVecDVecKronExpr.h:139
Header file for the If class template.
ReturnType_t< VT1 > RN1
Return type of the left-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:95
typename KronTrait< T1, T2 >::Type KronTrait_t
Auxiliary alias declaration for the KronTrait class template.The KronTrait_t alias declaration provid...
Definition: KronTrait.h:163
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecDVecKronExpr.h:189
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DVecDVecKronExpr.h:121
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecDVecKronExpr.h:128
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
Header file for the VecVecKronExpr base class.
ElementType_t< VT1 > ET1
Element type of the left-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:99
Constraint on the data type.
Header file for the Kron product trait.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecDVecKronExpr.h:233
Constraint on the data type.
Header file for the exception macros of the math module.
Constraint on the data type.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecDVecKronExpr.h:221
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecDVecKronExpr.h:253
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense vector operand.
Definition: DVecDVecKronExpr.h:199
LeftOperand lhs_
Left-hand side dense vector of the Kronecker product expression.
Definition: DVecDVecKronExpr.h:260
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
Header file for the Unique class template.
ReturnType_t< VT2 > RN2
Return type of the right-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:96
CompositeType_t< VT1 > CT1
Composite type of the left-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:97
CompositeType_t< VT2 > CT2
Composite type of the right-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:98
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
Header file for all forward declarations for expression class templates.
Header file for the isDefault shim.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
ResultType_t< VT2 > RT2
Result type of the right-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:94
RightOperand rightOperand() const noexcept
Returns the right-hand side dense vector operand.
Definition: DVecDVecKronExpr.h:209
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type,...
Definition: DenseVector.h:61
If_t< IsExpression_v< VT2 >, const VT2, const VT2 & > RightOperand
Composite type of the right-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:134
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_VECVECKRONEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid vector/vector ...
Definition: VecVecKronExpr.h:102
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
Expression object for dense vector-dense vector Kronecker product.The DVecDVecKronExpr class represen...
Definition: DVecDVecKronExpr.h:87
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: DVecDVecKronExpr.h:110
DVecDVecKronExpr(const VT1 &lhs, const VT2 &rhs) noexcept
Constructor for the DVecDVecKronExpr class.
Definition: DVecDVecKronExpr.h:151
If_t< IsExpression_v< VT1 >, const VT1, const VT1 & > LeftOperand
Composite type of the left-hand side dense vector expression.
Definition: DVecDVecKronExpr.h:131
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:63
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
Definition: Assert.h:101
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecDVecKronExpr.h:176