1 #ifndef __DUNE_ACFEM_TENSORS_MODULES_EYE_HH__
2 #define __DUNE_ACFEM_TENSORS_MODULES_EYE_HH__
4 #include "../tensorbase.hh"
5 #include "../expressiontraits.hh"
8 #ifndef SPECIALIZEDTRAITS_DEFINED
26 template<
class Seq,
class Field = IntFraction<1> >
29 template<
class Seq,
class Field>
30 struct HasSpecializedExpressionTraits<Eye<Seq, Field> >
34 template<
class,
class =
void>
40 struct IsEye<T, std::enable_if_t<!IsDecay<T>::value> >
41 : IsEye<std::decay_t<T> >
44 template<
class Seq,
class Field>
45 struct IsEye<Eye<Seq, Field> >
52 template<
class Field, std::size_t... Dimensions>
53 class Eye<Seq<Dimensions...>, Field>
54 :
public TensorBase<FloatingPointClosure<Field>, Seq<Dimensions...>, Eye<Seq<Dimensions...>, Field> >
56 ,
public MPL::UniqueTags<ConstantExpression,
57 ConditionalType<IsTypedValue<Field>::value, TypedValueExpression, void> >
62 using typename BaseType::Signature;
63 using typename BaseType::FieldType;
64 using ValueType = Field;
67 "Eye tensors must not be build with dynamic values.");
72 template<
class... Dims,
73 std::enable_if_t<(
sizeof...(Dims) == rank
79 if (!
isConstant(std::forward_as_tuple(indices...))) {
82 return FieldType(ValueType{});
88 template<std::size_t... Indices,
class Pos =
MakeIndexSequence<
sizeof...(Indices)> >
89 static bool constexpr isZero(Seq<Indices...> = Seq<Indices...>{}, Pos = Pos{})
94 template<std::size_t... Indices, std::enable_if_t<
sizeof...(Indices) == rank,
int> = 0>
95 decltype(
auto) operator()(Seq<Indices...> arg)
const
97 using ReturnType = ConditionalType<
isZero<Indices...>(),
99 ConditionalType<IsTypedValue<ValueType>::value,
105 static constexpr ValueType value()
110 std::string name()
const
112 if (!ExpressionTraits<ValueType>::isOne) {
113 return "eye<"+toString(ValueType{}) +
"@" + toString(Signature{})+
">";
115 return "eye<"+toString(Signature{})+
">";
121 template<std::size_t... Dimensions,
class F = Expressions::Closure>
122 auto eye(Seq<Dimensions...>, F closure = F{})
124 if constexpr (
sizeof...(Dimensions) > 1) {
125 return closure(Eye<Seq<Dimensions...>, IntFraction<1> >{});
127 return constantTensor(1_f, Seq<Dimensions...>{}, F{});
131 template<std::size_t... Dimensions,
class F = Expressions::Closure,
132 std::enable_if_t<!IsTensorOperand<F>::value,
int> = 0>
133 auto eye(F closure = F{})
135 if constexpr (
sizeof...(Dimensions) > 1) {
136 return closure(Eye<Seq<Dimensions...>, IntFraction<1> >{});
138 return constantTensor(1_f, Seq<Dimensions...>{}, F{});
142 template<
class T,
class F = Expressions::Closure,
143 std::enable_if_t<IsTensorOperand<T>::value,
int> = 0>
144 auto eye(T&&, F = F{})
146 return eye(
typename TensorTraits<T>::Signature{}, F{});
155 template<
class Seq,
class Field>
156 struct ExpressionTraits<Tensor::Eye<Seq, Field> >
157 : ExpressionTraits<Field>
160 using BaseType = ExpressionTraits<Field>;
163 static constexpr
bool isOne = BaseType::isOne && ExpressionType::rank == 0;
164 static constexpr
bool isMinusOne = BaseType::isMinusOne && ExpressionType::rank == 0;
165 static constexpr
bool isNonZero = BaseType::isNonZero && ExpressionType::rank == 0;
166 static constexpr
bool isPositive = BaseType::isPositive && ExpressionType::rank == 0;
167 static constexpr
bool isNegative = BaseType::isNegative && ExpressionType::rank == 0;
168 using Sign = ExpressionSign<isNonZero, BaseType::isSemiPositive, BaseType::isSemiNegative>;
173 template<
class Field,
class Signature>
174 struct FieldTraits<ACFem::Tensor::Eye<Signature, Field> >
175 : 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: eye.hh:77
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
MakeSequence< std::size_t, N, Offset, Stride, Repeat > MakeIndexSequence
Make a sequence of std::size_t elements.
Definition: generators.hh:34
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
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
constexpr bool isZero
Shortcut identifying a zero model.
Definition: modeltraits.hh:642
Terminals may derive from this class to express that they are expressions.
Definition: terminal.hh:25
Base class for all tensors.
Definition: tensorbase.hh:144