cast.cc 824 B

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