Tatooine
tensor_utility.h
Go to the documentation of this file.
1#ifndef TATOOINE_TENSOR_UTILITY_H
2#define TATOOINE_TENSOR_UTILITY_H
3//==============================================================================
5//==============================================================================
6namespace tatooine {
7//==============================================================================
9template <static_tensor T0, static_tensor T1>
10requires(same_dimensions<T0, T1>())
11constexpr auto approx_equal(
12 T0 const& lhs, T1 const& rhs,
14 1e-6) {
15 auto equal = true;
16 lhs.for_indices([&](const auto... is) {
17 if (std::abs(lhs(is...) - rhs(is...)) > eps) {
18 equal = false;
19 }
20 });
21 return equal;
22}
23//------------------------------------------------------------------------------
24template <typename Tensor, typename Real, size_t... Dims>
25constexpr auto isnan(base_tensor<Tensor, Real, Dims...> const& t) -> bool {
26 auto p = false;
27 auto it = [&](auto const... is) {
28 if (std::isnan(t(is...))) {
29 p = true;
30 return false;
31 }
32 return true;
33 };
34 for_loop(it, Dims...);
35 return p;
36}
37//==============================================================================
38} // namespace tatooine
39//==============================================================================
40#endif
Definition: algorithm.h:6
typename common_type_impl< Ts... >::type common_type
Definition: common_type.h:23
typename value_type_impl< T >::type value_type
Definition: type_traits.h:280
tensor< real_number, Dimensions... > Tensor
Definition: tensor.h:184
constexpr auto isnan(base_tensor< Tensor, Real, Dims... > const &t) -> bool
Definition: tensor_utility.h:25
constexpr auto approx_equal(T0 const &lhs, T1 const &rhs, common_type< tatooine::value_type< T0 >, tatooine::value_type< T1 > > eps=1e-6)
for comparison
Definition: tensor_utility.h:11
constexpr auto for_loop(Iteration &&iteration, execution_policy::sequential_t, Ranges(&&... ranges)[2]) -> void
Use this function for creating a sequential nested loop.
Definition: for_loop.h:336
Definition: base_tensor.h:23