ra-5.C 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // -*- mode: c++; coding: utf-8 -*-
  2. /// @file ra-5.C
  3. /// @brief A regression test.
  4. // (c) Daniel Llorens - 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. // Regression test for a bug ... caught first in fold_mat @ array.C.
  10. // Caused by d139794396a0d51dc0c25b0b03b2a2ef0e2760b5 : Remove set() from cell_iterator, cell_iterator_small.
  11. #include "ra/operators.H"
  12. #include "ra/io.H"
  13. #include "ra/test.H"
  14. #include "ra/mpdebug.H"
  15. #include <iostream>
  16. using std::cout, std::endl;
  17. // template <class T, class Enable=void> struct THECHECK { constexpr static bool value = false; };
  18. // template <class T> struct THECHECK<T, std::enable_if_t<mp::exists<decltype(T::dim)>>> { constexpr static bool value = true; };
  19. int main()
  20. {
  21. TestRecorder tr(std::cout);
  22. {
  23. ra::Big<int, 1> b = { 2, 1 };
  24. ra::Big<int, 2> A({3, 5}, ra::_0 - ra::_1);
  25. ra::Big<int, 2> F({2, 5}, 0);
  26. // This creates View & cell_iterator on each call of A(b(0) ...) as the driver is b and A is handled as a generic object with operator().
  27. // This seems unnecessary; I should be able to create a single cell_iterator and just bump a pointer as I move through b. Hmm.
  28. iter<-1>(F) = b*A(b);
  29. int Fcheck[2][5] = { {4, 2, 0, -2, -4}, {1, 0, -1, -2, -3} };
  30. tr.test_eq(Fcheck, F);
  31. }
  32. // They why: if x(0) is a temp, as in here, cell_iterator needs a copy of x(0).dim.
  33. // This is achieved by forwarding in start() -> iter() -> View.iter().
  34. {
  35. auto demo = [](auto & x)
  36. {
  37. return iter<0>(x(0));
  38. };
  39. ra::Big<int, 2> A({3, 5}, 0);
  40. auto z = demo(A);
  41. tr.test_eq(5, z.dim[0].size);
  42. tr.test_eq(false, std::is_reference_v<decltype(z)::Dimv>);
  43. auto y = A(0);
  44. auto yi = iter<0>(y);
  45. tr.test_eq(true, std::is_reference_v<decltype(yi)::Dimv>);
  46. }
  47. // const/nonconst begin :p
  48. {
  49. ra::Big<int> A({2, 3}, 3);
  50. auto const b = A();
  51. int x[6] = { 0, 0, 0, 0, 0, 0 };
  52. std::copy(b.begin(), b.end(), x);
  53. tr.test_eq(3, ra::start(x));
  54. }
  55. return tr.summary();
  56. }