forked from msupernaw/ATL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReal.hpp
253 lines (212 loc) · 5.47 KB
/
Real.hpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Real.hpp
* Author: matthewsupernaw
*
* Created on November 2, 2016, 5:21 PM
*/
#ifndef REAL_HPP
#define REAL_HPP
#include "Expression.hpp"
namespace atl {
/**
* Wrapper class for real numbers. Used in expression templates to avoid
* separate templates for operations involving real values in binary
* expressions.
*/
template<typename REAL_T>
struct Real : atl::ExpressionBase<REAL_T, Real<REAL_T> > {
typedef REAL_T base_type;
REAL_T value;
/**
* Constructor.
*
* @param v
*/
Real(REAL_T v = static_cast<REAL_T> (0.0)) {
value = v;
}
/**
* Copy constructor.
*
* @param other
*/
Real(const Real<REAL_T>& other) :
value(other.value) {
}
~Real() {
}
/**
* Assignment operator.
*
* @param v
* @return
*/
Real& operator=(const REAL_T& v) {
value = v;
return *this;
}
operator REAL_T() const {
return value;
}
/**
* Returns the value.
*
* @return
*/
inline const REAL_T GetValue() const {
return value;
}
/**
* Returns the value.
*
* @return
*/
inline const REAL_T GetValue(size_t i, size_t j = 0) const {
return value;
}
/**
* Returns false.
*
* @return
*/
inline bool IsNonlinear() const {
return false;
}
/**
* Nothing done.
*
* @param ids
*/
inline void PushIds(typename atl::StackEntry<REAL_T>::vi_storage& ids)const {
}
/**
* Nothing done.
*
* @param ids
* @param i
* @param j
*/
inline void PushIds(typename atl::StackEntry<REAL_T>::vi_storage& ids, size_t i, size_t j = 0)const {
}
inline void PushNLIds(typename atl::StackEntry<REAL_T>::vi_storage& ids, bool nl = false)const {
}
inline const std::complex<REAL_T> ComplexEvaluate(uint32_t x, REAL_T h = 1e-20) const {
return std::complex<REAL_T>(this->value);
}
inline const REAL_T Taylor(uint32_t degree) const {
return degree == 0 ? this->value : static_cast<REAL_T> (0.0);
}
std::shared_ptr<DynamicExpressionBase<REAL_T> > ToDynamic() const {
#ifdef USE_DELEGATES
return atl::RealFunctions<REAL_T>::Create(this->value);
#else
return std::make_shared<atl::RealDynamic<REAL_T> >(this->value);
#endif
}
/**
* Returns 0.
*
* @param x
* @return
*/
inline REAL_T EvaluateFirstDerivative(uint32_t x) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns 0.
*
* @param x
* @param y
* @return
*/
inline REAL_T EvaluateSecondDerivative(uint32_t x, uint32_t y) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns 0.
*
* @param x
* @param y
* @param z
* @return
*/
inline REAL_T EvaluateThirdDerivative(uint32_t x, uint32_t y, uint32_t z) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns 0.
*
* @param x
* @param i
* @param j
* @return
*/
inline REAL_T EvaluateFirstDerivativeAt(uint32_t x, size_t i, size_t j = 0) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns 0.
*
* @param x
* @param y
* @param i
* @param j
* @return
*/
inline REAL_T EvaluateSecondDerivativeAt(uint32_t x, uint32_t y, size_t i, size_t j = 0) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns 0.
*
* @param x
* @param y
* @param z
* @param i
* @param j
* @return
*/
inline REAL_T EvaluateThirdDerivativeAt(uint32_t x, uint32_t y, uint32_t z, size_t i, size_t j = 0) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns std::numeric_limits<size_t>::max();
* @return
*/
size_t GetColumns() const {
return std::numeric_limits<size_t>::max();
}
/**
* std::numeric_limits<size_t>::max();
*
* @return
*/
size_t GetRows() const {
return std::numeric_limits<size_t>::max();
}
/**
* Returns true.
*
* @return
*/
bool IsScalar() const {
return true;
}
/**
* Creates a string representation of this expression template.
*
* @return
*/
const std::string ToExpressionTemplateString() const {
std::stringstream ss;
ss << "atl::Real<T>";
return ss.str();
}
};
}
#endif /* REAL_HPP */