Tatooine
tensor_type_traits.h
Go to the documentation of this file.
1#ifndef TATOOINE_TENSOR_TYPE_TRAITS_H
2#define TATOOINE_TENSOR_TYPE_TRAITS_H
3//==============================================================================
5//==============================================================================
6namespace tatooine {
7//==============================================================================
8template <typename Tensor>
10// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11template <static_tensor Tensor>
13 : std::integral_constant<std::size_t, std::decay_t<Tensor>::rank()> {};
14// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15template <arithmetic_or_complex Tensor>
16struct tensor_rank_impl<Tensor> : std::integral_constant<std::size_t, 0> {};
17// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18template <arithmetic_or_complex T, std::size_t N>
19struct tensor_rank_impl<std::array<T, N>>
20 : std::integral_constant<std::size_t, 1> {};
21// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22template <typename T>
24//==============================================================================
25template <typename T>
27// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28template <static_tensor Tensor>
30 : std::integral_constant<std::size_t,
31 std::decay_t<Tensor>::num_components()> {};
32// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33template <arithmetic_or_complex T>
34struct tensor_num_components_impl<T> : std::integral_constant<std::size_t, 1> {
35};
36// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37template <arithmetic_or_complex T, std::size_t N>
38struct tensor_num_components_impl<std::array<T, N>>
39 : std::integral_constant<std::size_t, N> {};
40// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41template <typename T>
42static auto constexpr tensor_num_components =
44//==============================================================================
45template <typename T>
47// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48template <static_tensor Tensor>
50 static auto constexpr value = std::decay_t<Tensor>::dimensions();
51};
52// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53template <arithmetic_or_complex T, std::size_t N>
54struct tensor_dimensions_impl<std::array<T, N>> {
55 static auto constexpr value = std::array{N};
56};
57// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58template <typename T>
60//==============================================================================
61template <typename T, std::size_t I>
63// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64template <static_tensor Tensor, std::size_t I>
65requires(I < tensor_rank<Tensor>)
67 static auto constexpr value = std::decay_t<Tensor>::dimension(I);
68};
69// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70template <arithmetic_or_complex T, std::size_t I>
72 static auto constexpr value = std::numeric_limits<T>::max();
73};
74// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75template <arithmetic_or_complex T, std::size_t N>
76struct tensor_dimension_impl<std::array<T, N>, 0> {
77 static auto constexpr value = N;
78};
79// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80template <typename T, std::size_t I>
82//==============================================================================
83} // namespace tatooine
84//==============================================================================
85#endif
Definition: algorithm.h:6
static auto constexpr tensor_num_components
Definition: tensor_type_traits.h:42
static constexpr auto tensor_rank
Definition: tensor_type_traits.h:23
static auto constexpr tensor_dimensions
Definition: tensor_type_traits.h:59
static auto constexpr tensor_dimension
Definition: tensor_type_traits.h:81
Definition: tensor_type_traits.h:62
Definition: tensor_type_traits.h:46
Definition: tensor_type_traits.h:26
Definition: tensor_type_traits.h:9