ra-13.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Constructing views.
  3. // (c) Daniel Llorens - 2013-2015
  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. #include <numeric>
  9. #include <iostream>
  10. #include <iterator>
  11. #include "ra/test.hh"
  12. #include "mpdebug.hh"
  13. using std::cout, std::endl, std::flush, ra::TestRecorder;
  14. // Originally from ra-0.cc, but triggered need for fixes in Container::init() for gcc 10.1.
  15. int main()
  16. {
  17. TestRecorder tr(std::cout);
  18. tr.section("construct View<> from sizes AND steps");
  19. {
  20. int p[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  21. int * pp = &p[0]; // force pointer decay in case we ever enforce p's shape
  22. // default giving sizes only
  23. ra::View<int> a(ra::Small<int, 2>({5, 2}), pp);
  24. tr.test_eq(ra::_0*2 + ra::_1*1 + 1, a);
  25. // same as default
  26. ra::View<int> b(ra::Small<ra::Dim, 2>({ra::Dim{5, 2}, ra::Dim{2, 1}}), pp);
  27. tr.test_eq(ra::_0*2 + ra::_1*1 + 1, b);
  28. // col major
  29. ra::View<int> c(ra::Small<ra::Dim, 2>({ra::Dim{5, 1}, ra::Dim{2, 5}}), pp);
  30. tr.test_eq(ra::_0*1 + ra::_1*5 + 1, c);
  31. // taking expr - generic col major
  32. ra::View<int> d(ra::pack<ra::Dim>(ra::Small<int, 3> {5, 1, 2}, ra::Small<int, 3> {1, 0, 5}), pp);
  33. tr.test_eq(ra::_0*1 + ra::_1*0 + ra::_2*5 + 1, d);
  34. }
  35. return tr.summary();
  36. }