codac 2.0.0
Loading...
Searching...
No Matches
codac2_SlicedTube_operations.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <type_traits>
13
14#include "codac2_SlicedTube.h"
15#include "codac2_math.h"
16
17namespace codac2
18{
19 // These macros stand in for the body of the functions declared below. Doxygen
20 // parses this header to produce the Python docstrings, and it cannot name a
21 // function whose body it does not recognise, so every macro used that way is
22 // listed in EXPAND_AS_DEFINED in doc/api/Doxyfile.in. Add any new one there
23 // too, otherwise the bindings lose the docstring identifiers they expect and
24 // stop compiling.
25 #define macro_unary_tube(f) \
26 { \
27 auto y = x1; \
28 for(auto it = y.tdomain()->begin() ; it != y.tdomain()->end() ; it++) \
29 { \
30 auto sy = y.slice(it); \
31 sy->codomain() = f(sy->codomain()); \
32 } \
33 return y; \
34 } \
35
36 #define macro_binary_tube_tube(f,output_type) \
37 { \
38 assert_release(x1.tdomain() == x2.tdomain()); \
39 auto y = output_type; \
40 for(auto it = y.tdomain()->begin() ; it != y.tdomain()->end() ; it++) \
41 { \
42 auto sy = y.slice(it); \
43 sy->codomain() = f(x1.slice(it)->codomain(), x2.slice(it)->codomain()); \
44 } \
45 return y; \
46 } \
47
48 #define macro_binary_real_tube(f) \
49 { \
50 auto y = x2; \
51 for(auto it = y.tdomain()->begin() ; it != y.tdomain()->end() ; it++) \
52 { \
53 auto sy = y.slice(it); \
54 sy->codomain() = f(x1, sy->codomain()); \
55 } \
56 return y; \
57 } \
58
59 #define macro_binary_tube_real(f) \
60 { \
61 auto y = x1; \
62 for(auto it = y.tdomain()->begin() ; it != y.tdomain()->end() ; it++) \
63 { \
64 auto sy = y.slice(it); \
65 sy->codomain() = f(sy->codomain(), x2); \
66 } \
67 return y; \
68 } \
69
70 #define macro_member_binary_tube_tube(f) \
71 { \
72 assert_release(x1.tdomain() == x2.tdomain()); \
73 for(auto it = x1.tdomain()->begin() ; it != x1.tdomain()->end() ; it++) \
74 { \
75 auto sx1 = x1.slice(it); \
76 sx1->codomain() = f(sx1->codomain(), x2.slice(it)->codomain()); \
77 } \
78 return x1; \
79 } \
80
81 #define macro_member_binary_tube_real(f) \
82 { \
83 for(auto it = x1.tdomain()->begin() ; it != x1.tdomain()->end() ; it++) \
84 { \
85 auto sx1 = x1.slice(it); \
86 sx1->codomain() = f(sx1->codomain(), x2); \
87 } \
88 return x1; \
89 } \
90
91 template<typename U>
92 struct is_slicedtube : std::false_type {};
93
94 template<typename U>
95 struct is_slicedtube<SlicedTube<U>> : std::true_type {};
96
97 template<typename U>
98 inline constexpr bool is_slicedtube_v = is_slicedtube<std::remove_cvref_t<U>>::value;
99
100 template<typename Q>
101 concept NonSlicedTube = !is_slicedtube_v<Q>;
102
103 template<typename T>
104 concept NonScalarTubeCodomain =
105 !std::is_same_v<std::remove_cvref_t<T>, double> &&
106 !std::is_same_v<std::remove_cvref_t<T>, Interval>;
107
108 template<typename T>
109 inline T operator_tube_union(const T& x1, const T& x2) { return x1 | x2; }
110
111 template<typename T>
112 inline T operator_tube_intersection(const T& x1, const T& x2) { return x1 & x2; }
113
114 template<typename T, typename X1, typename X2>
115 inline T operator_tube_add(const X1& x1, const X2& x2) { return x1 + x2; }
116
117 template<typename T, typename X1, typename X2>
118 inline T operator_tube_sub(const X1& x1, const X2& x2) { return x1 - x2; }
119
120 template<typename T, typename X1, typename X2>
121 inline T operator_tube_mul(const X1& x1, const X2& x2) { return x1 * x2; }
122
123 template<typename T>
124 inline T operator_tube_scal_mul(const Interval& x1, const T& x2) { return x1 * x2; }
125
126 template<typename T>
127 inline T operator_tube_mul_scal(const T& x1, const Interval& x2) { return x1 * x2; }
128
129 inline IntervalVector operator_tube_mul_vec(const IntervalMatrix& x1, const IntervalVector& x2) { return x1 * x2; }
130
131 template<typename T, typename X1, typename X2>
132 inline T operator_tube_div(const X1& x1, const X2& x2) { return x1 / x2; }
133
134 template<typename T, typename X1>
135 inline T operator_tube_div_scal(const X1& x1, const Interval& x2) { return x1 / x2; }
136
149 template<typename T>
151 macro_member_binary_tube_tube(operator_tube_union<T>)
152
153
165 template<typename T>
166 inline SlicedTube<T> operator|(const SlicedTube<T>& x1, const SlicedTube<T>& x2)
167 macro_binary_tube_tube(operator_tube_union<T>,x1)
168
169
181 template<typename T>
183 macro_member_binary_tube_tube(operator_tube_intersection<T>)
184
185
197 template<typename T>
199 macro_binary_tube_tube(operator_tube_intersection<T>,x1)
200
201
210 template<typename T>
211 inline const SlicedTube<T>& operator+(const SlicedTube<T>& x1)
212 {
213 return x1;
214 }
215
228 template<typename T>
230 macro_binary_tube_tube(operator_tube_add<T>,x1)
231
232
244 template<typename T, typename Q>
245 requires NonSlicedTube<Q>
246 inline SlicedTube<T> operator+(const SlicedTube<T>& x1, const Q& x2)
247 macro_binary_tube_real(operator_tube_add<T>)
248
249
261 template<typename T, typename Q>
262 requires NonSlicedTube<Q>
263 inline SlicedTube<T> operator+(const Q& x1, const SlicedTube<T>& x2)
264 macro_binary_real_tube(operator_tube_add<T>)
265
266
273 template<typename T, typename Q>
274 requires NonSlicedTube<Q>
275 inline SlicedTube<T>& operator+=(SlicedTube<T>& x1, const Q& x2)
276 macro_member_binary_tube_real(operator_tube_add<T>)
277
278
285 template<typename T>
287 macro_member_binary_tube_tube(operator_tube_add<T>)
288
289
298 template<typename T>
300 {
301 return -1. * x1;
302 }
303
316 template<typename T>
318 macro_binary_tube_tube(operator_tube_sub<T>,x1)
319
320
332 template<typename T, typename Q>
333 requires NonSlicedTube<Q>
334 inline SlicedTube<T> operator-(const SlicedTube<T>& x1, const Q& x2)
335 macro_binary_tube_real(operator_tube_sub<T>)
336
337
349 template<typename T, typename Q>
350 requires NonSlicedTube<Q>
351 inline SlicedTube<T> operator-(const Q& x1, const SlicedTube<T>& x2)
352 macro_binary_real_tube(operator_tube_sub<T>)
353
354
361 template<typename T, typename Q>
362 requires NonSlicedTube<Q>
363 inline SlicedTube<T>& operator-=(SlicedTube<T>& x1, const Q& x2)
364 macro_member_binary_tube_real(operator_tube_sub<T>)
365
366
373 template<typename T>
375 macro_member_binary_tube_tube(operator_tube_sub<T>)
376
377
389 template<typename T>
390 requires (!std::is_same_v<T, double>)
391 inline SlicedTube<T> operator*(const Interval& x1, const SlicedTube<T>& x2)
392 macro_binary_real_tube(operator_tube_scal_mul<T>)
393
394
406 template<typename T>
407 requires (!std::is_same_v<T, double>)
408 inline SlicedTube<T> operator*(const SlicedTube<T>& x1, const Interval& x2)
409 macro_binary_tube_real(operator_tube_mul_scal<T>)
410
411
420 inline SlicedTube<Interval> operator*(const SlicedTube<Interval>& x1, const SlicedTube<Interval>& x2)
421 macro_binary_tube_tube(operator_tube_mul<Interval>,x1)
422
433 macro_binary_tube_tube(operator_tube_mul<IntervalVector>,x1)
434
445 macro_binary_tube_tube(operator_tube_mul<IntervalMatrix>,x1)
446
458 template<typename T>
459 requires NonScalarTubeCodomain<T>
460 inline SlicedTube<T> operator*(const SlicedTube<Interval>& x1, const SlicedTube<T>& x2)
461 macro_binary_tube_tube(operator_tube_mul<T>,x2)
462
474 template<typename T>
475 requires NonScalarTubeCodomain<T>
476 inline SlicedTube<T> operator*(const SlicedTube<T>& x1, const SlicedTube<Interval>& x2)
477 macro_binary_tube_tube(operator_tube_mul<T>,x1)
478
491 template<typename T, typename Q>
492 requires NonSlicedTube<Q>
493 inline SlicedTube<T> operator*(const SlicedTube<T>& x1, const Q& x2)
494 macro_binary_tube_real(operator_tube_mul<T>)
495
508 template<typename T, typename Q>
509 requires NonSlicedTube<Q>
510 inline SlicedTube<T> operator*(const Q& x1, const SlicedTube<T>& x2)
511 macro_binary_real_tube(operator_tube_mul<T>)
512
523 macro_binary_tube_tube(operator_tube_mul_vec,x2)
524
532 template<typename T, typename Q>
533 requires NonSlicedTube<Q>
534 inline SlicedTube<T>& operator*=(SlicedTube<T>& x1, const Q& x2)
535 macro_member_binary_tube_real(operator_tube_mul<T>)
536
544 template<typename T>
545 inline SlicedTube<T>& operator*=(SlicedTube<T>& x1, const SlicedTube<T>& x2)
546 macro_member_binary_tube_tube(operator_tube_mul<T>)
547
559 template<typename T>
560 requires NonScalarTubeCodomain<T>
561 inline SlicedTube<T>& operator*=(SlicedTube<T>& x1, const SlicedTube<Interval>& x2)
562 macro_member_binary_tube_tube(operator_tube_mul<T>)
563
576 template<typename T>
577 requires (!std::is_same_v<T, double>)
578 inline SlicedTube<T> operator/(const SlicedTube<T>& x1, const Interval& x2)
579 macro_binary_tube_real(operator_tube_div_scal<T>)
580
590 inline SlicedTube<Interval> operator/(const SlicedTube<Interval>& x1, const SlicedTube<Interval>& x2)
591 macro_binary_tube_tube(operator_tube_div<Interval>,x1)
592
604 template<typename T>
605 requires NonScalarTubeCodomain<T>
606 inline SlicedTube<T> operator/(const SlicedTube<T>& x1, const SlicedTube<Interval>& x2)
607 macro_binary_tube_tube(operator_tube_div<T>,x1)
608
621 template<typename T, typename Q>
622 requires NonSlicedTube<Q>
623 inline SlicedTube<T> operator/(const SlicedTube<T>& x1, const Q& x2)
624 macro_binary_tube_real(operator_tube_div<T>)
625
638 template<typename T, typename Q>
639 requires NonSlicedTube<Q>
640 inline SlicedTube<T> operator/(const Q& x1, const SlicedTube<T>& x2)
641 macro_binary_real_tube(operator_tube_div<T>)
642
650 template<typename T, typename Q>
651 requires NonSlicedTube<Q>
652 inline SlicedTube<T>& operator/=(SlicedTube<T>& x1, const Q& x2)
653 macro_member_binary_tube_real(operator_tube_div<T>)
654
662 template<typename T>
663 inline SlicedTube<T>& operator/=(SlicedTube<T>& x1, const SlicedTube<T>& x2)
664 macro_member_binary_tube_tube(operator_tube_div<T>)
665
677 template<typename T>
678 requires NonScalarTubeCodomain<T>
679 inline SlicedTube<T>& operator/=(SlicedTube<T>& x1, const SlicedTube<Interval>& x2)
680 macro_member_binary_tube_tube(operator_tube_div<T>)
681
691
701
712
723
733
743
753
763
773
783
793
803
814
825
836
846
856
866
876
886
896
906
917
928
939
950
961
972
982
992
1002
1012}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:50
Tube represented over a sliced temporal domain.
Definition codac2_SlicedTube.h:38
Definition codac2_OctaSym.h:21
Interval ceil(const Interval &x)
Returns ceil of .
Definition codac2_Interval_operations_impl.h:294
Interval atan(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:133
SlicedTube< T > & operator+=(SlicedTube< T > &x1, const Q &x2)
Pointwise addition assignment with a constant object of matching codomain type.
Definition codac2_SlicedTube_operations.h:275
Interval max(const Interval &x, const Interval &y)
Returns .
Definition codac2_Interval_operations_impl.h:274
SlicedTube< T > & operator-=(SlicedTube< T > &x1, const Q &x2)
Pointwise subtraction assignment with a constant object of matching codomain type.
Definition codac2_SlicedTube_operations.h:363
Interval asinh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:237
Interval atanh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:257
Interval pow(const Interval &x, int n)
Returns , .
Definition codac2_Interval_operations_impl.h:33
Interval sqrt(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:26
Interval cosh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:205
Interval floor(const Interval &x)
Returns floor of .
Definition codac2_Interval_operations_impl.h:289
Interval sinh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:216
Interval acos(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:119
Eigen::Matrix< Interval,-1, 1 > IntervalVector
Alias for a dynamic-size column vector of intervals.
Definition codac2_IntervalVector.h:25
Ellipsoid operator+(const Ellipsoid &e1, const Ellipsoid &e2)
Compute the Minkowski sum of two ellipsoids.
Interval atan2(const Interval &y, const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:140
Interval log(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:85
CtcInterType< typenameC1::ContractedTypes >::Ctc operator&(const C1 &c1, const C2 &c2)
Builds an intersection contractor from two contractors.
Definition codac2_CtcInter.h:230
SlicedTube< T > & operator&=(SlicedTube< T > &x1, const SlicedTube< T > &x2)
Pointwise intersection assignment of two tubes with the same codomain type.
Definition codac2_SlicedTube_operations.h:182
Interval operator-(const Interval &x, double y)
Returns with .
Definition codac2_Interval_impl.h:438
SlicedTube< T > & operator|=(SlicedTube< T > &x1, const SlicedTube< T > &x2)
Pointwise hull-union assignment of two tubes with the same codomain type.
Definition codac2_SlicedTube_operations.h:150
Interval cos(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:98
Interval exp(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:78
Interval tanh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:223
Interval sqr(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:21
Interval abs(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:264
Interval asin(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:126
Interval integer(const Interval &x)
Returns the largest integer interval included in .
Definition codac2_Interval_operations_impl.h:284
Interval min(const Interval &x, const Interval &y)
Returns .
Definition codac2_Interval_operations_impl.h:269
Eigen::Matrix< Interval,-1,-1 > IntervalMatrix
Alias for a dynamic-size matrix of intervals.
Definition codac2_IntervalMatrix.h:25
Interval acosh(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:230
Interval sign(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:279
Interval sin(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:105
Interval tan(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:112