#include #include "xtensor/xarray.hpp" #include "xtensor/xio.hpp" #include "xtensor/xview.hpp" xt::xarray arr1 {{1.0, 2.0, 3.0}, {2.0, 5.0, 7.0}, {2.0, 5.0, 7.0}}; xt::xarray arr2 {5.0, 6.0, 7.0}; xt::view(arr1, 1) + arr2 arr1 #include #include "xtensor/xarray.hpp" #include "xtensor/xio.hpp" xt::xarray arr {1, 2, 3, 4, 5, 6, 7, 8, 9}; arr.reshape({3, 3}); arr #include #include "xtensor/xarray.hpp" #include "xtensor/xmath.hpp" #include "xtensor/xio.hpp" xt::xarray arr3 {1.0, 2.0, 3.0}; xt::xarray arr4 {4, 5, 6, 7}; arr4.reshape({4, 1}); xt::pow(arr3, arr4) #include #include "xtensor/xrandom.hpp" xt::xarray arr5 = xt::random::randn({4, 3}); arr5 xt::random::randn({5, 3, 8, 10}) > 0.2 #include "xtensor/xbuilder.hpp" xt::xarray ar = xt::linspace(0.0, 10.0, 12); ar.reshape({4, 3}); ar xt::xarray fones = xt::ones({2, 2}); fones xt::arange(1569325055) #include #include "xtensor/xbroadcast.hpp" xt::broadcast(xt::linspace(0.0, 10.0, 4), std::vector({3, 4})) #include xt::xarray frand = xt::random::randn({2, 2}); // begin() and end() provide and iterator pair iterating over the xexpression in a row-major fashion std::cout << std::accumulate(frand.begin(), frand.end(), 0.0); frand // begin(shape) and end(shape) provide and iterator pair iterating // over the xexpression broadcasted to the prescrived shape in a row-major fashion std::vector shape = {3, 2, 2}; std::cout << std::accumulate(frand.begin(shape), frand.end(shape), 0.0); #include "xtensor-blas/xlinalg.hpp" xt::xtensor m = {{1.5, 0.5}, {0.7, 1.0}}; std::cout << "Matrix rank: " << std::endl << xt::linalg::matrix_rank(m); std::cout << "Matrix inverse: " << std::endl << xt::linalg::inv(m); std::cout << "Eigen values: " << std::endl << xt::linalg::eigvals(m); xt::xarray arg1 = xt::arange(9); xt::xarray arg2 = xt::arange(18); arg1.reshape({3, 3}); arg2.reshape({2, 3, 3}); std::cout << xt::linalg::dot(arg1, arg2) << std::endl;