ra-13.cc 1.7 KB

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