aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/CXX11/src/Tensor/Tensor.h
diff options
context:
space:
mode:
authorGravatar Christian Seiler <christian@iwakd.de>2013-11-14 23:35:11 +0100
committerGravatar Christian Seiler <christian@iwakd.de>2013-11-14 23:35:11 +0100
commit03a956925a969e3759418bd1e0fced82eb5f9d12 (patch)
tree9ec0cfecc851a8c75cdac18e981ecb01a69ec5a8 /unsupported/Eigen/CXX11/src/Tensor/Tensor.h
parentf97b3cd0249228820807229a2d529260522ba8c7 (diff)
CXX11/TensorSymmetry: add symmetry support for Tensor class
Add a symCoeff() method to the Tensor class template that allows the user of the class to set multiple elements of a tensor at once if they are connected by a symmetry operation with respect to the tensor's indices (symmetry/antisymmetry/hermiticity/antihermiticity under echange of two indices and combination thereof for different pairs of indices). A compile-time resolution of the required symmetry groups via meta templates is also implemented. For small enough groups this is used to unroll the loop that goes through all the elements of the Tensor that are connected by this group. For larger groups or groups where the symmetries are defined at run time, a standard run-time implementation of the same algorithm is provided. For example, the following code completely initializes all elements of the totally antisymmetric tensor in three dimensions ('epsilon tensor'): SGroup<3, AntiSymmetry<0,1>, AntiSymmetry<1,2>> sym; Eigen::Tensor<double, 3> epsilon(3,3,3); epsilon.setZero(); epsilon.symCoeff(sym, 0, 1, 2) = 1;
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor/Tensor.h')
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/Tensor.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/Tensor.h b/unsupported/Eigen/CXX11/src/Tensor/Tensor.h
index c40905af4..ff3d6513e 100644
--- a/unsupported/Eigen/CXX11/src/Tensor/Tensor.h
+++ b/unsupported/Eigen/CXX11/src/Tensor/Tensor.h
@@ -92,6 +92,9 @@ struct tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor>
return std_array_get<RowMajor ? 0 : NumIndices - 1>(indices);
}
};
+
+/* Forward-declaration required for the symmetry support. */
+template<typename Tensor_, typename Symmetry_, int Flags = 0> class tensor_symmetry_value_setter;
} // end namespace internal
template<typename Scalar_, std::size_t NumIndices_, int Options_>
@@ -283,6 +286,18 @@ class Tensor
#endif
}
+ template<typename Symmetry_, typename... IndexTypes>
+ internal::tensor_symmetry_value_setter<Self, Symmetry_> symCoeff(const Symmetry_& symmetry, Index firstIndex, IndexTypes... otherIndices)
+ {
+ return symCoeff(symmetry, std::array<Index, NumIndices>{{firstIndex, otherIndices...}});
+ }
+
+ template<typename Symmetry_, typename... IndexTypes>
+ internal::tensor_symmetry_value_setter<Self, Symmetry_> symCoeff(const Symmetry_& symmetry, std::array<Index, NumIndices> const& indices)
+ {
+ return internal::tensor_symmetry_value_setter<Self, Symmetry_>(*this, symmetry, indices);
+ }
+
protected:
bool checkIndexRange(const std::array<Index, NumIndices>& indices) const
{