old.cc 5.4 KB

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