old.cc 5.6 KB

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