outer.cc 718 B

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