1#ifndef __DUNE_ACFEM_TENSORS_EXPRESSIONOPERATIONS_HH__
2#define __DUNE_ACFEM_TENSORS_EXPRESSIONOPERATIONS_HH__
6#include "../mpl/compare.hh"
7#include "../expressions/storage.hh"
8#include "../expressions/expressionoperations.hh"
9#include "operations/einsum.hh"
10#include "operations/product.hh"
11#include "operations/reshape.hh"
12#include "operations/restriction.hh"
13#include "operations/transpose.hh"
35 struct IsTensorOperation
51 template<
class Dims,
class Pivot>
55 template<
class Dims,
class Pivot>
61 struct IsRestrictionOperation
65 template<
class Dims,
class Pivot>
66 struct IsRestrictionOperation<RestrictionOperation<Dims, Pivot> >
70 template<
class T,
class SFINAE =
void>
71 struct IsRestrictionExpression
76 struct IsRestrictionExpression<
78 std::enable_if_t<(IsExpressionOfArity<1, T>::value
79 && IsRestrictionOperation<Expressions::Operation<T> >::value
84 template<
class T,
class SFINAE =
void>
85 struct RestrictionTraits
88 template<
class Dims,
class Pivot>
89 struct RestrictionTraits<RestrictionOperation<Dims, Pivot> >
91 using DefectPositions = Dims;
92 using PivotSequence = Pivot;
95 template<
class Dims,
class Pivot>
96 struct RestrictionTraits<OperationTraits<RestrictionOperation<Dims, Pivot> > >
97 : RestrictionTraits<RestrictionOperation<Dims, Pivot> >
101 struct RestrictionTraits<T,
std::enable_if_t<IsRestrictionExpression<T>::value> >
102 : RestrictionTraits<Expressions::Operation<T> >
105 template<
class T,
class SFINAE =
void>
106 struct IsConstRestrictionOperation
111 struct IsConstRestrictionOperation<
113 std::enable_if_t<(IsRestrictionOperation<T>::value
114 && (RestrictionTraits<T>::DefectPositions::size()
116 RestrictionTraits<T>::PivotSequence::size())
121 template<
class T,
class SFINAE =
void>
122 struct IsConstRestrictionExpression
127 struct IsConstRestrictionExpression<
129 std::enable_if_t<(IsRestrictionExpression<T>::value
130 && IsConstRestrictionOperation<Expressions::Operation<T> >::value
135 template<
class T,
class SFINAE =
void>
136 struct IsDynamicRestrictionExpression
141 struct IsDynamicRestrictionExpression<
143 std::enable_if_t<(IsRestrictionExpression<T>::value
144 && !IsConstRestrictionOperation<Expressions::Operation<T> >::value
150 struct IsDynamicOperation<
152 std::enable_if_t<(IsRestrictionOperation<T>::value
153 && !IsConstRestrictionOperation<T>::value
154 && (RestrictionTraits<T>::DefectPositions::size() > 0)
169 "Given sequence is not a permutation of 0, 1, ...");
178 struct IsTransposeOperation
183 struct IsTransposeOperation<TransposeOperation<Perm> >
187 template<
class T,
class SFINAE =
void>
188 struct IsTransposeExpression
193 struct IsTransposeExpression<
195 std::enable_if_t<(IsExpression<T>::value
196 && Expressions::Arity<T>::value == 1
197 && IsTransposeOperation<Expressions::Operation<T> >::value
202 template<
class T,
class SFINAE =
void>
203 struct TransposeTraits
209 struct TransposeTraits<TransposeOperation<Perm> >
211 using Permutation = Perm;
215 struct TransposeTraits<OperationTraits<TransposeOperation<Perm> > >
216 : TransposeTraits<TransposeOperation<Perm> >
220 struct TransposeTraits<T,
std::enable_if_t<IsTransposeExpression<T>::value> >
221 : TransposeTraits<Expressions::Operation<T> >
230 template<
class Signature>
234 template<
class Signature>
240 struct IsReshapeOperation
245 struct IsReshapeOperation<ReshapeOperation<Sig> >
249 template<
class T,
class SFINAE =
void>
250 struct IsReshapeExpression
255 struct IsReshapeExpression<T,
std::enable_if_t<!IsDecay<T>::value> >
256 : IsReshapeExpression<std::decay_t<T> >
260 struct IsReshapeExpression<
262 std::enable_if_t<(IsDecay<T>::value
263 && IsExpression<T>::value
264 && Expressions::Arity<T>::value == 1
265 && IsReshapeOperation<Expressions::Operation<T> >::value
270 template<
class T,
class SFINAE =
void>
277 struct ReshapeTraits<ReshapeOperation<Sig> >
279 using Signature = Sig;
283 struct ReshapeTraits<OperationTraits<ReshapeOperation<Sig> > >
284 : ReshapeTraits<ReshapeOperation<Sig> >
288 struct ReshapeTraits<T,
std::enable_if_t<IsReshapeExpression<T>::value> >
289 : ReshapeTraits<Expressions::Operation<T> >
306 template<
class Pos1,
class Pos2,
class ContractDims>
310 "Number of contraction indices and dimensions differs.");
313 template<
class Pos1,
class Pos2,
class ContractDims>
319 struct IsEinsumOperation
323 template<
class Pos1,
class Pos2,
class ContractDims>
324 struct IsEinsumOperation<EinsumOperation<Pos1, Pos2, ContractDims> >
329 constexpr inline bool HasEinsumFunctorV = IsEinsumOperation<typename T::FunctorType::OperationType>::value;
331 template<
class T,
class SFINAE =
void>
332 struct IsEinsumExpression
337 struct IsEinsumExpression<
339 std::enable_if_t<(IsExpression<T>::value
340 && Expressions::Arity<T>::value == 2
341 && IsEinsumOperation<Expressions::Operation<T> >::value
346 template<
class T,
class SFINAE =
void>
350 template<
class Pos1,
class Pos2,
class Dims>
351 struct EinsumTraits<EinsumOperation<Pos1, Pos2, Dims> >
353 static constexpr std::size_t defectRank_ =
Dims::size();
354 using LeftIndexPositions = Pos1;
355 using RightIndexPositions = Pos2;
356 using Dimensions = Dims;
359 template<
class Pos1,
class Pos2,
class Dims>
360 struct EinsumTraits<OperationTraits<EinsumOperation<Pos1, Pos2, Dims> > >
361 : EinsumTraits<EinsumOperation<Pos1, Pos2, Dims> >
365 struct EinsumTraits<T,
std::enable_if_t<IsEinsumExpression<T>::value> >
366 : EinsumTraits<Expressions::Operation<T> >
369 template<
class Pos1,
class Pos2,
class Dims>
370 struct IsProductOperation<EinsumOperation<Pos1, Pos2, Dims> >
387 template<
class Pos1,
class Pos2,
class ProductDims>
391 template<
class Pos1,
class Pos2,
class ProductDims>
397 struct IsTensorProductOperation
401 template<
class Pos1,
class Pos2,
class ContractDims>
402 struct IsTensorProductOperation<TensorProductOperation<Pos1, Pos2, ContractDims> >
406 template<
class T,
class SFINAE =
void>
407 struct IsTensorProductExpression
412 struct IsTensorProductExpression<
414 std::enable_if_t<(IsExpression<T>::value
415 && Expressions::Arity<T>::value == 2
416 && IsTensorProductOperation<Expressions::Operation<T> >::value
422 struct TensorProductTraits
425 template<
class Pos1,
class Pos2,
class Dims>
426 struct TensorProductTraits<TensorProductOperation<Pos1, Pos2, Dims> >
428 static constexpr std::size_t defectRank_ =
Dims::size();
429 using LeftIndexPositions = Pos1;
430 using RightIndexPositions = Pos2;
431 using Dimensions = Dims;
434 template<
class Pos1,
class Pos2,
class Dims>
435 struct TensorProductTraits<OperationTraits<TensorProductOperation<Pos1, Pos2, Dims> > >
436 : TensorProductTraits<TensorProductOperation<Pos1, Pos2, Dims> >
439 template<
class Pos1,
class Pos2,
class Dims>
440 struct IsProductOperation<TensorProductOperation<Pos1, Pos2, Dims> >
448 template<
class T,
class SFINAE =
void>
449 struct IsComponentWiseOperation
457 struct IsComponentWiseOperation<
459 std::enable_if_t<(IsReshapeOperation<T>::value
460 || IsTransposeOperation<T>::value
461 || IsRestrictionOperation<T>::value
462 || IsProductOperation<T>::value
467 template<
class T,
class SFINAE =
void>
468 struct IsProductWithScalarExpression
473 struct IsProductWithScalarExpression<
475 std::enable_if_t<(IsProductExpression<T>::value
476 && (TensorTraits<Operand<0, T> >::rank == 0
478 TensorTraits<Operand<1, T> >::rank == 0)
483 template<
class T,
class SFINAE =
void>
484 struct IsComponentWiseExpression
485 : IsComponentWiseOperation<Expressions::Operation<T> >
489 struct IsComponentWiseExpression<T,
std::enable_if_t<IsProductWithScalarExpression<T>::value> >
495 template<
class Operation>
496 struct IsDistributiveOperation<
498 std::enable_if_t<(IsTransposeOperation<Operation>::value
499 || IsRestrictionOperation<Operation>::value
constexpr std::size_t size()
Gives the number of elements in tuple-likes and std::integer_sequence.
Definition: size.hh:73
constexpr bool isPermutation(IndexSequence< Ind... >=IndexSequence< Ind... >{})
Definition: compare.hh:362
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
Einstein summation, i.e.
Definition: expressionoperations.hh:308
Signature of index positions of tensors.
Definition: expressionoperations.hh:232
AutoDiff operation.
Definition: expressionoperations.hh:53
Component-wise product over given index-set.
Definition: expressionoperations.hh:389
Permutation of index positions of tensors.
Definition: expressionoperations.hh:167