9 #include <xtensor/xtensor.hpp>
10 #include <xtl/xspan.hpp>
64 std::vector<std::size_t>
118 template <
typename E>
120 const xtl::span<E>& data, std::size_t offset = 0,
121 std::size_t block_size = 1)
123 for (std::size_t b = 0; b < block_size; ++b)
125 for (std::size_t i = 0; i < perm.size(); ++i)
127 std::swap(data[block_size * (offset + i) + b],
128 data[block_size * (offset + perm[i]) + b]);
139 template <
typename E>
141 const xtl::span<E>& data,
142 std::size_t offset = 0,
143 std::size_t block_size = 1)
145 const std::size_t dim = perm.size();
146 const std::size_t data_size
147 = (data.size() + (dim < block_size ? block_size - dim : 0)) / block_size;
148 for (std::size_t b = 0; b < block_size; ++b)
150 for (std::size_t i = 0; i < dim; ++i)
152 std::swap(data[data_size * b + offset + i],
153 data[data_size * b + offset + perm[i]]);
251 std::tuple<std::vector<std::size_t>, std::vector<double>,
252 xt::xtensor<double, 2>>
318 template <
typename T,
typename E>
319 void apply_matrix(
const std::tuple<std::vector<std::size_t>, std::vector<T>,
320 xt::xtensor<T, 2>>& matrix,
321 const xtl::span<E>& data, std::size_t offset = 0,
322 std::size_t block_size = 1)
324 const std::vector<std::size_t>& v_size_t = std::get<0>(matrix);
325 const std::vector<T>& v_t = std::get<1>(matrix);
326 const xt::xtensor<T, 2>& M = std::get<2>(matrix);
328 const std::size_t dim = v_size_t.size();
330 for (std::size_t b = 0; b < block_size; ++b)
332 for (std::size_t i = 0; i < dim; ++i)
334 data[block_size * (offset + i) + b] *= v_t[i];
335 for (std::size_t j = 0; j < dim; ++j)
337 data[block_size * (offset + i) + b]
338 += M(i, j) * data[block_size * (offset + j) + b];
350 template <
typename T,
typename E>
352 const std::tuple<std::vector<std::size_t>, std::vector<T>,
353 xt::xtensor<T, 2>>& matrix,
354 const xtl::span<E>& data, std::size_t offset = 0,
355 std::size_t block_size = 1)
357 const std::vector<std::size_t>& v_size_t = std::get<0>(matrix);
358 const std::vector<T>& v_t = std::get<1>(matrix);
359 const xt::xtensor<T, 2>& M = std::get<2>(matrix);
361 const std::size_t dim = v_size_t.size();
362 const std::size_t data_size
363 = (data.size() + (dim < block_size ? block_size - dim : 0)) / block_size;
365 for (std::size_t b = 0; b < block_size; ++b)
367 for (std::size_t i = 0; i < dim; ++i)
369 data[data_size * b + offset + i] *= v_t[i];
370 for (std::size_t j = 0; j < dim; ++j)
372 data[data_size * b + offset + i]
373 += M(i, j) * data[data_size * b + offset + j];