Skip to content

Instantly share code, notes, and snippets.

@dsuess
Created March 27, 2019 07:18
Show Gist options
  • Save dsuess/aebc43efeb07e56f80890e2135ce1de3 to your computer and use it in GitHub Desktop.
Save dsuess/aebc43efeb07e56f80890e2135ce1de3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "xtensor/xio.hpp"
#include "xtensor/xrandom.hpp"
#include "xtensor/xtensor.hpp"
#include "xtensor/xview.hpp"
template <class E>
auto transform(E& x) {
x *= 2;
}
using farray = xt::xtensor<float, 2, xt::layout_type::column_major>;
int main() {
const farray x_orig = xt::random::randn<float>({2, 2});
using namespace xt::placeholders;
farray x_view = x_orig;
auto x1 = xt::view(x_view, xt::all(), xt::range(_, 1));
transform(x1);
auto x2 = xt::view(x_view, xt::all(), xt::range(1, _));
transform(x2);
std::cout << "Same with views? " << xt::allclose(x_view, 2 * x_orig)
<< std::endl;
std::cout << 2 * x_orig << std::endl;
std::cout << "--------------------" << std::endl;
std::cout << x_view << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment