1#ifndef __DUNE_ACFEM_TENSORS_OPERATIONS_TRANSPOSE_HH__
2#define __DUNE_ACFEM_TENSORS_OPERATIONS_TRANSPOSE_HH__
4#include "../../expressions/storage.hh"
5#include "../../mpl/permutation.hh"
6#include "../../mpl/sort.hh"
7#include "../tensorbase.hh"
8#include "../modules.hh"
16 struct TransposeOperation;
28 template<
class Tensor,
class Perm>
50 template<
class Tensor, std::size_t... Perm>
52 :
public TensorBase<typename TensorTraits<Tensor>::FieldType,
53 Seq<Get<Perm, typename TensorTraits<Tensor>::Signature>::value...>,
54 Transposition<Tensor, Seq<Perm...> > >
55 ,
public Expressions::Storage<OperationTraits<TransposeOperation<Seq<Perm...> > >, Tensor>
57 static_assert(
sizeof...(Perm) == TensorTraits<Tensor>::rank,
58 "A transposition must be provided for all tensor dimensions.");
60 using ArgType = Tensor;
61 using HostType = std::decay_t<Tensor>;
63 Seq<Get<Perm, typename TensorTraits<Tensor>::Signature>::value...>,
65 using StorageType = Expressions::Storage<OperationTraits<
TransposeOperation<Seq<Perm...> > >, Tensor>;
67 using Permutation = Seq<Perm...>;
68 using StorageType::operation;
69 using StorageType::operand;
71 using typename BaseType::Signature;
72 using typename BaseType::FieldType;
77 template<class Arg, std::enable_if_t<std::is_constructible<ArgType, Arg>::value,
int> = 0>
79 : StorageType(
std::forward<Arg>(host))
85 std::enable_if_t<(
sizeof...(Dummy) == 0
88 : StorageType(ArgType{})
94 template<
class... Dims,
95 std::enable_if_t<(
sizeof...(Dims) == rank
99 decltype(
auto)
operator()(Dims... indices)
101 return operand(0_c)(std::get<Perm>(std::forward_as_tuple(indices...))...);
107 template<
class... Dims,
108 std::enable_if_t<(
sizeof...(Dims) == rank
112 decltype(
auto)
operator()(Dims... indices)
const
114 return operand(0_c)(std::get<Perm>(std::forward_as_tuple(indices...))...);
117 template<std::size_t... Indices, std::enable_if_t<
sizeof...(Indices) == rank,
int> = 0>
118 decltype(
auto)
constexpr operator()(Seq<Indices...>)
const
120 return operand(0_c)(Seq<
Get<Perm, Seq<Indices...> >::value...>{});
123 template<std::size_t... Indices,
class Pos =
MakeIndexSequence<
sizeof...(Indices)> >
124 static bool constexpr isZero(Seq<Indices...> = Seq<Indices...>{}, Pos = Pos{})
127 using RealPos =
HeadPart<
sizeof...(Indices), Pos>;
132 using SortedPos =
typename SortSequence<TransposedPos>::Result;
133 using Permutation =
typename SortSequence<TransposedPos>::Permutation;
136 return HostType::isZero(SortedIndices{}, SortedPos{});
139 std::string name()
const
142 std::string pfx = std::is_reference<T>::value ? (RefersConst<T>::value ?
"cref" :
"ref") :
"";
154 template<
class T, std::size_t... Perm>
160 template<std::size_t... Perm,
class T,
161 std::enable_if_t<(IsProperTensor<T>::value
163 &&
sizeof...(Perm) <= TensorTraits<T>::rank
165 constexpr decltype(
auto)
transpose(T&& t, Seq<Perm...> = Seq<Perm...>{})
167 using Operation = TransposeOperation<
ResizedPermutation<Seq<Perm...>, TensorTraits<T>::rank> >;
169 return Expressions::finalize<Operation>(std::forward<T>(t));
174 template<
class Perm,
class T, std::enable_if_t<Perm::size() == TensorTraits<T>::rank,
int> = 0>
177 DUNE_ACFEM_RECORD_OPTIMIZATION;
179 return Transposition<T, Perm>(std::forward<T>(t));
188 template<
class T,
class P>
189 struct FieldTraits<ACFem::Tensor::Transposition<T, P> >
190 : FieldTraits<std::decay_t<T> >
OptimizeTag< 0 > DontOptimize
Bottom level is overloaded to do nothing.
Definition: optimizationbase.hh:74
std::string operationName(F &&f, const std::string &arg)
Verbose print of an operation, helper function to produce noise.
Definition: operationtraits.hh:601
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
MakeSequence< std::size_t, N, Offset, Stride, Repeat > MakeIndexSequence
Make a sequence of std::size_t elements.
Definition: generators.hh:34
constexpr auto operate(Expressions::DontOptimize, OperationTraits< TransposeOperation< Perm > >, T &&t)
Definition: transpose.hh:175
Transposition(Arg &&host)
Constructor from a given host-tensor.
Definition: transpose.hh:78
Transposition(Dummy &&...)
Allow default construction if contained types fulfill IsTypedValue.
Definition: transpose.hh:87
constexpr decltype(auto) transpose(T &&t, Seq< Perm... >=Seq< Perm... >{})
Promote operands to tensor transposition operation.
Definition: operandpromotion.hh:309
typename ResizedPermutationHelper< Permutation, N >::Type ResizedPermutation
Pad or truncate the permuation at the given size.
Definition: permutation.hh:83
typename TranspositionHelper< I0, I1, N >::Type Transposition
Generate the transposition of I0 and I1 as permutation.
Definition: permutation.hh:206
constexpr bool isPermutation(IndexSequence< Ind... >=IndexSequence< Ind... >{})
Definition: compare.hh:362
decltype(isIntegralPack(std::declval< T >()...)) IsIntegralPack
Decide whether the given parameter pack contains only integral types.
Definition: compare.hh:377
typename PermuteSequenceValuesHelper< Perm, Sequence >::Type PermuteSequenceValues
Apply the given permutation to the values of the given sequence.
Definition: permutation.hh:101
std::decay_t< decltype(permute(Sequence{}, Perm{}))> PermuteSequence
Apply the given permutation to the positions of the given sequence.
Definition: permutation.hh:137
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
Gets the type of the n-th element of a tuple-like or the std::integral_constant corresponding to the ...
Definition: access.hh:42
Traits in order to identify a TensorView class.
Definition: transpose.hh:152
Base class for all tensors.
Definition: tensorbase.hh:144
Permutation of index positions of tensors.
Definition: expressionoperations.hh:167