13 #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;
136 template <
typename E>
138 std::size_t offset = 0, std::size_t n = 1)
140 for (std::size_t i = 0; i < perm.size(); ++i)
141 for (std::size_t b = 0; b < n; ++b)
142 std::swap(data[n * (offset + i) + b], data[n * (offset + perm[i]) + b]);
146 template <
typename E>
148 std::span<E> data, std::span<const int> emap,
151 for (std::size_t i = 0; i < perm.size(); ++i)
152 for (std::size_t b = 0; b < n; ++b)
153 std::swap(data[n * emap[i] + b], data[n * emap[perm[i]] + b]);
164 template <
typename E>
166 std::span<E> data, std::size_t offset = 0,
169 const std::size_t dim = perm.size();
170 const std::size_t data_size = (data.size() + (dim < n ? n - dim : 0)) / n;
171 for (std::size_t b = 0; b < n; ++b)
173 for (std::size_t i = 0; i < dim; ++i)
175 std::swap(data[data_size * b + offset + i],
176 data[data_size * b + offset + perm[i]]);
197 template <std::
floating_po
int T>
198 std::vector<std::size_t>
201 return math::transpose_lu<T>(A);
235 template <
typename T,
typename E>
237 std::span<const std::size_t> v_size_t,
238 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
239 const T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
241 std::span<E> data, std::size_t offset = 0, std::size_t n = 1)
243 using U =
typename impl::scalar_value_type_t<E>;
245 const std::size_t dim = v_size_t.size();
247 for (std::size_t b = 0; b < n; ++b)
249 for (std::size_t i = 0; i < dim; ++i)
251 for (std::size_t j = i + 1; j < dim; ++j)
253 data[n * (offset + i) + b]
254 +=
static_cast<U
>(M(i, j)) * data[n * (offset + j) + b];
258 for (std::size_t i = 1; i <= dim; ++i)
260 data[n * (offset + dim - i) + b] *=
static_cast<U
>(M(dim - i, dim - i));
261 for (std::size_t j = 0; j < dim - i; ++j)
263 data[n * (offset + dim - i) + b]
264 +=
static_cast<U
>(M(dim - i, j)) * data[n * (offset + j) + b];
278 template <
typename T,
typename E>
280 std::span<const std::size_t> v_size_t,
281 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
282 const T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
284 std::span<E> data, std::size_t offset = 0, std::size_t n = 1)
286 using U =
typename impl::scalar_value_type_t<E>;
288 const std::size_t dim = v_size_t.size();
289 const std::size_t data_size = (data.size() + (dim < n ? n - dim : 0)) / n;
291 for (std::size_t b = 0; b < n; ++b)
293 for (std::size_t i = 0; i < dim; ++i)
295 for (std::size_t j = i + 1; j < dim; ++j)
297 data[data_size * b + offset + i]
298 +=
static_cast<U
>(M(i, j)) * data[data_size * b + offset + j];
301 for (std::size_t i = 1; i <= dim; ++i)
303 data[data_size * b + offset + dim - i]
304 *=
static_cast<U
>(M(dim - i, dim - i));
305 for (std::size_t j = 0; j < dim - i; ++j)
307 data[data_size * b + offset + dim - i]
308 +=
static_cast<U
>(M(dim - i, j)) * data[data_size * b + offset + j];
Matrix and permutation pre-computation.
Definition: precompute.h:18
std::vector< std::size_t > prepare_matrix(std::pair< std::vector< T >, std::array< std::size_t, 2 >> &A)
Prepare a square matrix.
Definition: precompute.h:199
void apply_tranpose_matrix_right(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 n=1)
Apply a (precomputed) matrix to some transposed data.
Definition: precompute.h:279
void apply_permutation(std::span< const std::size_t > perm, std::span< E > data, std::size_t offset=0, std::size_t n=1)
Apply a (precomputed) permutation .
Definition: precompute.h:137
void apply_inv_permutation_right(std::span< const std::size_t > perm, std::span< E > data, std::size_t offset=0, std::size_t n=1)
Apply a (precomputed) permutation to some transposed data.
Definition: precompute.h:165
void prepare_permutation(std::span< std::size_t > perm)
Prepare a permutation.
Definition: precompute.cpp:10
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 n=1)
Apply a (precomputed) matrix.
Definition: precompute.h:236
void apply_permutation_mapped(std::span< const std::size_t > perm, std::span< E > data, std::span< const int > emap, std::size_t n=1)
Permutation of mapped data.
Definition: precompute.h:147