16 #ifndef OPENKALMAN_EIGEN_TRAITS_TENSORCONTRACTIONOP_HPP 17 #define OPENKALMAN_EIGEN_TRAITS_TENSORCONTRACTIONOP_HPP 22 template<
typename Indices,
typename LhsXprType,
typename RhsXprType,
typename OutputKernelType>
28 using Xpr = Eigen::TensorContractionOp<Indices, LhsXprType, RhsXprType, OutputKernelType>;
33 template<
typename Arg,
typename N>
36 using IndexType =
typename Xpr::Index;
37 return Eigen::TensorEvaluator<const Arg, Eigen::DefaultDevice>{arg, Eigen::DefaultDevice{}}.dimensions()[
static_cast<IndexType
>(n)];
44 template<
typename Arg>
45 static constexpr
auto get_constant(
const Arg& arg)
49 if constexpr (zero<LhsXprType>)
53 else if constexpr (zero<RhsXprType>)
57 else if constexpr (constant_diagonal_matrix<LhsXprType> and constant_matrix<RhsXprType>)
59 if constexpr (std::tuple_size_v<decltype(arg.indices())> == 1)
65 auto& indices = arg.indices();
66 auto dims = Eigen::TensorEvaluator<const Arg, Eigen::DefaultDevice>{arg, Eigen::DefaultDevice{}}.dimensions();
67 auto f = [&dims](
const Scalar& a,
auto b) -> Scalar {
return a * dims[b.first]; };
68 auto factor = std::accumulate(++indices.cbegin(), indices.cend(), Scalar{1}, f);
72 else if constexpr (constant_matrix<LhsXprType> and constant_diagonal_matrix<RhsXprType>)
74 if constexpr (std::tuple_size_v<decltype(arg.indices())> == 1)
80 auto& indices = arg.indices();
81 auto dims = Eigen::TensorEvaluator<const Arg, Eigen::DefaultDevice>{arg, Eigen::DefaultDevice{}}.dimensions();
82 auto f = [&dims](
const Scalar& a,
auto b) -> Scalar {
return a * dims[b.first]; };
83 auto factor = std::accumulate(++indices.cbegin(), indices.cend(), Scalar{1}, f);
89 auto& indices = arg.indices();
90 auto dims = Eigen::TensorEvaluator<const Arg, Eigen::DefaultDevice>{arg, Eigen::DefaultDevice{}}.dimensions();
91 auto f = [&dims](
const Scalar& a,
auto b) -> Scalar {
return a * dims[b.first]; };
92 auto factor = std::accumulate(indices.cbegin(), indices.cend(), Scalar{1}, f);
98 template<
typename Arg>
99 static constexpr
auto get_constant_diagonal(
const Arg& arg)
101 if constexpr (std::tuple_size_v<decltype(arg.indices())> == 1)
109 auto& indices = arg.indices();
110 auto dims = Eigen::TensorEvaluator<const Arg, Eigen::DefaultDevice>{arg, Eigen::DefaultDevice{}}.dimensions();
111 auto f = [&dims](
const Scalar& a,
auto b) -> Scalar {
return a * dims[b.first]; };
112 auto factor = std::accumulate(++indices.cbegin(), indices.cend(), Scalar{1}, f);
127 static constexpr
bool is_triangular_adapter =
false;
130 static constexpr
bool is_hermitian = std::tuple_size_v<decltype(std::declval<Xpr>().indices())> == 1 and
131 ((constant_diagonal_matrix<LhsXprType> and hermitian_matrix<RhsXprType, Applicability::permitted>) or
132 (constant_diagonal_matrix<RhsXprType> and hermitian_matrix<LhsXprType, Applicability::permitted>));
135 static constexpr
bool is_writable =
false;
147 #endif //OPENKALMAN_EIGEN_TRAITS_TENSORCONTRACTIONOP_HPP Definition: indexible_object_traits.hpp:36
Definition: basics.hpp:41
An operation involving some number of values.
Definition: operation.hpp:69
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
Definition: eigen-comma-initializers.hpp:20
Trait object providing get and set routines for Eigen tensors.
Definition: eigen-tensor-forward-declarations.hpp:114
The constant associated with T, assuming T is a constant_matrix.
Definition: constant_coefficient.hpp:36
The constant associated with T, assuming T is a constant_diagonal_matrix.
Definition: constant_diagonal_coefficient.hpp:32
constexpr auto get_vector_space_descriptor(const T &t, const N &n)
Get the coordinates::pattern object for index N of indexible object T.
Definition: get_vector_space_descriptor.hpp:56