ra-5.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Regression tests (2).
  3. // (c) Daniel Llorens - 2023
  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 ... caught first in fold_mat @ array.cc.
  9. // Caused by d139794396a0d51dc0c25b0b03b2a2ef0e2760b5 : Remove set() from CellBig, CellSmall.
  10. #include <iostream>
  11. #include "ra/test.hh"
  12. #include "mpdebug.hh"
  13. using std::cout, std::endl, ra::TestRecorder;
  14. int main()
  15. {
  16. TestRecorder tr(std::cout);
  17. // [ra14] A(b) which is from(A, b) can require CellBig to copy its source Dimv.
  18. tr.section("Big");
  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 & CellBig on each call of A(b(0) ...) as the driver is b and A is handled as generic object with operator().
  24. // But I should be able to create a single CellBig 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. // Equivalent for Small is static so no such issues.
  30. tr.section("Small");
  31. {
  32. ra::Small<int, 2> b = { 2, 1 };
  33. ra::Small<int, 3, 5> A = ra::_0 - ra::_1;
  34. ra::Small<int, 2, 5> F = 0;
  35. iter<-1>(F) = b*A(b);
  36. int Fcheck[2][5] = { {4, 2, 0, -2, -4}, {1, 0, -1, -2, -3} };
  37. tr.test_eq(Fcheck, F);
  38. }
  39. // Why: if x(0) is a temp, as in here, CellBig needs a copy of x(0).dim.
  40. // This is achieved by forwarding in start() -> iter() -> View.iter().
  41. tr.section("CellBig handling of temps");
  42. {
  43. auto demo = [](auto & x) { return iter<0>(x(0)); };
  44. ra::Big<int, 2> A({3, 5}, 0);
  45. auto z = demo(A);
  46. tr.test_eq(5, z.dimv[0].len);
  47. tr.test_eq(false, std::is_reference_v<decltype(z.dimv)>);
  48. auto y = A(0);
  49. auto yi = iter<0>(y);
  50. tr.test_eq(true, std::is_reference_v<decltype(yi.dimv)>);
  51. }
  52. // const/nonconst begin :p
  53. {
  54. ra::Big<int> A({2, 3}, 3);
  55. auto const b = A();
  56. int x[6] = { 0, 0, 0, 0, 0, 0 };
  57. std::ranges::copy(b.begin(), b.end(), x);
  58. tr.test_eq(3, ra::start(x));
  59. }
  60. return tr.summary();
  61. }