1 #ifndef __DUNE_ACFEM_TENSORS_MODULES_BLOCKEYE_HH__
2 #define __DUNE_ACFEM_TENSORS_MODULES_BLOCKEYE_HH__
4 #include "../tensorbase.hh"
22 template<std::
size_t BlockRank,
class BlockSignature,
class Field = IntFraction<1> >
25 template<std::
size_t BlockRank,
class BlockSignature,
class Field>
26 struct HasSpecializedExpressionTraits<BlockEye<BlockRank, BlockSignature, Field> >
37 : IsBlockEye<std::decay_t<T> >
41 struct IsBlockEye<T&&>
42 : IsBlockEye<std::decay_t<T> >
46 template<std::
size_t BlockRank,
class BlockSignature,
class Field>
47 struct IsBlockEye<BlockEye<BlockRank, BlockSignature, Field> >
51 template<
class T,
class SFINAE =
void>
54 using ValueType = void;
55 static constexpr std::size_t blockRank_ = 0;
56 using BlockSignature = Seq<>;
57 static constexpr std::size_t blockSize_ = 0;
61 struct BlockEyeTraits<T, std::enable_if_t<!IsDecay<T>::value> >
62 : BlockEyeTraits<std::decay_t<T> >
65 template<std::
size_t Rank,
class Signature,
class Field>
66 struct BlockEyeTraits<BlockEye<Rank, Signature, Field> >
68 using ValueType = Field;
69 static constexpr std::size_t blockRank_ = Rank;
70 using BlockSignature = Signature;
92 template<
class Pos, std::
size_t BlockRank,
class Dims,
class SFINAE =
void>
95 template<std::size_t... P, std::size_t BlockRank,
class Dims>
97 typename SortSequence<Seq<(P %
Dims::size())...> >::Result,
111 template<std::size_t BlockRank, std::size_t... Dimensions,
class Field>
112 class BlockEye<BlockRank, Seq<Dimensions...>, Field>
113 :
public TensorBase<FloatingPointClosure<Field>, SequenceProd<BlockRank, Seq<Dimensions...> >,
114 BlockEye<BlockRank, Seq<Dimensions...>, Field> >
116 ,
public MPL::UniqueTags<ConstantExpression,
117 ConditionalType<IsTypedValue<Field>::value, TypedValueExpression, void>
121 BlockEye<BlockRank, Seq<Dimensions...>, Field> >;
122 static constexpr std::size_t blockSize_ =
sizeof...(Dimensions);
124 using BaseType::rank;
125 using typename BaseType::FieldType;
126 using typename BaseType::Signature;
127 using ValueType = Field;
128 using BlockSignature = Seq<Dimensions...>;
129 static constexpr std::size_t blockRank_ = BlockRank;
134 template<
class... Dims,
135 std::enable_if_t<(
sizeof...(Dims) == rank
142 #if __GNUC__ <= 7 && !defined(__clang__)
143 const auto indexArray = std::array<std::size_t,
sizeof...(Dims)>({{ (std::size_t)indices... }});
144 for (
unsigned i = 0; i < blockSize_; ++i) {
145 const auto first = indexArray[i];
146 for (
unsigned j = 1; j < BlockRank; ++j) {
147 const auto next = indexArray[i+j*blockSize_];
155 forLoop<blockSize_>([&](
auto i) {
156 using I = decltype(i);
157 std::size_t first = get<I::value>(std::forward_as_tuple(indices...));
159 using J = decltype(j);
160 std::size_t next = std::get<I::value+J::value*blockSize_>(std::forward_as_tuple(indices...));
170 return FieldType(ValueType{});
177 template<std::size_t... Indices, std::enable_if_t<
sizeof...(Indices) == rank,
int> = 0>
180 using ReturnType = ConditionalType<isZero<Indices...>(),
189 template<
class Indices,
class Pos>
193 template<std::
size_t N>
198 template<std::
size_t N>
199 using IndexBlock = SequenceSlice<Indices, PositionsOf<N> >;
201 template<std::
size_t N>
205 template<
class Indices,
class Pos, std::size_t... N>
206 static bool constexpr isZeroExpander(Indices, Pos, Seq<N...>)
208 return (... || (IsZeroFunctor<Indices, Pos>::template ZeroMatch<N>::value));
212 template<std::size_t... Indices,
class Pos =
MakeIndexSequence<
sizeof...(Indices)> >
213 static bool constexpr isZero(Seq<Indices...> = Seq<Indices...>{}, Pos = Pos{})
216 using RealPos =
HeadPart<
sizeof...(Indices), Pos>;
218 return isZeroExpander(Seq<Indices...>{}, RealPos{}, MakeSequenceFor<RealPos>{});
221 std::string name()
const
223 return "blockEye<"+std::to_string(blockRank_)+
"|"+toString(BlockSignature{})+
">";
230 template<std::size_t Rank, std::size_t... Dimensions,
class F = Expressions::Closure>
231 auto blockEye(Seq<Dimensions...> = Seq<Dimensions...>{}, F closure = F{})
233 if constexpr (Rank > 0) {
234 if constexpr (
sizeof...(Dimensions) == 1) {
237 return closure(BlockEye<Rank, Seq<Dimensions...>, IntFraction<1> >{});
240 return constantTensor(1_f, Seq<>{}, F{});
245 template<std::size_t Rank,
class T,
class F = Expressions::Closure,
246 std::enable_if_t<!IsSequence<T>::value,
int> = 0>
249 return blockEye<Rank>(
typename TensorTraits<T>::Signature{}, F{});
258 template<
class Field, std::
size_t BlockRank,
class BlockSignature>
259 struct ExpressionTraits<Tensor::BlockEye<BlockRank, BlockSignature, Field> >
260 : ExpressionTraits<Field>
263 using BaseType = ExpressionTraits<Field>;
265 using ExpressionType = Tensor::BlockEye<BlockRank, BlockSignature, Field>;
266 static constexpr
bool isOne = BaseType::isOne && ExpressionType::rank == 0;
267 static constexpr
bool isMinusOne = BaseType::isMinusOne && ExpressionType::rank == 0;
268 static constexpr
bool isNonZero = BaseType::isNonZero && ExpressionType::rank == 0;
269 static constexpr
bool isPositive = BaseType::isPositive && ExpressionType::rank == 0;
270 static constexpr
bool isNegative = BaseType::isNegative && ExpressionType::rank == 0;
271 using Sign = ExpressionSign<isNonZero, BaseType::isSemiPositive, BaseType::isSemiNegative>;
276 template<
class Field, std::
size_t N,
class Signature>
277 struct FieldTraits<ACFem::Tensor::BlockEye<N, Signature, Field> >
278 : FieldTraits<std::decay_t<Field> >
FieldType operator()(Dims... indices) const
Insert the current view-indices at their proper positions and foward to the underlying "host" tensor.
Definition: blockeye.hh:139
decltype(auto) operator()(Seq< Indices... >) const
Constant access with index sequence.
Definition: blockeye.hh:178
decltype(operate(std::declval< OptOrF >(), std::declval< Rest >()...)) ExpressionType
Generate the type of an expression by calling operate().
Definition: optimizationbase.hh:256
BoolConstant< ExpressionTraits< T >::isTypedValue > IsTypedValue
Compile-time true if T is a "typed value", e.g. a std::integral_constant.
Definition: expressiontraits.hh:90
typename GetHeadPartHelper< Cnt, Seq >::Type HeadPart
Extract Cnt many consecutive elements from the front of Seq.
Definition: access.hh:217
constexpr std::size_t size()
Gives the number of elements in tuple-likes and std::integer_sequence.
Definition: size.hh:73
MakeSequence< std::size_t, N, Offset, Stride, Repeat > MakeIndexSequence
Make a sequence of std::size_t elements.
Definition: generators.hh:34
MakeIndexSequence< N, Value, 0 > MakeConstantSequence
Generate a constant index sequence of the given size.
Definition: generators.hh:45
auto blockEye(T &&, F=F{})
Return the blockEye with the block-signature taken from T.
Definition: blockeye.hh:247
constexpr bool IsBlockEyePositionsV
Definition: blockeye.hh:93
constexpr bool isConstant(Sequence< T, T0, Ts... >)
Definition: compare.hh:285
decltype(isIntegralPack(std::declval< T >()...)) IsIntegralPack
Decide whether the given parameter pack contains only integral types.
Definition: compare.hh:377
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
Accept if input-value MOD P = R.
Definition: transform.hh:511
Terminals may derive from this class to express that they are expressions.
Definition: terminal.hh:25
Index functor.
Definition: transform.hh:346
Base class for all tensors.
Definition: tensorbase.hh:144