ra-12.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Exercise step(k) with k>=rank().
  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. #include <numeric>
  9. #include <iostream>
  10. #include <iterator>
  11. #include "ra/test.hh"
  12. using std::cout, std::endl, std::flush, ra::TestRecorder;
  13. int main()
  14. {
  15. TestRecorder tr(std::cout);
  16. tr.section("case I");
  17. {
  18. ra::Small<float, 2, 3> A {{1, 2, 3}, {1, 2, 3}};
  19. ra::Small<float, 2> B {-1, +1};
  20. ra::Small<float, 2, 3> C {{99, 99, 99}, {99, 99, 99}};
  21. C = A * B;
  22. ra::Small<float, 2> D = {0, 0};
  23. D += A * B;
  24. tr.test_eq(-6, D[0]);
  25. tr.test_eq(6, D[1]);
  26. }
  27. tr.section("case II");
  28. {
  29. ra::Big<float, 2> A {{1, 2, 3}, {1, 2, 3}};
  30. ra::Big<float, 1> B {-1, +1};
  31. ra::Big<float, 2> C({2, 3}, 99.);
  32. C = A * B;
  33. ra::Big<float, 1> D({2}, 0.);
  34. D += A * B;
  35. tr.test_eq(-6, D[0]);
  36. tr.test_eq(6, D[1]);
  37. }
  38. tr.section("case III");
  39. {
  40. ra::Big<float> A ({2, 3}, {1, 2, 3, 1, 2, 3});
  41. ra::Big<float> B {-1, +1};
  42. ra::Big<float> C({2, 3}, 99.);
  43. C = A * B;
  44. ra::Big<float> D({2}, 0.);
  45. D += A * B;
  46. tr.test_eq(-6, D[0]);
  47. tr.test_eq(6, D[1]);
  48. }
  49. return tr.summary();
  50. }