test-ra-6.C 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // (c) Daniel Llorens - 2014-2015
  2. // This library is free software; you can redistribute it and/or modify it under
  3. // the terms of the GNU Lesser General Public License as published by the Free
  4. // Software Foundation; either version 3 of the License, or (at your option) any
  5. // later version.
  6. // Regression test for a bug with > 2 non-beatable selectors. The bug was due to
  7. // bad assumptions in ra::Iota::adv() and ra::Vector::adv().
  8. #include "ra/ra-operators.H"
  9. #include "ra/test.H"
  10. using std::cout; using std::endl;
  11. int main()
  12. {
  13. int N = 4;
  14. ra::Owned<float, 3> A({N, N, N}, ra::_2 + ra::_1*4 + ra::_0*16);
  15. ra::Owned<float, 2> B({N, N}, ra::_1 + ra::_0*4);
  16. ra::Owned<float, 1> C({N}, ra::_0);
  17. cout << "A: " << N << endl;
  18. cout << "B: " << N << endl;
  19. cout << "C: " << N << endl;
  20. // beatable.
  21. ra::Iota<int> i(2, 1);
  22. // making unbeatable on purpose, but still depends on internal Iota counter.
  23. auto j = ra::map([](int i) { return i; }, i);
  24. // naturally unbeatable.
  25. ra::Small<int, 2> k { 1, 2 };
  26. auto l = std::array<int, 2> {{ 1, 2 }};
  27. auto ll = ra::vector(l);
  28. cout << "X0: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, i, i, i) << endl;
  29. cout << "X1: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, j, j, j) << endl;
  30. cout << "X2: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, k, k, k) << endl;
  31. cout << "X3: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, ra::vector(l), ra::vector(l), ra::vector(l)) << endl;
  32. cout << "X4: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, ll, ll, ll) << endl;
  33. cout << endl;
  34. cout << "Y0: " << ra::from(A, i, i, i) << endl;
  35. cout << "Y1: " << ra::from(A, j, j, j) << endl;
  36. cout << "Y2: " << ra::from(A, k, k, k) << endl;
  37. cout << "Y3: " << ra::from(A, ra::vector(l), ra::vector(l), ra::vector(l)) << endl;
  38. cout << "Y4: " << ra::from(A, ll, ll, ll) << endl;
  39. cout << B(i, i) << endl;
  40. TestRecorder tr(std::cout);
  41. {
  42. ra::Small<int, 2, 2, 2> ref3 {21, 22, 25, 26, 37, 38, 41, 42};
  43. tr.test_eq(ref3, A(i, i, i));
  44. // tr.test_eq(ref3, A(j, j, j));
  45. tr.test_eq(ref3, A(k, k, k));
  46. tr.test_eq(ref3, A(ra::vector(l), ra::vector(l), ra::vector(l)));
  47. tr.test_eq(ref3, A(ll, ll, ll));
  48. // @TODO have a proper rank / shape match error when comparing these with ref3
  49. ra::Small<int, 2, 2> ref2 {5, 6, 9, 10};
  50. tr.test_eq(ref2, B(i, i));
  51. tr.test_eq(ref2, B(j, j));
  52. tr.test_eq(ref2, B(k, k));
  53. tr.test_eq(ref2, B(ra::vector(l), ra::vector(l)));
  54. tr.test_eq(ref2, B(ll, ll));
  55. // @TODO have a proper rank / shape match error when comparing these with ref3
  56. ra::Small<int, 2> ref1 {1, 2};
  57. tr.test_eq(ref1, C(i));
  58. tr.test_eq(ref1, C(j));
  59. tr.test_eq(ref1, C(k));
  60. tr.test_eq(ref1, C(ra::vector(l)));
  61. tr.test_eq(ref1, C(ll));
  62. }
  63. return tr.summary();
  64. }