9 #include <xtensor/xarray.hpp>
10 #include <xtensor/xfixed.hpp>
11 #include <xtensor/xtensor.hpp>
24 template <
typename U,
typename V>
25 xt::xtensor<typename U::value_type, 2>
outer(
const U& u,
const V& v)
27 xt::xtensor<typename U::value_type, 2> results({u.size(), v.size()});
28 for (std::size_t i = 0; i < u.size(); i++)
29 for (std::size_t j = 0; j < u.size(); j++)
30 results(i, j) = u(i) * v(j);
39 template <
typename U,
typename V>
40 xt::xtensor_fixed<typename U::value_type, xt::xshape<3>>
cross(
const U& u,
43 assert(u.size() == 3);
44 assert(v.size() == 3);
45 return {u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2],
46 u[0] * v[1] - u[1] * v[0]};
53 template <
typename U,
typename V>
54 xt::xtensor<typename U::value_type, 2>
dot(
const U& A,
const V& B)
56 xt::xtensor<typename U::value_type, 2> C
57 = xt::zeros<typename U::value_type>({A.shape(0), B.shape(1)});
59 assert(A.shape(1) == B.shape(0));
60 for (std::size_t i = 0; i < A.shape(0); i++)
61 for (std::size_t j = 0; j < B.shape(1); j++)
62 for (std::size_t k = 0; k < A.shape(1); k++)
63 C(i, j) += A(i, k) * B(k, j);
71 std::pair<xt::xtensor<double, 1>,
72 xt::xtensor<double, 2, xt::layout_type::column_major>>
73 eigh(
const xt::xtensor<double, 2>& A);
79 xt::xarray<double, xt::layout_type::column_major>
80 solve(
const xt::xtensor<double, 2>& A,
const xt::xarray<double>& B);