codac 1.5.6
Loading...
Searching...
No Matches
codac2_mat.h
1
9
10#pragma once
11
14#include "codac2_AnalyticType.h"
16
17namespace codac2
18{
19 struct MatrixOp
20 {
21 static void fwd_i(IntervalMatrix& m, const IntervalVector& x, Index i);
22
23 template<typename... X>
24 requires (std::is_base_of_v<Domain,X> && ...)
25 static inline IntervalMatrix fwd(const X&... x)
26 {
27 throw std::runtime_error("MatrixOp not fully implemented yet");
28 IntervalMatrix m(1, sizeof...(X));
29 Index i = 0;
30 (MatrixOp::fwd_i(m, x, i++), ...);
31 return m;
32 }
33
34 template<typename... X>
35 requires (std::is_base_of_v<VectorType,X> && ...)
36 static inline MatrixType fwd_natural(const X&... x)
37 {
38 throw std::runtime_error("MatrixOp not fully implemented yet");
39 return {
40 IntervalMatrix({x.a...}),
41 true // todo with variadic
42 };
43 }
44
45 template<typename... X>
46 requires (std::is_base_of_v<VectorType,X> && ...)
47 static inline MatrixType fwd_centered(const X&... x)
48 {
49 throw std::runtime_error("MatrixOp not fully implemented yet");
50 return {
51 IntervalMatrix({x.m...}),
52 IntervalMatrix({x.a...}),
53 IntervalMatrix(0,0), // not supported yet for matrices
54 true // todo with variadic
55 };
56 }
57
58 template<typename... X>
59 requires (std::is_base_of_v<IntervalVector,X> && ...)
60 static inline void bwd(const IntervalMatrix& y, X&... x)
61 {
62 throw std::runtime_error("MatrixOp not fully implemented yet");
63 Index i = 0;
64 ((x &= y.col(i++)), ...);
65 }
66 };
67
68 // Analytic operator
69 // The following function can be used to build analytic expressions.
70
71 // Generic variadic case, cannot handle const values (int, double) for now
72
73 template<typename... X>
74 inline MatrixExpr
75 mat(const std::shared_ptr<AnalyticExpr<X>>&... x)
76 {
77 return { std::make_shared<AnalyticOperationExpr<MatrixOp,MatrixType,X...>>(
78 AnalyticOperationExpr<MatrixOp,MatrixType,X...>(x...)) };
79 }
80
81 // Inline functions
82
83 inline void MatrixOp::fwd_i(IntervalMatrix& m, const IntervalVector& x, Index i)
84 {
85 assert(i >= 0 && i < m.cols());
86 m.resize(x.size(),m.cols());
87 m.col(i) = x;
88 }
89}