nested.cc 752 B

1234567891011121314151617181920212223242526272829303132333435
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/examples - Nested heterogeneous arrays
  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<ra::Big<int, 1>, 1> A({3}, ra::none);
  11. A(0).resize(3);
  12. A(0) = { 0, 1, 2 };
  13. A(1).resize(5);
  14. A(1) = { 5, 7, 18, 2, 1 };
  15. A(2).resize(4);
  16. A(2) = pow(ra::_0+1, 2);
  17. cout << "A = " << A << endl;
  18. // A = [ [ 0 1 2 ] [ 5 7 18 2 1 ] [ 1 4 9 16 ] ]
  19. // [ra] Note that this is written with the shape in front, so (without the brackets)
  20. // [3 [3 [0 1 2]] [5 [5 7 18 2 1]] [4 [1 4 9 16]]]
  21. // Therefore, the type of A must be known to read this back in.
  22. return 0;
  23. }