ra-16.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra/test - Spurious out of range error with gcc11 -O3 I can't reproduce
  3. // (c) Daniel Llorens - 2024
  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 <iostream>
  9. #include "ra/test.hh"
  10. using real = float;
  11. using real2 = ra::Small<real, 2>;
  12. using real3 = ra::Small<real, 3>;
  13. using real23 = ra::Small<real, 2, 3>;
  14. using real32 = ra::Small<real, 3, 2>;
  15. using complex = std::complex<float>;
  16. template <class Tu, class TR>
  17. constexpr void
  18. sph22c_s_op(Tu const & u, TR & R)
  19. {
  20. real ct = cos(u[0]), st = sin(u[0]), cp = cos(u[1]), sp = sin(u[1]);
  21. R = { ct*cp, -sp, ct*sp, cp, -st, real(0) };
  22. }
  23. constexpr real2
  24. c2s2(real3 const c)
  25. {
  26. real2 s;
  27. real p2 = ra::sqr(c[0])+ra::sqr(c[1]);
  28. s[0] = atan2(sqrt(p2), c[2]);
  29. s[1] = atan2(c[1], c[0]);
  30. return s;
  31. }
  32. ra::Big<real, 2> rr = { { 0., 0., 1. } };
  33. ra::Big<complex, 3> a({20, 1, 3}, 0.);
  34. ra::Big<complex, 2> dip({20, 2}, 1.);
  35. void
  36. far(real const f, ra::ViewBig<real, 2> const & rr, ra::ViewBig<complex, 3> & a)
  37. {
  38. real A = 1., m = .5, n = .4;
  39. for_each([&](auto && r, auto & a) {
  40. a = real(0);
  41. if (r[2]>0) {
  42. real32 op;
  43. sph22c_s_op(c2s2(r), op);
  44. real pn = A*std::pow(r[2], n);
  45. real23 opmn = transpose<1, 0>(op)*real2 { pn*std::pow(r[2], m-1), pn };
  46. gemm(dip, gemm(op, opmn), a);
  47. }
  48. }, iter<1>(rr), iter<2>(ra::transpose<1, 0, 2>(a)));
  49. }
  50. int main()
  51. {
  52. ra::TestRecorder tr(std::cout);
  53. far(20e9, rr, a);
  54. tr.test_eq(complex(40.), sum(a));
  55. return tr.summary();
  56. }