outer.cc 777 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/examples - Outer product
  3. // Daniel Llorens - 2015, 2019
  4. // Adapted from blitz++/examples/outer.cpp
  5. #include "ra/ra.hh"
  6. #include <iostream>
  7. using std::cout, std::endl, std::flush;
  8. int main()
  9. {
  10. ra::Big<float,1> x { 1, 2, 3, 4 }, y { 1, 0, 0, -1 };
  11. ra::Big<float,2> A({4,4}, 99.);
  12. x = { 1, 2, 3, 4 };
  13. y = { 1, 0, 0, -1 };
  14. constexpr auto i = ra::iota<0>();
  15. constexpr auto j = ra::iota<1>();
  16. A = x(i) * y(j);
  17. cout << A << endl;
  18. // [ra] alternative I
  19. cout << from(std::multiplies<float>(), x, y) << endl;
  20. // [ra] alternative II by axis insertion
  21. cout << (x * y(ra::insert<1>)) << endl;
  22. // [ra] alternative II by transposing
  23. cout << (x * transpose<1>(y)) << endl;
  24. return 0;
  25. }