8#include <compile_time_options.h>
10#include <deal.II/base/tensor.h>
11#include <deal.II/base/utilities.h>
12#include <deal.II/base/vectorization.h>
35 template <
typename T, std::
size_t w
idth>
51 template <
typename T, std::
size_t w
idth>
52 unsigned int get_stride_size<dealii::VectorizedArray<T, width>> = width;
59 template <
typename Functor,
size_t... Is>
60 auto generate_iterators_impl(Functor f, std::index_sequence<Is...>)
61 -> std::array<
decltype(f(0)),
sizeof...(Is)>
80 template <
unsigned int length,
typename Functor>
82 -> std::array<
decltype(f(0)), length>
84 return generate_iterators_impl<>(f, std::make_index_sequence<length>());
96 for (
auto &it : iterators)
111 template <
typename Number>
114 return std::max(Number(0.), number);
123 template <
typename Number>
126 return -std::min(Number(0.), number);
137 template <
int N,
typename T>
140 return dealii::Utilities::fixed_power<N, T>(x);
149 template <
typename T>
150 T
pow(
const T x,
const T b);
158 template <
typename T, std::
size_t w
idth>
159 dealii::VectorizedArray<T, width>
160 pow(
const dealii::VectorizedArray<T, width> x,
const T b);
169 template <
typename T, std::
size_t w
idth>
170 dealii::VectorizedArray<T, width>
171 pow(
const dealii::VectorizedArray<T, width> x,
172 const dealii::VectorizedArray<T, width> b);
203 template <
typename T>
212 template <
typename T, std::
size_t w
idth>
213 dealii::VectorizedArray<T, width>
214 fast_pow(
const dealii::VectorizedArray<T, width> x,
225 template <
typename T, std::
size_t w
idth>
226 dealii::VectorizedArray<T, width>
227 fast_pow(
const dealii::VectorizedArray<T, width> x,
228 const dealii::VectorizedArray<T, width> b,
243 template <
typename T,
typename V>
244 DEAL_II_ALWAYS_INLINE
inline T
get_entry(
const V &vector,
unsigned int i)
246 static_assert(std::is_same_v<typename get_value_type<T>::type,
247 typename V::value_type>,
251 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
253 result = vector.local_element(i);
256 result.load(vector.get_values() + i);
267 template <
typename T,
typename T2>
268 DEAL_II_ALWAYS_INLINE
inline T
get_entry(
const std::vector<T2> &vector,
271 if constexpr (std::is_same_v<typename get_value_type<T>::type, T2>) {
275 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
280 result.load(vector.data() + i);
287 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
291 for (
unsigned int k = 0; k < T::size(); ++k)
292 result[k] = vector[i + k];
305 template <
typename T,
typename V>
306 DEAL_II_ALWAYS_INLINE
inline T
get_entry(
const V &vector,
307 const unsigned int *js)
309 static_assert(std::is_same_v<typename get_value_type<T>::type,
310 typename V::value_type>,
314 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
316 result = vector.local_element(js[0]);
319 result.gather(vector.get_values(), js);
330 template <
typename T,
typename T2>
331 DEAL_II_ALWAYS_INLINE
inline T
get_entry(
const std::vector<T2> &vector,
332 const unsigned int *js)
334 static_assert(std::is_same_v<typename get_value_type<T>::type, T2>,
338 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
340 result = vector[js[0]];
343 result.load(vector.data(), js);
355 template <
typename T,
typename V>
356 DEAL_II_ALWAYS_INLINE
inline void
359 static_assert(std::is_same_v<typename get_value_type<T>::type,
360 typename V::value_type>,
363 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
365 vector.local_element(i) = values;
368 values.store(vector.get_values() + i);
377 template <
typename T,
typename T2>
378 DEAL_II_ALWAYS_INLINE
inline void
379 write_entry(std::vector<T2> &vector,
const T &values,
unsigned int i)
381 if constexpr (std::is_same_v<typename get_value_type<T>::type, T2>) {
384 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
389 values.store(vector.data() + i);
394 if constexpr (std::is_same_v<T, typename get_value_type<T>::type>) {
398 for (
unsigned int k = 0; k < T::size(); ++k)
399 vector[i + k] = values[k];
410 template <
int rank,
int dim, std::
size_t w
idth,
typename Number>
411 DEAL_II_ALWAYS_INLINE
inline dealii::Tensor<rank, dim, Number>
413 const dealii::Tensor<rank, dim, dealii::VectorizedArray<Number, width>>
415 const unsigned int k)
417 Assert(k < width, dealii::ExcMessage(
"Index past VectorizedArray width"));
418 dealii::Tensor<rank, dim, Number> result;
419 if constexpr (rank == 1) {
420 for (
unsigned int d = 0; d < dim; ++d)
421 result[d] = vectorized[d][k];
423 for (
unsigned int d = 0; d < dim; ++d)
436 template <
int rank,
int dim,
typename Number>
437 DEAL_II_ALWAYS_INLINE
inline dealii::Tensor<rank, dim, Number>
439 const unsigned int k [[maybe_unused]])
443 "The given index k must be zero for a serial tensor"));
453 template <
int rank,
int dim, std::
size_t w
idth,
typename Number>
455 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number, width>> &result,
456 const dealii::Tensor<rank, dim, Number> &serial,
457 const unsigned int k)
459 Assert(k < width, dealii::ExcMessage(
"Index past VectorizedArray width"));
460 if constexpr (rank == 1) {
461 for (
unsigned int d = 0; d < dim; ++d)
462 result[d][k] = serial[d];
464 for (
unsigned int d = 0; d < dim; ++d)
476 template <
int rank,
int dim,
typename Number>
477 DEAL_II_ALWAYS_INLINE
inline void
479 const dealii::Tensor<rank, dim, Number> &serial,
480 const unsigned int k [[maybe_unused]])
484 "The given index k must be zero for a serial tensor"));
DEAL_II_ALWAYS_INLINE void assign_serial_tensor(dealii::Tensor< rank, dim, dealii::VectorizedArray< Number, width > > &result, const dealii::Tensor< rank, dim, Number > &serial, const unsigned int k)
DEAL_II_ALWAYS_INLINE auto generate_iterators(Functor f) -> std::array< auto, length >
T pow(const T x, const T b)
DEAL_II_ALWAYS_INLINE void increment_iterators(T &iterators)
DEAL_II_ALWAYS_INLINE T get_entry(const V &vector, unsigned int i)
DEAL_II_ALWAYS_INLINE Number negative_part(const Number number)
DEAL_II_ALWAYS_INLINE void write_entry(V &vector, const T &values, unsigned int i)
T fast_pow(const T x, const T b, const Bias bias=Bias::none)
unsigned int get_stride_size
DEAL_II_ALWAYS_INLINE Number positive_part(const Number number)
DEAL_II_ALWAYS_INLINE dealii::Tensor< rank, dim, Number > serialize_tensor(const dealii::Tensor< rank, dim, dealii::VectorizedArray< Number, width > > &vectorized, const unsigned int k)