SUNphi  1.0
MulAdd.hpp
Go to the documentation of this file.
1 #ifndef _MUL_ADD_HPP
2 #define _MUL_ADD_HPP
3 
4 /// \file MulAdd.hpp
5 ///
6 /// \brief Defines a class which take the sum of a \c SmET with the product of two others
7 ///
8 /// For the moment this is just used to provide a testcase to write the generic Nnary
9 
10 #include <smet/Reference.hpp>
11 #include <smet/NnarySmET.hpp>
12 #include <tens/TensKind.hpp>
13 #include <tens/TensClass.hpp>
14 
15 namespace SUNphi
16 {
17  // Base type to qualify as MulAdder
18  DEFINE_BASE_TYPE(MulAdder);
19 
20  /// Class to add a \c SmET with the prodcut of two others: \c a+b*c
21  template <typename..._Refs> // Reference types
22  class MulAdder :
23  public BaseMulAdder, // Inherit from \c BaseMulAdder to detect in expression
24  public NnarySmET<MulAdder<_Refs...>>, // Inherit from \c NnarySmET
25  public ConstrainAreSmETs<_Refs...> // Constrain all \c Refs to be \c SmET
26  {
27  public:
28 
30 
31  /// Position of the elements
32  enum Pos_t{FACT1,
33  FACT2,
34  ADDEND};
35 
36  /// Representative function of the multiply-sum operation
37  template <typename Fact1, // Type of the first factor
38  typename Fact2, // Type of the second factor
39  typename Addend> // Type of the third factor
40  static DECLAUTO representativeFunction(Fact1&& fact1, ///< First factor
41  Fact2&& fact2, ///< Second factor
42  Addend&& addend) ///< Third factor
43  {
44  return fact1*fact2+addend;
45  }
46 
48 
49  // Attributes
52 
53  /// TensorKind of the result
54  ///
55  /// \todo fixit
56  PROVIDE_TK(typename RemRef<Ref<ADDEND>>::Tk);
57 
59 
61 
63 
65 
67 
69 
71 };
72 
73  // Check that a test MulAdder is a NnarySmET
74  namespace CheckMulAdderIsNnarySmet
75  {
76  /// Tensor comp for test
77  using MyTc=
78  TensComp<double,1>;
79 
80  /// Tensor kind to be tested
81  using MyTk=
82  TensKind<MyTc>;
83 
84  /// Tensor to be tested
85  using MyT=
86  Tens<MyTk,double>;
87 
88  STATIC_ASSERT_IS_NNARY_SMET(MulAdder<MyT,MyT,MyT>);
89  }
90 
91  // Build MulAdder from mulAdd
92  SIMPLE_NNARY_SMET_BUILDER(mulAdd,MulAdder);
93 
94  // /// Implement smet1+smet2
95  // template <typename T1, // Type of the first expression
96  // typename T2, // Type of the second expression
97  // SFINAE_ON_TEMPLATE_ARG(isSmET<T1> and isSmET<T2>)>
98  // DECLAUTO operator+(T1&& smet1, ///< First addend
99  // T2&& smet2) ///< Second addend
100  // {
101  // return add(forw<T1>(smet1),forw<T2>(smet2));
102  // }
103 }
104 
105 #endif
#define PROVIDE_NNARY_GET_MERGED_COMPS_VIEW_ACCORDING_TO_REPRESENTATIVE_FUNCTION
Uses the representativeFunction to provide a merged view.
Definition: NnarySmET.hpp:365
#define EVAL_THROUGH_REPRESENTATIVE_FUNCTION_PASSING_COMPS_BY_NAME
Provides an evaluator through a representative function.
Definition: NnarySmET.hpp:105
#define PROVIDE_POS_OF_RES_TCS_IN_REFS
Provide the position of result Tk TensComp in each input.
Definition: NnarySmET.hpp:206
#define PROVIDE_TK(...)
Provides the Tk member.
Definition: BaseSmET.hpp:94
#define PROVIDE_MERGEABLE_COMPS_ACCORDING_TO_REFS_AND_EXTRA
Provide MergeableComps delimiter according to references and extra.
Definition: NnarySmET.hpp:324
#define NO_EXTRA_MERGE_DELIMS
Add an empty ExtraDelims.
Definition: NnarySmET.hpp:319
#define PROVIDE_SIMPLE_NNARY_COMP_SIZE
Definition: NnarySmET.hpp:151
#define FORWARD_IS_ALIASING_TO_REFS
Definition: NnarySmET.hpp:420
#define PROVIDE_NNARY_SMET_SIMPLE_CREATOR(NNARY_SMET)
Defines a simple creator taking n references.
Definition: NnarySmET.hpp:383
#define STATIC_ASSERT_IS_NNARY_SMET(...)
Defines the check for a Nnary SmET.
Definition: NnarySmET.hpp:394
#define NOT_STORING
Set the SmET to not-storing.
Definition: BaseSmET.hpp:86
#define PROVIDE_FUND_ACCORDING_TO_REPRESENTATIVE_FUNCTION
Defines the Fund type using the call to representativeFunction.
Definition: NnarySmET.hpp:175
#define DECLAUTO
Short name for decltype(auto)
#define SIMPLE_NNARY_SMET_BUILDER(BUILDER,NNARY_SMET)
Definition: NnarySmET.hpp:406
#define PROVIDE_NNARY_SMET_REFS_AND_CHECK_ARE_N(N)
Definition: NnarySmET.hpp:126
#define DEFINE_BASE_TYPE(TYPE,...)
Definition: TypeTraits.hpp:526