-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ops.inl
51 lines (40 loc) · 1.58 KB
/
Ops.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include "Model.h"
#include "Var.h"
namespace netn {
template<typename L, typename R, typename Op>
inline Ops<L, R, Op>::Ops(const Model<L> & lhs, const Model<R> & rhs)
: _lhs(lhs.toModel()), _rhs(rhs.toModel()) {}
template<typename L, typename R, typename Op>
inline std::shared_ptr<Model<typename Ops<L, R, Op>::value_t>> Ops<L, R, Op>::toModel() const {
return std::make_shared<Ops<L, R, Op>>(*this);
}
template<typename L, typename R, typename Fct>
inline typename Ops<L, R, Fct>::value_t Ops<L, R, Fct>::eval() const {
return Fct::eval(_lhs->eval(), _rhs->eval());
}
template<typename L, typename R, typename Fct>
inline typename Ops<L, R, Fct>::value_t Ops<L, R, Fct>::derivPart(const Component & component) const {
return Fct::derivPart(_lhs->eval(), _rhs->eval(), _lhs->derivPart(component), _rhs->derivPart(component));
}
template <typename L, typename R>
inline AddOp<L, R> operator+(const Model<L> & lhs, const Model<R> & rhs) {
return AddOp<L, R>(lhs, rhs);
}
template <typename L, typename R>
inline SubOp<L, R> operator-(const Model<L> & lhs, const Model<R> & rhs) {
return SubOp<L, R>(lhs, rhs);
}
template <typename L, typename R>
inline MulOp<L, R> operator*(const Model<L> & lhs, const Model<R> & rhs) {
return MulOp<L, R>(lhs, rhs);
}
template <typename L, typename R>
inline DivOp<L, R> operator/(const Model<L> & lhs, const Model<R> & rhs) {
return DivOp<L, R>(lhs, rhs);
}
template <typename T>
inline MulOp<double, T> operator*(double lhs, const Model<T> & rhs) {
return MulOp<double, T>(Var<double>(lhs), rhs);
}
}