12 #include <type_traits>
23 template <
typename T,
typename =
void>
24 struct scalar_value_type
31 struct scalar_value_type<T, std::void_t<typename T::value_type>>
33 typedef typename T::value_type value_type;
37 using scalar_value_type_t =
typename scalar_value_type<T>::value_type;
140 template <
typename E>
142 std::size_t offset = 0, std::size_t block_size = 1)
144 for (std::size_t i = 0; i < perm.size(); ++i)
146 for (std::size_t b = 0; b < block_size; ++b)
148 std::swap(data[block_size * (offset + i) + b],
149 data[block_size * (offset + perm[i]) + b]);
155 template <
typename E>
157 std::span<E> data, std::span<const int> emap,
158 std::size_t block_size = 1)
160 for (std::size_t i = 0; i < perm.size(); ++i)
162 for (std::size_t b = 0; b < block_size; ++b)
164 std::swap(data[block_size * emap[i] + b],
165 data[block_size * emap[perm[i]] + b]);
176 template <
typename E>
178 std::span<E> data, std::size_t offset = 0,
179 std::size_t block_size = 1)
181 const std::size_t dim = perm.size();
182 const std::size_t data_size
183 = (data.size() + (dim < block_size ? block_size - dim : 0)) / block_size;
184 for (std::size_t b = 0; b < block_size; ++b)
186 for (std::size_t i = 0; i < dim; ++i)
188 std::swap(data[data_size * b + offset + i],
189 data[data_size * b + offset + perm[i]]);
210 template <std::
floating_po
int T>
211 std::vector<std::size_t>
214 return math::transpose_lu<T>(A);
250 template <
typename T,
typename E>
252 std::span<const std::size_t> v_size_t,
253 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
254 const T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
256 std::span<E> data, std::size_t offset = 0, std::size_t block_size = 1)
258 using U =
typename impl::scalar_value_type_t<E>;
260 const std::size_t dim = v_size_t.size();
262 for (std::size_t b = 0; b < block_size; ++b)
264 for (std::size_t i = 0; i < dim; ++i)
266 for (std::size_t j = i + 1; j < dim; ++j)
268 data[block_size * (offset + i) + b]
269 +=
static_cast<U
>(M(i, j)) * data[block_size * (offset + j) + b];
272 for (std::size_t i = 1; i <= dim; ++i)
274 data[block_size * (offset + dim - i) + b]
275 *=
static_cast<U
>(M(dim - i, dim - i));
276 for (std::size_t j = 0; j < dim - i; ++j)
278 data[block_size * (offset + dim - i) + b]
279 +=
static_cast<U
>(M(dim - i, j))
280 * data[block_size * (offset + j) + b];
292 template <
typename T,
typename E>
294 std::span<const std::size_t> v_size_t,
295 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
296 const T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
298 std::span<E> data, std::size_t offset = 0, std::size_t block_size = 1)
300 using U =
typename impl::scalar_value_type_t<E>;
302 const std::size_t dim = v_size_t.size();
303 const std::size_t data_size
304 = (data.size() + (dim < block_size ? block_size - dim : 0)) / block_size;
306 for (std::size_t b = 0; b < block_size; ++b)
308 for (std::size_t i = 0; i < dim; ++i)
310 for (std::size_t j = i + 1; j < dim; ++j)
312 data[data_size * b + offset + i]
313 +=
static_cast<U
>(M(i, j)) * data[data_size * b + offset + j];
316 for (std::size_t i = 1; i <= dim; ++i)
318 data[data_size * b + offset + dim - i]
319 *=
static_cast<U
>(M(dim - i, dim - i));
320 for (std::size_t j = 0; j < dim - i; ++j)
322 data[data_size * b + offset + dim - i]
323 +=
static_cast<U
>(M(dim - i, j)) * data[data_size * b + offset + j];
Matrix and permutation precomputation.
Definition: precompute.h:17
void apply_matrix_to_transpose(std::span< const std::size_t > v_size_t, MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan< const T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents< std::size_t, 2 >> M, std::span< E > data, std::size_t offset=0, std::size_t block_size=1)
Apply a (precomputed) matrix to some transposed data.
Definition: precompute.h:293
void apply_permutation(std::span< const std::size_t > perm, std::span< E > data, std::size_t offset=0, std::size_t block_size=1)
Definition: precompute.h:141
std::vector< std::size_t > prepare_matrix(std::pair< std::vector< T >, std::array< std::size_t, 2 >> &A)
Definition: precompute.h:212
void apply_matrix(std::span< const std::size_t > v_size_t, MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan< const T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents< std::size_t, 2 >> M, std::span< E > data, std::size_t offset=0, std::size_t block_size=1)
Apply a (precomputed) matrix.
Definition: precompute.h:251
void apply_permutation_to_transpose(std::span< const std::size_t > perm, std::span< E > data, std::size_t offset=0, std::size_t block_size=1)
Definition: precompute.h:177
void prepare_permutation(std::span< std::size_t > perm)
Definition: precompute.cpp:10
void apply_permutation_mapped(std::span< const std::size_t > perm, std::span< E > data, std::span< const int > emap, std::size_t block_size=1)
Permutation of mapped data.
Definition: precompute.h:156