test-large.C 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // (c) Daniel Llorens - 2017
  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. /// @file test-large.C
  7. /// @brief Tests specific to WithStorage.
  8. #include <iostream>
  9. #include <iterator>
  10. #include "ra/operators.H"
  11. #include "ra/io.H"
  12. #include "ra/view-ops.H"
  13. #include "ra/format.H"
  14. #include "ra/test.H"
  15. using std::cout; using std::endl; using std::flush;
  16. int main()
  17. {
  18. TestRecorder tr;
  19. tr.section("push_back");
  20. {
  21. using int2 = ra::Small<int, 2>;
  22. std::vector<int2> a;
  23. a.push_back({1, 2});
  24. ra::Big<int2, 1> b;
  25. b.push_back({1, 2});
  26. int2 check[1] = {{1, 2}};
  27. tr.test_eq(check, ra::start(a));
  28. tr.test_eq(check, b);
  29. }
  30. tr.section("behavior of forced Fortran array");
  31. {
  32. ra::Big<int, 2> a ({2, 3}, {0, 1, 2, 3, 4, 5});
  33. ra::Big<int, 2> b ({2, 3}, {0, 1, 2, 3, 4, 5});
  34. auto c = transpose({1, 0}, ra::View<int, 2>({3, 2}, a.data()));
  35. a.dim = c.dim;
  36. for (int k=0; k!=c.rank(); ++k) {
  37. std::cout << "CSTRIDE " << k << " " << c.stride(k) << std::endl;
  38. std::cout << "CSIZE " << k << " " << c.size(k) << std::endl;
  39. }
  40. cout << endl;
  41. for (int k=0; k!=a.rank(); ++k) {
  42. std::cout << "ASTRIDE " << k << " " << a.stride(k) << std::endl;
  43. std::cout << "ASIZE " << k << " " << a.size(k) << std::endl;
  44. }
  45. cout << endl;
  46. c = b;
  47. // FIXME this clobber the strides in a, which is surprising -> WithStorage should behave as View.
  48. a = b;
  49. for (int k=0; k!=c.rank(); ++k) {
  50. std::cout << "CSTRIDE " << k << " " << c.stride(k) << std::endl;
  51. std::cout << "CSIZE " << k << " " << c.size(k) << std::endl;
  52. }
  53. cout << endl;
  54. for (int k=0; k!=a.rank(); ++k) {
  55. std::cout << "ASTRIDE " << k << " " << a.stride(k) << std::endl;
  56. std::cout << "ASIZE " << k << " " << a.size(k) << std::endl;
  57. }
  58. cout << endl;
  59. std::cout << "a: " << a << std::endl;
  60. std::cout << "b: " << b << std::endl;
  61. std::cout << "c: " << c << std::endl;
  62. }
  63. return tr.summary();
  64. }