EvaluateRank1TestHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <iterator>
8 #include <numeric>
9 
13 #include "Utilities/GenerateInstantiations.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 namespace TestHelpers::TensorExpressions {
17 
18 /// \ingroup TestingFrameworkGroup
19 /// \brief Test that evaluating a right hand side tensor expression containing a
20 /// single rank 1 tensor correctly assigns the data to the evaluated left hand
21 /// side tensor
22 ///
23 /// \tparam DataType the type of data being stored in the Tensors
24 /// \tparam TensorIndexTypeList the Tensors' typelist containing their
25 /// \ref SpacetimeIndex "TensorIndexType"
26 /// \param tensorindex the TensorIndex used in the the TensorExpression,
27 /// e.g. `ti_a`
28 template <typename DataType, typename TensorIndexTypeList, typename TensorIndex>
29 void test_evaluate_rank_1_impl(const TensorIndex& tensorindex) noexcept {
30  Tensor<DataType, Symmetry<1>, TensorIndexTypeList> R_a(5_st);
31  std::iota(R_a.begin(), R_a.end(), 0.0);
32 
33  // L_a = R_a
34  // Use explicit type (vs auto) so the compiler checks return type of
35  // `evaluate`
36  const Tensor<DataType, Symmetry<1>, TensorIndexTypeList> L_a =
37  ::TensorExpressions::evaluate<TensorIndex>(R_a(tensorindex));
38 
39  const size_t dim = tmpl::at_c<TensorIndexTypeList, 0>::dim;
40 
41  // For L_a = R_a, check that L_i == R_i
42  for (size_t i = 0; i < dim; ++i) {
43  CHECK(L_a.get(i) == R_a.get(i));
44  }
45 }
46 
47 /// \ingroup TestingFrameworkGroup
48 /// \brief Iterate testing of evaluating single rank 1 Tensors on multiple Frame
49 /// types and dimensions
50 ///
51 /// \tparam DataType the type of data being stored in the Tensors
52 /// \tparam TensorIndexType the Tensors' \ref SpacetimeIndex "TensorIndexType"
53 /// \tparam Valence the valence of the Tensors' index
54 /// \param tensorindex the TensorIndex used in the the TensorExpression,
55 /// e.g. `ti_a`
56 template <typename DataType,
57  template <size_t, UpLo, typename> class TensorIndexType, UpLo Valence,
58  typename TensorIndex>
59 void test_evaluate_rank_1(const TensorIndex& tensorindex) noexcept {
60 #define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)
61 #define FRAME(data) BOOST_PP_TUPLE_ELEM(1, data)
62 
63 #define CALL_TEST_EVALUATE_RANK_1_IMPL(_, data) \
64  test_evaluate_rank_1_impl< \
65  DataType, index_list<TensorIndexType<DIM(data), Valence, FRAME(data)>>>( \
66  tensorindex);
67 
68  GENERATE_INSTANTIATIONS(CALL_TEST_EVALUATE_RANK_1_IMPL, (1, 2, 3),
70 
71 #undef CALL_TEST_EVALUATE_RANK_1_IMPL
72 #undef FRAME
73 #undef DIM
74 }
75 
76 } // namespace TestHelpers::TensorExpressions
Frame::Inertial
Definition: IndexType.hpp:44
TensorExpression.hpp
UpLo
UpLo
Definition: IndexType.hpp:20
Frame::Grid
Definition: IndexType.hpp:43
TensorIndex
Represents the indices in a TensorExpression.
Definition: TensorExpression.hpp:35
iterator
cstddef
TestHelpers::TensorExpressions::test_evaluate_rank_1_impl
void test_evaluate_rank_1_impl(const TensorIndex &tensorindex) noexcept
Test that evaluating a right hand side tensor expression containing a single rank 1 tensor correctly ...
Definition: EvaluateRank1TestHelpers.hpp:29
Tensor.hpp
TestHelpers::TensorExpressions::test_evaluate_rank_1
void test_evaluate_rank_1(const TensorIndex &tensorindex) noexcept
Iterate testing of evaluating single rank 1 Tensors on multiple Frame types and dimensions.
Definition: EvaluateRank1TestHelpers.hpp:59
numeric
GENERATE_INSTANTIATIONS
#define GENERATE_INSTANTIATIONS(INSTANTIATION_MACRO,...)
Macro useful for generating many explicit instantiations of function or class templates.
Definition: GenerateInstantiations.hpp:160
TMPL.hpp
Evaluate.hpp
cpp2b::iota
constexpr void iota(ForwardIterator first, ForwardIterator last, T value)
Definition: Numeric.hpp:20