Tatooine
tensor_concepts.h
Go to the documentation of this file.
1#ifndef TATOOINE_TENSOR_CONCEPTS_H
2#define TATOOINE_TENSOR_CONCEPTS_H
3//==============================================================================
4#include <tatooine/concepts.h>
5//==============================================================================
6namespace tatooine {
7//==============================================================================
8template <typename T>
9concept general_tensor = std::decay_t<T>::is_tensor() && requires(T t) {
10 { t.rank() } -> integral;
11 { t.dimensions() } -> integral_range;
12 { t.dimension(std::declval<std::size_t>()) } -> std::integral;
13 typename std::decay_t<T>::value_type;
14};
15//==============================================================================
16template <typename T>
17concept dynamic_tensor = general_tensor<T> && std::decay_t<T>::is_dynamic();
18//==============================================================================
19template <typename T>
20concept static_tensor = general_tensor<T> && std::decay_t<T>::is_static();
21//==============================================================================
22template <typename T>
23concept static_vec = static_tensor<T> && std::decay_t<T>::rank() == 1;
24//==============================================================================
25template <typename T>
26concept static_mat = static_tensor<T> && std::decay_t<T>::rank() == 2;
27//==============================================================================
28template <typename T, std::size_t... Dimensions>
29concept fixed_size_tensor = static_tensor<T> && std::decay_t<T>::dimensions()
30== std::array{Dimensions...};
31//------------------------------------------------------------------------------
32template <typename T, std::size_t N>
33concept fixed_size_vec = static_vec<T> && std::decay_t<T>::dimension(0) == N;
34//------------------------------------------------------------------------------
35template <typename T, std::size_t N>
38//==============================================================================
39template <typename T, std::size_t M, std::size_t N>
40concept fixed_size_mat = static_mat<T> && std::decay_t<T>::dimension(0)
41== M&& std::decay_t<T>::dimension(1) == N;
42// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43template <typename T, std::size_t N>
44concept fixed_num_cols_mat = static_mat<T> && std::decay_t<T>::dimension(1)
45== N;
46// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47template <typename T, std::size_t M>
48concept fixed_num_rows_mat = static_mat<T> && std::decay_t<T>::dimension(0)
49== M;
50//==============================================================================
51template <static_tensor Tensor,
52 std::size_t I = std::decay_t<Tensor>::rank() - 1>
53requires requires {std::decay_t<Tensor>::rank() > 2;}
55 static auto constexpr value =
56 std::decay_t<Tensor>::dimension(0) == std::decay_t<Tensor>::dimension(I) &&
58};
59//------------------------------------------------------------------------------
60template <static_tensor Tensor>
61requires requires {std::decay_t<Tensor>::rank() > 2;}
63 static auto constexpr value =
64 std::decay_t<Tensor>::dimension(0) == std::decay_t<Tensor>::dimension(1);
65};
66//------------------------------------------------------------------------------
67template <static_tensor Tensor>
68requires requires {std::decay_t<Tensor>::rank() > 2;}
70 static auto constexpr value = true;
71};
72//------------------------------------------------------------------------------
73template <static_tensor Tensor>
75//==============================================================================
76template <typename T>
77concept static_quadratic_tensor = static_tensor<T> && is_square<T>;
78//==============================================================================
79template <typename T>
80concept static_quadratic_mat = static_mat<T> && is_square<T>;
81//==============================================================================
82template <typename T, std::size_t N>
84 std::decay_t<T>::dimension(0)
85== N;
86//==============================================================================
87template <typename T, std::size_t N>
89 std::decay_t<T>::dimension(0)
90== N;
91//==============================================================================
92template <typename T>
94 std::decay_t<T>::is_transposed();
95//==============================================================================
96// template <typename T>
97// concept transposed_static_tensor =
98// transposed_tensor<T> &&
99// static_tensor<T>;
100//==============================================================================
101// template <typename T>
102// concept transposed_dynamic_tensor =
103// transposed_tensor<T> &&
104// dynamic_tensor<T>;
105//==============================================================================
106template <typename T>
107concept diag_tensor = general_tensor<T> && std::decay_t<T>::is_diag();
108//==============================================================================
109// template <typename T>
110// concept diag_static_tensor =
111// diag_tensor<T> &&
112// static_tensor<T>;
113//==============================================================================
114// template <typename T>
115// concept diag_dynamic_tensor =
116// diag_tensor<T> &&
117// dynamic_tensor<T>;
118//==============================================================================
119} // namespace tatooine
120//==============================================================================
121#endif
Definition: concepts.h:33
Definition: tensor_concepts.h:107
Definition: tensor_concepts.h:17
Definition: tensor_concepts.h:44
Definition: tensor_concepts.h:48
Definition: tensor_concepts.h:40
Definition: tensor_concepts.h:88
Definition: tensor_concepts.h:83
Definition: tensor_concepts.h:36
Definition: tensor_concepts.h:29
Definition: tensor_concepts.h:33
Definition: tensor_concepts.h:9
Definition: concepts.h:91
Definition: concepts.h:21
Definition: tensor_concepts.h:26
Definition: tensor_concepts.h:80
Definition: tensor_concepts.h:77
Definition: tensor_concepts.h:20
Definition: tensor_concepts.h:23
Definition: tensor_concepts.h:93
Definition: algorithm.h:6
tensor< real_number, Dimensions... > Tensor
Definition: tensor.h:184
static auto constexpr is_square
Definition: tensor_concepts.h:74
Definition: tensor_concepts.h:54
static auto constexpr value
Definition: tensor_concepts.h:55