cast.cc 737 B

1234567891011121314151617181920212223242526272829303132
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // Adapted from blitz++/examples/cast.cpp
  3. // Daniel Llorens - 2015
  4. #include "ra/ra.hh"
  5. #include <iostream>
  6. using std::cout, std::endl;
  7. int main()
  8. {
  9. ra::Big<int, 1> A { 1, 2, 3, 5 }, B { 2, 2, 2, 7 };
  10. ra::Big<float, 1> C({4}, 0);
  11. // OT: this is a peculiarity of ra:: : C had to be initialized with the right
  12. // size or C = A/B below will fail because of a shape mismatch. This is so C =
  13. // ... works the same way whether C is an owned type or a view. You can always
  14. // initialize with a new object:
  15. {
  16. ra::Big<float, 1> D;
  17. D = ra::Big<float, 1>(A / B);
  18. }
  19. C = A / B;
  20. cout << C << endl;
  21. C = A / ra::cast<float>(B);
  22. cout << C << endl;
  23. return 0;
  24. }