8 #include <xtensor/xtensor.hpp>
9 #include <xtensor/xview.hpp>
10 #include <xtl/xspan.hpp>
66 std::vector<std::size_t>
117 template <
typename E>
119 const xtl::span<E>& data, std::size_t offset = 0,
120 std::size_t block_size = 1)
122 for (std::size_t b = 0; b < block_size; ++b)
124 for (std::size_t i = 0; i < perm.size(); ++i)
126 std::swap(data[block_size * (offset + i) + b],
127 data[block_size * (offset + perm[i]) + b]);
135 template <
typename E>
137 const xtl::span<E>& data,
138 std::size_t offset = 0,
139 std::size_t block_size = 1)
141 const std::size_t dim = perm.size();
142 const std::size_t data_size = data.size() / block_size;
143 for (std::size_t b = 0; b < block_size; ++b)
145 for (std::size_t i = 0; i < dim; ++i)
147 std::swap(data[data_size * b + offset + i],
148 data[data_size * b + offset + perm[i]]);
246 std::tuple<std::vector<std::size_t>, std::vector<double>,
247 xt::xtensor<double, 2>>
310 template <
typename T,
typename E>
311 void apply_matrix(
const std::tuple<std::vector<std::size_t>, std::vector<T>,
312 xt::xtensor<T, 2>>& matrix,
313 const xtl::span<E>& data, std::size_t offset = 0,
314 std::size_t block_size = 1)
316 const std::vector<std::size_t>& v_size_t = std::get<0>(matrix);
317 const std::vector<T>& v_t = std::get<1>(matrix);
318 const xt::xtensor<T, 2>& M = std::get<2>(matrix);
320 const std::size_t dim = v_size_t.size();
322 for (std::size_t b = 0; b < block_size; ++b)
324 for (std::size_t i = 0; i < dim; ++i)
326 data[block_size * (offset + i) + b] *= v_t[i];
327 for (std::size_t j = 0; j < dim; ++j)
329 data[block_size * (offset + i) + b]
330 += M(i, j) * data[block_size * (offset + j) + b];
339 template <
typename T,
typename E>
341 const std::tuple<std::vector<std::size_t>, std::vector<T>,
342 xt::xtensor<T, 2>>& matrix,
343 const xtl::span<E>& data, std::size_t offset = 0,
344 std::size_t block_size = 1)
346 const std::vector<std::size_t>& v_size_t = std::get<0>(matrix);
347 const std::vector<T>& v_t = std::get<1>(matrix);
348 const xt::xtensor<T, 2>& M = std::get<2>(matrix);
350 const std::size_t dim = v_size_t.size();
351 const std::size_t data_size = data.size() / block_size;
353 for (std::size_t b = 0; b < block_size; ++b)
355 for (std::size_t i = 0; i < dim; ++i)
357 data[data_size * b + offset + i] *= v_t[i];
358 for (std::size_t j = 0; j < dim; ++j)
360 data[data_size * b + offset + i]
361 += M(i, j) * data[data_size * b + offset + j];