old.cc 5.6 KB

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