lin
operations.hpp
Go to the documentation of this file.
1 
5 #ifndef LIN_QUERIES_OPERATIONS_HPP_
6 #define LIN_QUERIES_OPERATIONS_HPP_
7 
8 #include "../core.hpp"
9 #include "functors.hpp"
10 
11 #include <type_traits>
12 
13 namespace lin {
14 
15 template <class C,
16  std::enable_if_t<internal::matches_tensor<C>::value, size_t> = 0>
17 constexpr bool all(internal::Stream<C> const &c) {
18  for (size_t i = 0; i < c.size(); i++) if (!c(i)) return false;
19  return true;
20 }
21 
22 template <typename T,
23  std::enable_if_t<internal::matches_scalar<T>::value, size_t> = 0>
24 constexpr bool all(T const &t) {
25  return bool(t);
26 }
27 
28 template <class C>
29 constexpr bool any(internal::Stream<C> const &c) {
30  for (size_t i = 0; i < c.size(); i++) if (c(i)) return true;
31  return false;
32 }
33 
34 template <typename T,
35  std::enable_if_t<internal::matches_scalar<T>::value, size_t> = 0>
36 constexpr bool any(T const &t) {
37  return bool(t);
38 }
39 
40 template <class C, class D, std::enable_if_t<
41  internal::matches_tensor_tensor<C, D>::value, size_t> = 0>
42 inline constexpr auto equal_to(internal::Stream<C> const &c, internal::Stream<D> const &d) {
43  LIN_ASSERT(c.rows() == d.rows());
44  LIN_ASSERT(c.cols() == d.cols());
45 
46  return internal::StreamElementWiseOperator<internal::equal_to, C, D>(c, d);
47 }
48 
49 template <typename T, class C, std::enable_if_t<
50  internal::matches_scalar_tensor<T, C>::value, size_t> = 0>
51 inline constexpr auto equal_to(T const &t, internal::Stream<C> const &c) {
52  return internal::StreamElementWiseOperator<internal::equal_to_st<T>, C>(c, t);
53 }
54 
55 template <class C, typename T, std::enable_if_t<
56  internal::matches_tensor_scalar<C, T>::value, size_t> = 0>
57 inline constexpr auto equal_to(internal::Stream<C> const &c, T const &t) {
58  return internal::StreamElementWiseOperator<internal::equal_to_ts<T>, C>(c, t);
59 }
60 
61 template <typename T, typename U, std::enable_if_t<
62  internal::matches_scalar_scalar<T, U>::value, size_t> = 0>
63 inline constexpr auto equal_to(T const &t, U const &u) {
64  return internal::equal_to()(t, u);
65 }
66 
67 template <class C, class D, std::enable_if_t<
68  internal::matches_tensor_tensor<C, D>::value, size_t> = 0>
69 inline constexpr auto greater(internal::Stream<C> const &c, internal::Stream<D> const &d) {
70  LIN_ASSERT(c.rows() == d.rows());
71  LIN_ASSERT(c.cols() == d.cols());
72 
73  return internal::StreamElementWiseOperator<internal::greater, C, D>(c, d);
74 }
75 
76 template <typename T, class C, std::enable_if_t<
77  internal::matches_scalar_tensor<T, C>::value, size_t> = 0>
78 inline constexpr auto greater(T const &t, internal::Stream<C> const &c) {
79  return internal::StreamElementWiseOperator<internal::greater_st<T>, C>(c, t);
80 }
81 
82 template <class C, typename T, std::enable_if_t<
83  internal::matches_tensor_scalar<C, T>::value, size_t> = 0>
84 inline constexpr auto greater(internal::Stream<C> const &c, T const &t) {
85  return internal::StreamElementWiseOperator<internal::greater_ts<T>, C>(c, t);
86 }
87 
88 template <typename T, typename U, std::enable_if_t<
89  internal::matches_scalar_scalar<T, U>::value, size_t> = 0>
90 inline constexpr auto greater(T const &t, U const &u) {
91  return internal::greater()(t, u);
92 }
93 
94 template <class C, class D, std::enable_if_t<
95  internal::matches_tensor_tensor<C, D>::value, size_t> = 0>
96 inline constexpr auto greater_equal(internal::Stream<C> const &c, internal::Stream<D> const &d) {
97  LIN_ASSERT(c.rows() == d.rows());
98  LIN_ASSERT(c.cols() == d.cols());
99 
100  return internal::StreamElementWiseOperator<internal::greater_equal, C, D>(c, d);
101 }
102 
103 template <typename T, class C, std::enable_if_t<
104  internal::matches_scalar_tensor<T, C>::value, size_t> = 0>
105 inline constexpr auto greater_equal(T const &t, internal::Stream<C> const &c) {
106  return internal::StreamElementWiseOperator<internal::greater_equal_st<T>, C>(c, t);
107 }
108 
109 template <class C, typename T, std::enable_if_t<
110  internal::matches_tensor_scalar<C, T>::value, size_t> = 0>
111 inline constexpr auto greater_equal(internal::Stream<C> const &c, T const &t) {
112  return internal::StreamElementWiseOperator<internal::greater_equal_ts<T>, C>(c, t);
113 }
114 
115 template <typename T, typename U, std::enable_if_t<
116  internal::matches_scalar_scalar<T, U>::value, size_t> = 0>
117 inline constexpr auto greater_equal(T const &t, U const &u) {
118  return internal::greater_equal()(t, u);
119 }
120 
121 template <class C, class D, std::enable_if_t<
122  internal::matches_tensor_tensor<C, D>::value, size_t> = 0>
123 inline constexpr auto less(internal::Stream<C> const &c, internal::Stream<D> const &d) {
124  LIN_ASSERT(c.rows() == d.rows());
125  LIN_ASSERT(c.cols() == d.cols());
126 
127  return internal::StreamElementWiseOperator<internal::less, C, D>(c, d);
128 }
129 
130 template <typename T, class C, std::enable_if_t<
131  internal::matches_scalar_tensor<T, C>::value, size_t> = 0>
132 inline constexpr auto less(T const &t, internal::Stream<C> const &c) {
133  return internal::StreamElementWiseOperator<internal::less_st<T>, C>(c, t);
134 }
135 
136 template <class C, typename T, std::enable_if_t<
137  internal::matches_tensor_scalar<C, T>::value, size_t> = 0>
138 inline constexpr auto less(internal::Stream<C> const &c, T const &t) {
139  return internal::StreamElementWiseOperator<internal::less_ts<T>, C>(c, t);
140 }
141 
142 template <typename T, typename U, std::enable_if_t<
143  internal::matches_scalar_scalar<T, U>::value, size_t> = 0>
144 inline constexpr auto less(T const &t, U const &u) {
145  return internal::less()(t, u);
146 }
147 
148 template <class C, class D, std::enable_if_t<
149  internal::matches_tensor_tensor<C, D>::value, size_t> = 0>
150 inline constexpr auto less_equal(internal::Stream<C> const &c, internal::Stream<D> const &d) {
151  LIN_ASSERT(c.rows() == d.rows());
152  LIN_ASSERT(c.cols() == d.cols());
153 
154  return internal::StreamElementWiseOperator<internal::less_equal, C, D>(c, d);
155 }
156 
157 template <typename T, class C, std::enable_if_t<
158  internal::matches_scalar_tensor<T, C>::value, size_t> = 0>
159 inline constexpr auto less_equal(T const &t, internal::Stream<C> const &c) {
160  return internal::StreamElementWiseOperator<internal::less_equal_st<T>, C>(c, t);
161 }
162 
163 template <class C, typename T, std::enable_if_t<
164  internal::matches_tensor_scalar<C, T>::value, size_t> = 0>
165 inline constexpr auto less_equal(internal::Stream<C> const &c, T const &t) {
166  return internal::StreamElementWiseOperator<internal::less_equal_ts<T>, C>(c, t);
167 }
168 
169 template <typename T, typename U, std::enable_if_t<
170  internal::matches_scalar_scalar<T, U>::value, size_t> = 0>
171 inline constexpr auto less_equal(T const &t, U const &u) {
172  return internal::less_equal()(t, u);
173 }
174 
175 template <class C, class D, std::enable_if_t<
176  internal::matches_tensor_tensor<C, D>::value, size_t> = 0>
177 inline constexpr auto logical_and(internal::Stream<C> const &c, internal::Stream<D> const &d) {
178  LIN_ASSERT(c.rows() == d.rows());
179  LIN_ASSERT(c.cols() == d.cols());
180 
181  return internal::StreamElementWiseOperator<internal::logical_and, C, D>(c, d);
182 }
183 
184 template <typename T, class C, std::enable_if_t<
185  internal::matches_scalar_tensor<T, C>::value, size_t> = 0>
186 inline constexpr auto logical_and(T const &t, internal::Stream<C> const &c) {
187  return internal::StreamElementWiseOperator<internal::logical_and_st<T>, C>(c, t);
188 }
189 
190 template <class C, typename T, std::enable_if_t<
191  internal::matches_tensor_scalar<C, T>::value, size_t> = 0>
192 inline constexpr auto logical_and(internal::Stream<C> const &c, T const &t) {
193  return internal::StreamElementWiseOperator<internal::logical_and_ts<T>, C>(c, t);
194 }
195 
196 template <typename T, typename U, std::enable_if_t<
197  internal::matches_scalar_scalar<T, U>::value, size_t> = 0>
198 inline constexpr auto logical_and(T const &t, U const &u) {
199  return internal::logical_and()(t, u);
200 }
201 
202 template <class C, std::enable_if_t<internal::matches_tensor<C>::value, size_t> = 0>
203 inline constexpr auto logical_not(internal::Stream<C> const &c) {
204  return internal::StreamElementWiseOperator<internal::logical_not, C>(c);
205 }
206 
207 template <typename T, std::enable_if_t<internal::matches_scalar<T>::value, size_t> = 0>
208 inline constexpr auto logical_not(T const &t) {
209  return internal::logical_not()(t);
210 }
211 
212 template <class C, class D, std::enable_if_t<
213  internal::matches_tensor_tensor<C, D>::value, size_t> = 0>
214 inline constexpr auto logical_or(internal::Stream<C> const &c, internal::Stream<D> const &d) {
215  LIN_ASSERT(c.rows() == d.rows());
216  LIN_ASSERT(c.cols() == d.cols());
217 
218  return internal::StreamElementWiseOperator<internal::logical_or, C, D>(c, d);
219 }
220 
221 template <typename T, class C, std::enable_if_t<
222  internal::matches_scalar_tensor<T, C>::value, size_t> = 0>
223 inline constexpr auto logical_or(T const &t, internal::Stream<C> const &c) {
224  return internal::StreamElementWiseOperator<internal::logical_or_st<T>, C>(c, t);
225 }
226 
227 template <class C, typename T, std::enable_if_t<
228  internal::matches_tensor_scalar<C, T>::value, size_t> = 0>
229 inline constexpr auto logical_or(internal::Stream<C> const &c, T const &t) {
230  return internal::StreamElementWiseOperator<internal::logical_or_ts<T>, C>(c, t);
231 }
232 
233 template <typename T, typename U, std::enable_if_t<
234  internal::matches_scalar_scalar<T, U>::value, size_t> = 0>
235 inline constexpr auto logical_or(T const &t, U const &u) {
236  return internal::logical_or()(t, u);
237 }
238 
239 template <class C, class D, std::enable_if_t<
240  internal::matches_tensor_tensor<C, D>::value, size_t> = 0>
241 inline constexpr auto not_equal_to(internal::Stream<C> const &c, internal::Stream<D> const &d) {
242  LIN_ASSERT(c.rows() == d.rows());
243  LIN_ASSERT(c.cols() == d.cols());
244 
245  return internal::StreamElementWiseOperator<internal::not_equal_to, C, D>(c, d);
246 }
247 
248 template <typename T, class C, std::enable_if_t<
249  internal::matches_scalar_tensor<T, C>::value, size_t> = 0>
250 inline constexpr auto not_equal_to(T const &t, internal::Stream<C> const &c) {
251  return internal::StreamElementWiseOperator<internal::not_equal_to_st<T>, C>(c, t);
252 }
253 
254 template <class C, typename T, std::enable_if_t<
255  internal::matches_tensor_scalar<C, T>::value, size_t> = 0>
256 inline constexpr auto not_equal_to(internal::Stream<C> const &c, T const &t) {
257  return internal::StreamElementWiseOperator<internal::not_equal_to_ts<T>, C>(c, t);
258 }
259 
260 template <typename T, typename U, std::enable_if_t<
261  internal::matches_scalar_scalar<T, U>::value, size_t> = 0>
262 inline constexpr auto not_equal_to(T const &t, U const &u) {
263  return internal::not_equal_to()(t, u);
264 }
265 } // namespace lin
266 
267 #endif
#define LIN_ASSERT(x)
Asserts the condition x when assertions are enabled within lin.
Definition: config.hpp:22
Definition: config.hpp:27