old.C 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // -*- mode: c++; coding: utf-8 -*-
  2. /// @file old.C
  3. /// @brief Deprecated parts of test/ra-0.C.
  4. // (c) Daniel Llorens - 2013-2015, 2019
  5. // This library is free software; you can redistribute it and/or modify it under
  6. // the terms of the GNU Lesser General Public License as published by the Free
  7. // Software Foundation; either version 3 of the License, or (at your option) any
  8. // later version.
  9. #include <iostream>
  10. #include <iterator>
  11. #include <numeric>
  12. #include <type_traits>
  13. #include "ra/test.H"
  14. #include "ra/ra.H"
  15. #include "ra/mpdebug.H"
  16. // FIXME Remove these tests as soon as there's an updated equivalent elsewhere.
  17. namespace ra {
  18. template <class A, class B>
  19. struct pick_driver
  20. {
  21. constexpr static int ra = A::rank_s();
  22. constexpr static int rb = B::rank_s();
  23. constexpr static bool value_ =
  24. // check by rank
  25. rb==RANK_BAD
  26. ? 1
  27. : rb==RANK_ANY
  28. ? ra==RANK_ANY
  29. : ra==RANK_BAD
  30. ? 0
  31. : ra==RANK_ANY
  32. ? 1
  33. : ra>rb
  34. ? 1
  35. : ra<rb
  36. ? 0
  37. // check by size
  38. : gt_size(size_s<A>(), size_s<B>());
  39. constexpr static int value = value_ ? 0 : 1; // 0 if A wins over B, else 1
  40. };
  41. template <class ... P> using driver_index = mp::IndexOf<pick_driver, std::tuple<P ...>>;
  42. } // namespace ra
  43. using std::cout, std::endl, std::flush;
  44. template <int i> using TI = ra::TensorIndex<i, int>;
  45. template <int i> using UU = decltype(std::declval<ra::Unique<double, i>>().iter());
  46. using SM1 = decltype(std::declval<ra::Small<double, 2>>().iter());
  47. using SM2 = decltype(std::declval<ra::Small<double, 2, 2>>().iter());
  48. using SM3 = decltype(std::declval<ra::Small<double, 2, 2, 2>>().iter());
  49. using SS = decltype(ra::scalar(1));
  50. int main()
  51. {
  52. TestRecorder tr(std::cout);
  53. // FIXME this section is deprecated, this mechanism isn't used anymore after v10. See test/frame-new.C.
  54. tr.section("driver selection");
  55. {
  56. static_assert(TI<0>::rank_s()==1, "bad TI rank");
  57. static_assert(ra::pick_driver<UU<0>, UU<1> >::value==1, "bad driver 1a");
  58. static_assert(ra::pick_driver<TI<1>, UU<2> >::value==1, "bad driver 1b");
  59. // these two depend on TI<w>::rank_s() being w+1, which I haven't settled on.
  60. static_assert(TI<1>::rank_s()==2, "bad TI rank");
  61. static_assert(ra::pick_driver<TI<0>, TI<1> >::value==1, "bad driver 1c");
  62. static_assert(ra::size_s<UU<0>>()==1, "bad size_s 0");
  63. static_assert(ra::size_s<SS>()==1, "bad size_s 1");
  64. static_assert(ra::pick_driver<UU<0>, SS>::value==0, "bad size_s 2");
  65. // static size/rank identical; prefer the first.
  66. static_assert(ra::driver_index<UU<0>, SS>::value==0, "bad match 1a");
  67. static_assert(ra::driver_index<SS, UU<0>>::value==0, "bad match 1b");
  68. // prefer the larger rank.
  69. static_assert(ra::driver_index<SS, UU<1>>::value==1, "bad match 2a");
  70. static_assert(ra::driver_index<UU<1>, SS>::value==0, "bad match 2b");
  71. // never choose TensorIndex as driver.
  72. static_assert(ra::pick_driver<UU<2>, TI<0>>::value==0, "bad match 3a");
  73. static_assert(ra::pick_driver<TI<0>, UU<2>>::value==1, "bad match 3b");
  74. // static size/rank identical; prefer the first.
  75. static_assert(ra::pick_driver<UU<2>, UU<2>>::value==0, "bad match 4");
  76. static_assert(ra::driver_index<UU<2>, TI<0>, UU<2>>::value==0, "bad match 5a");
  77. // dynamic rank counts as +inf.
  78. static_assert(ra::gt_rank(ra::RANK_ANY, 2), "bad match 6a");
  79. static_assert(ra::gt_rank(UU<ra::RANK_ANY>::rank_s(), UU<2>::rank_s()), "bad match 6b");
  80. static_assert(!ra::gt_rank(UU<2>::rank_s(), UU<ra::RANK_ANY>::rank_s()), "bad match 6c");
  81. static_assert(ra::pick_driver<UU<ra::RANK_ANY>, UU<2>>::value==0, "bad match 6d");
  82. static_assert(ra::pick_driver<UU<2>, UU<ra::RANK_ANY>>::value==1, "bad match 6e");
  83. static_assert(ra::pick_driver<UU<ra::RANK_ANY>, UU<ra::RANK_ANY>>::value==0, "bad match 6f");
  84. static_assert(ra::pick_driver<TI<0>, UU<ra::RANK_ANY>>::value==1, "bad match 6g");
  85. static_assert(ra::pick_driver<UU<ra::RANK_ANY>, TI<0>>::value==0, "bad match 6h");
  86. static_assert(ra::driver_index<TI<0>, UU<ra::RANK_ANY>>::value==1, "bad match 6i");
  87. static_assert(ra::driver_index<UU<ra::RANK_ANY>, TI<0>>::value==0, "bad match 6j");
  88. static_assert(ra::driver_index<UU<2>, UU<ra::RANK_ANY>, TI<0>>::value==1, "bad match 6k");
  89. static_assert(ra::driver_index<UU<1>, UU<2>, UU<3>>::value==2, "bad match 6l");
  90. static_assert(ra::driver_index<UU<2>, TI<0>, UU<ra::RANK_ANY>>::value==2, "bad match 6m");
  91. // dynamic vs static size, both static rank
  92. static_assert(ra::pick_driver<UU<3>, SM3>::value==1, "static rank, dynamic vs static size");
  93. // dynamic rank vs static size & rank
  94. static_assert(ra::pick_driver<UU<ra::RANK_ANY>, SM1 >::value==0, "bad match 7a");
  95. static_assert(ra::pick_driver<SM1, UU<ra::RANK_ANY> >::value==1, "bad match 7b");
  96. static_assert(ra::pick_driver<UU<ra::RANK_ANY>, SM2 >::value==0, "bad match 7c");
  97. static_assert(ra::pick_driver<SM2, UU<ra::RANK_ANY> >::value==1, "bad match 7d");
  98. // more cases with +2 candidates.
  99. static_assert(ra::driver_index<UU<3>, UU<1>, TI<0>>::value==0, "bad match 7b");
  100. static_assert(ra::driver_index<TI<0>, UU<3>, UU<1>>::value==1, "bad match 7c");
  101. static_assert(ra::driver_index<UU<1>, TI<0>, UU<3>>::value==2, "bad match 7d");
  102. static_assert(ra::driver_index<UU<1>, TI<0>, UU<3>>::value==2, "bad match 7e");
  103. }
  104. return tr.summary();
  105. }