nested.C 725 B

12345678910111213141516171819202122232425262728293031323334
  1. // Daniel Llorens - 2015
  2. // Adapted from blitz++/examples/cast.cpp
  3. // Nested heterogeneous arrays
  4. #include "ra/ra-operators.H"
  5. #include <iostream>
  6. using std::cout; using std::endl;
  7. int main()
  8. {
  9. ra::Owned<ra::Owned<int, 1>, 1> A({3}, ra::unspecified);
  10. A(0).resize(3);
  11. A(0) = { 0, 1, 2 };
  12. A(1).resize(5);
  13. A(1) = { 5, 7, 18, 2, 1 };
  14. A(2).resize(4);
  15. A(2) = pow(ra::_0+1, 2);
  16. cout << "A = " << A << endl;
  17. // A = [ [ 0 1 2 ] [ 5 7 18 2 1 ] [ 1 4 9 16 ] ]
  18. // [ra] Note that this is written with the shape in front, so (without the brackets)
  19. // [3 [3 [0 1 2]] [5 [5 7 18 2 1]] [4 [1 4 9 16]]]
  20. // Therefore, the type of A must be known to read this back in.
  21. return 0;
  22. }