SUNphi  1.0
TensComp.hpp
Go to the documentation of this file.
1 #ifndef _TENSCOMP_HPP
2 #define _TENSCOMP_HPP
3 
4 /// \file TensComp.hpp
5 ///
6 /// \brief Defines the Tensor Components
7 
8 #include <metaprogramming/CRTP.hpp>
9 #include <metaprogramming/TypeTraits.hpp>
10 #include <system/SIMD.hpp>
11 #include <utility/String.hpp>
12 #include <utility/Unused.hpp>
13 
14 namespace SUNphi
15 {
16  /// Defines the BaseTensComp type traits
17  ///
18  /// Used to specify the underlying kind and number of component of a
19  /// tensor component
21 
22  /// Constant used to instantiate a Dynamic-size TensComp
23  constexpr int DYNAMIC=-1;
24 
25  /// Tensor Component
26  ///
27  /// A tensor component is defined by an internal type and the
28  /// associated size, which can be known at compile-time or can be
29  /// made \c DYNAMIC, to be specified at runtime in the storage class
30  template <class T, // Type defining the TensComp
31  int Size=DYNAMIC, // Size of the TensComp
32  int MaxKnownSubMultiple=1> // Given known submultiple (used for DYNAMIC case)
33  struct TensComp :
34  public BaseTensComp
35  {
36  /// Mapped type
37  using type=T;
38 
39  // Cast to type
41 
42  /// Size of the tensor component (max index value)
43  static constexpr int size=Size;
44 
45  /// Report if the component has dynamic size
46  static constexpr bool isDynamic=(Size==DYNAMIC);
47 
48  /// If DYNAMIC size, this is used to provide a submultiple of "size"
50 
51  /// Check if compatible with vectorization
52  template <typename F> // Fundamental type
54 
55  /// Provide a dummy name, maybe we can improve it
56  PROVIDE_NAME("TensComp");
57 
58  };
59 
60  /// Defines a \c TensComp, with name TYPE and max N
61 #define DEFINE_TENS_COMP_CLASS(TYPE,N)
62  /*! Tensor component of \c TYPE Kind */
63  struct TYPE : public TensComp<TYPE,N>
64  {
65  PROVIDE_NAME(#TYPE);
66  }
67 
68  /// Define a \c TensComp named \c TYPE with maximal component \c N
69  ///
70  /// Defines also a binder-instantiator named BINDER, a \c TensKind
71  /// suffixing TYPE with Kind, and a constat holding the maximal value,
72  /// named \c NCONST_NAME
73 #define DEFINE_TENS_COMP(BINDER,
74  TYPE,
75  CONST_NAME,
76  HMANY)
77 
78  /*! Maximal value for \c TensKind of type TYPE */
79  constexpr const int N ## CONST_NAME=HMANY;
80  MAYBE_UNUSED(N ## CONST_NAME);
81 
82  DEFINE_TENS_COMP_CLASS(TYPE,HMANY);
83 
84  DEFINE_NAMED_BINDER(TYPE,BINDER)
85 
86  /// Define row and \c TensComp named \c Rw/CnTYPE with maximal component \c N
87  ///
88  /// Defines also a common binder-instantiator named BINDER, a \c
89  /// TensKind suffixing TYPE with Kind, and a constat holding the
90  /// maximal value, named \c NCONST_NAME
91 #define DEFINE_RW_CN_TENS_COMP(BINDER,
92  TYPE,
93  CONST_NAME,
94  HMANY)
95 
96  /*! Number of components of TYPE type */
97  constexpr const int N ## CONST_NAME=HMANY;
98  MAYBE_UNUSED(N ## CONST_NAME);
99 
100  /* Defines the Row TYPE component */
101  DEFINE_TENS_COMP(rw ## TYPE,Rw ## TYPE,RW_ ## TYPE,N ## CONST_NAME);
102 
103  /* Defines the Column TYPE component */
104  DEFINE_TENS_COMP(cn ## TYPE,Cn ## TYPE,CN_ ## TYPE,N ## CONST_NAME);
105 
106  /* Makes the Row and Column TYPE component twinned */
107  DECLARE_TENS_COMPS_ARE_TWIN(Rw ## TYPE,Cn ## TYPE);
108 
109  /* Declares a row or column (aliasing) binder for type TYPE */
110  DEFINE_NAMED_RW_OR_COL_BINDER(TYPE,BINDER);
111 
112  /*! Declares an alias TYPE to be used when no column or row specified */
113  using TYPE=Cn ## TYPE;
114  /*! Declares the twin types of TYPE TensComp */
115  template<>
116  struct TwinTensCompOf<TYPE>
117  {
118  /*! rw type of TYPE TensComp */
119  using Rw=Rw ## TYPE;
120 
121  /*! cn type of TYPE TensComp */
122  using Cn=Cn ## TYPE;
123  }
124 }
125 
126 #endif
#define DEFINE_NAMED_RW_OR_COL_BINDER(TG,NAME)
Defines a Binder named NAME for type RwTG or CnTG.
Definition: Bind.hpp:34
#define MAYBE_UNUSED(A)
Suppress the "Unused Variable" warning at any scope.
Definition: Unused.hpp:23
#define PROVIDE_CRTP_CAST_OPERATOR(CLASS)
Definition: CRTP.hpp:16
#define DEFINE_NAMED_BINDER(TG,NAME)
Defines a Binder named NAME for type TG.
Definition: Bind.hpp:23
#define PROVIDE_NAME(STR)
Provides a static name() method to a class, returning STR.
Definition: String.hpp:24
static constexpr bool isVectorizable
Check if compatible with vectorization.
Definition: TensComp.hpp:53
#define DEFINE_TENS_COMP_CLASS(TYPE, N)
Defines a TensComp, with name TYPE and max N.
Definition: TensComp.hpp:61
decltype(auto) operator+(T1 &&smet1, T2 &&smet2)
Implement smet1+smet2.
Definition: Add.hpp:87
#define DECLARE_TENS_COMPS_ARE_TWIN(T1, T2)
Declare a pair of TensComp twins one of the other.
Definition: TwinsComp.hpp:48
#define DEFINE_BASE_TYPE(TYPE,...)
Definition: TypeTraits.hpp:526
#define DEFINE_TENS_COMP(BINDER,TYPE,CONST_NAME,HMANY)
Definition: TensComp.hpp:73