ra-6.cc 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Regression test (3).
  3. // (c) Daniel Llorens - 2014-2015
  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. // Regression test for a bug with > 2 non-beatable selectors. The bug was due to
  9. // bad assumptions in ra::Iota::adv() and ra::Ptr::adv().
  10. #include "ra/test.hh"
  11. using std::cout, std::endl, ra::TestRecorder;
  12. int main()
  13. {
  14. int N = 4;
  15. ra::Big<float, 3> A({N, N, N}, ra::_2 + ra::_1*4 + ra::_0*16);
  16. ra::Big<float, 2> B({N, N}, ra::_1 + ra::_0*4);
  17. ra::Big<float, 1> C({N}, ra::_0);
  18. cout << "A: " << N << endl;
  19. cout << "B: " << N << endl;
  20. cout << "C: " << N << endl;
  21. // beatable.
  22. auto i = ra::iota(2, 1);
  23. // making unbeatable on purpose, but still depends on Iota's internal counter.
  24. auto j = ra::map([](int i) { return i; }, i);
  25. // naturally unbeatable.
  26. ra::Small<int, 2> k { 1, 2 };
  27. auto l = std::array<int, 2> { 1, 2 };
  28. auto ll = ra::ptr(l);
  29. // auto ll = ra::ptr(std::array<int, 2> { 1, 2 }); // FIXME find a way to forbid this [ra9]
  30. cout << "X0: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, i, i, i) << endl;
  31. cout << "X1: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, j, j, j) << endl;
  32. cout << "X2: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, k, k, k) << endl;
  33. cout << "X3: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, ra::ptr(l), ra::ptr(l), ra::ptr(l)) << endl;
  34. cout << "X4: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, l, l, l) << endl;
  35. cout << "X5: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, ll, ll, ll) << endl;
  36. cout << endl;
  37. cout << "Y0: " << ra::from(A, i, i, i) << endl;
  38. cout << "Y1: " << ra::from(A, j, j, j) << endl;
  39. cout << "Y2: " << ra::from(A, k, k, k) << endl;
  40. cout << "Y3: " << ra::from(A, ra::ptr(l), ra::ptr(l), ra::ptr(l)) << endl;
  41. cout << "Y4: " << ra::from(A, l, l, l) << endl;
  42. cout << "Y5: " << ra::from(A, ll, ll, ll) << endl;
  43. cout << B(i, i) << endl;
  44. TestRecorder tr(std::cout);
  45. tr.section("subs 1");
  46. {
  47. ra::Small<int, 2> ref1 {1, 2};
  48. tr.test_eq(ref1, C(i));
  49. tr.test_eq(ref1, C(j));
  50. tr.test_eq(ref1, C(k));
  51. tr.test_eq(ref1, C(ra::ptr(l)));
  52. tr.info("ll").test_eq(ref1, C(ll));
  53. }
  54. tr.section("subs 2");
  55. {
  56. ra::Small<int, 2, 2> ref2 {5, 6, 9, 10};
  57. tr.test_eq(ref2, B(i, i));
  58. tr.test_eq(ref2, B(j, j));
  59. tr.test_eq(ref2, B(k, k));
  60. tr.test_eq(ref2, B(ra::ptr(l), ra::ptr(l)));
  61. tr.test_eq(ref2, B(l, l));
  62. tr.info("ll").test_eq(ref2, B(ll, ll));
  63. }
  64. // TODO have a proper rank / shape match error when comparing these with ref3
  65. tr.section("subs 3");
  66. {
  67. ra::Small<int, 2, 2, 2> ref3 {21, 22, 25, 26, 37, 38, 41, 42};
  68. tr.test_eq(ref3, A(i, i, i));
  69. tr.test_eq(ref3, A(j, j, j));
  70. tr.test_eq(ref3, A(k, k, k));
  71. tr.test_eq(ref3, A(ra::ptr(l), ra::ptr(l), ra::ptr(l)));
  72. tr.test_eq(ref3, A(l, l, l));
  73. tr.info("ll").test_eq(ref3, A(ll, ll, ll));
  74. }
  75. return tr.summary();
  76. }