cast.C 733 B

123456789101112131415161718192021222324252627282930313233
  1. // Daniel Llorens - 2015
  2. // Adapted from blitz++/examples/cast.cpp
  3. #include "ra/operators.H"
  4. #include "ra/io.H"
  5. #include <iostream>
  6. using std::cout; using 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. }