ra-5.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // -*- mode: c++; coding: utf-8 -*-
  2. /// @file ra-5.cc
  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.cc.
  10. // Caused by d139794396a0d51dc0c25b0b03b2a2ef0e2760b5 : Remove set() from cell_iterator, cell_iterator_small.
  11. #include "ra/ra.hh"
  12. #include "ra/test.hh"
  13. #include "ra/mpdebug.hh"
  14. #include <iostream>
  15. using std::cout, std::endl, ra::TestRecorder;
  16. int main()
  17. {
  18. TestRecorder tr(std::cout);
  19. {
  20. ra::Big<int, 1> b = { 2, 1 };
  21. ra::Big<int, 2> A({3, 5}, ra::_0 - ra::_1);
  22. ra::Big<int, 2> F({2, 5}, 0);
  23. // 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().
  24. // This seems unnecessary; I should be able to create a single cell_iterator and just bump a pointer as I move through b. Hmm.
  25. iter<-1>(F) = b*A(b);
  26. int Fcheck[2][5] = { {4, 2, 0, -2, -4}, {1, 0, -1, -2, -3} };
  27. tr.test_eq(Fcheck, F);
  28. }
  29. // They why: if x(0) is a temp, as in here, cell_iterator needs a copy of x(0).dim.
  30. // This is achieved by forwarding in start() -> iter() -> View.iter().
  31. {
  32. auto demo = [](auto & x)
  33. {
  34. return iter<0>(x(0));
  35. };
  36. ra::Big<int, 2> A({3, 5}, 0);
  37. auto z = demo(A);
  38. tr.test_eq(5, z.dim[0].size);
  39. tr.test_eq(false, std::is_reference_v<decltype(z)::Dimv>);
  40. auto y = A(0);
  41. auto yi = iter<0>(y);
  42. tr.test_eq(true, std::is_reference_v<decltype(yi)::Dimv>);
  43. }
  44. // const/nonconst begin :p
  45. {
  46. ra::Big<int> A({2, 3}, 3);
  47. auto const b = A();
  48. int x[6] = { 0, 0, 0, 0, 0, 0 };
  49. std::copy(b.begin(), b.end(), x);
  50. tr.test_eq(3, ra::start(x));
  51. }
  52. return tr.summary();
  53. }