codac 1.5.6
Loading...
Searching...
No Matches
codac2_cross_prod.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_Interval.h"
13#include "codac2_AnalyticType.h"
15
16namespace codac2
17{
18 struct CrossProdOp
19 {
20 static IntervalVector fwd(const IntervalVector& x1, const IntervalVector& x2);
21 static VectorType fwd_natural(const VectorType& x1, const VectorType& x2);
22 static VectorType fwd_centered(const VectorType& x1, const VectorType& x2);
23 static void bwd(const IntervalVector& y, IntervalVector& x1, IntervalVector& x2);
24 };
25
26 // Analytic operator
27 // The following function can be used to build analytic expressions.
28
29 inline VectorExpr
30 cross_prod(const VectorExpr& x1, const VectorExpr& x2)
31 {
32 return { std::make_shared<AnalyticOperationExpr<CrossProdOp,VectorType,VectorType,VectorType>>(x1,x2) };
33 }
34
35 // Inline functions
36
37 inline IntervalVector CrossProdOp::fwd(const IntervalVector& x1, const IntervalVector& x2)
38 {
39 assert_release(x1.size() == 3 && x2.size() == 3);
40 return {
41 x1[1]*x2[2] - x1[2]*x2[1],
42 x1[2]*x2[0] - x1[0]*x2[2],
43 x1[0]*x2[1] - x1[1]*x2[0]
44 };
45 }
46
47 inline VectorType CrossProdOp::fwd_natural(const VectorType& x1, const VectorType& x2)
48 {
49 return {
50 fwd(x1.a,x2.a),
51 x1.def_domain && x2.def_domain
52 };
53 }
54
55 inline VectorType CrossProdOp::fwd_centered(const VectorType& x1, const VectorType& x2)
56 {
57 return {
58 fwd(x1.m,x2.m),
59 fwd(x1.a,x2.a),
60 IntervalMatrix(0,0), // not supported yet for auto diff
61 x1.def_domain && x2.def_domain
62 };
63 }
64
65 inline void CrossProdOp::bwd([[maybe_unused]] const IntervalVector& y, [[maybe_unused]] IntervalVector& x1, [[maybe_unused]] IntervalVector& x2)
66 {
67 assert_release(y.size() == 3 && x1.size() == 3 && x2.size() == 3);
68 // todo
69 }
70}