forked from msupernaw/ATL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Floor.hpp
265 lines (230 loc) · 6.84 KB
/
Floor.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
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
* File: Floor.hpp
* Author: matthewsupernaw
*
* Created on June 18, 2014, 12:54 PM
*/
/**
*
* @author Matthew R. Supernaw
*
* Public Domain Notice
* National Oceanic And Atmospheric Administration
*
* This software is a "United States Government Work" under the terms of the
* United States Copyright Act. It was written as part of the author's official
* duties as a United States Government employee and thus cannot be copyrighted.
* This software is freely available to the public for use. The National Oceanic
* And Atmospheric Administration and the U.S. Government have not placed any
* restriction on its use or reproduction. Although all reasonable efforts have
* been taken to ensure the accuracy and reliability of the software and data,
* the National Oceanic And Atmospheric Administration and the U.S. Government
* do not and cannot warrant the performance warrant the performance or results
* that may be obtained by using this software or data. The National Oceanic
* And Atmospheric Administration and the U.S. Government disclaim all
* warranties, express or implied, including warranties of performance,
* merchantability or fitness for any particular purpose.
*
* Please cite the author(s) in any work or product based on this material.
*
*/
#ifndef FLOOR_HPP
#define FLOOR_HPP
#include "Expression.hpp"
#include <exception>
namespace atl {
/**
* Expression template to handle cosine for variable or
* container expressions.
*
* \f$ \floor f(x,y) \f$
*
* or
*
* \f$ \floor f_{i,j}(x,y) \f$
*
*
* This is not differentiable and calls to the derivative member functions
* result in 0.
*
*
*/
template<class REAL_T, class EXPR>
struct Floor : public ExpressionBase<REAL_T, Floor<REAL_T, EXPR> > {
typedef REAL_T BASE_TYPE;
Floor(const Floor<REAL_T, EXPR>& other) :
expr_m(other.expr_m) {
}
/**
* Constructor
*
* @param a
*/
Floor(const ExpressionBase<REAL_T, EXPR>& a)
: expr_m(a.Cast()) {
}
/**
* Compute the floor of the evaluated expression.
*
* @return
*/
inline const REAL_T GetValue() const {
return std::floor(expr_m.GetValue());
}
/**
* Compute the floor of the evaluated expression at index {i,j}.
*
* @return
*/
inline const REAL_T GetValue(size_t i, size_t j = 0) const {
return std::floor(expr_m.GetValue(i, j));
}
/**
* Returns false.
*
* @return
*/
inline bool IsNonlinear() const {
return false;
}
/**
* Push variable info into a set.
*
* @param ids
*/
inline void PushIds(typename atl::StackEntry<REAL_T>::vi_storage& ids)const {
expr_m.PushIds(ids);
}
/**
* Push variable info into a set at index {i,j}.
*
* @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 {
expr_m.PushIds(ids, i, j);
}
inline void PushNLIds(typename atl::StackEntry<REAL_T>::vi_storage& ids, bool nl = false)const {
expr_m.PushNLIds(ids, nl);
}
inline const std::complex<REAL_T> ComplexEvaluate(uint32_t x, REAL_T h = 1e-20) const {
throw std::invalid_argument("floor not available for complex numbers");
// return std::floor(expr_m.ComplexEvaluate(x, h));
}
std::shared_ptr<DynamicExpressionBase<REAL_T> > ToDynamic() const {
return atl::floor(expr_m.ToDynamic());
}
/**
* Returns 0. Not differentiable.
*
* @param id
* @return
*/
inline const REAL_T EvaluateFirstDerivative(uint32_t id) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns 0. Not differentiable.
*
* @param a
* @param b
* @return
*/
inline REAL_T EvaluateSecondDerivative(uint32_t a, uint32_t b) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns 0. Not differentiable.
*
* @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. Not differentiable.
*
* @param id
* @param i
* @param j
* @return
*/
inline const REAL_T EvaluateFirstDerivativeAt(uint32_t id, size_t i, size_t j = 0) const {
return static_cast<REAL_T> (0.0);
}
/**
* Returns 0. Not differentiable.
*
* @param a
* @param b
* @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. Not differentiable.
*
* @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);
}
/**
* Return the number of columns.
*
* @return
*/
size_t GetColumns() const {
return expr_m.GetColumns();
}
/**
* Return the number of rows.
*
* @return
*/
size_t GetRows() const {
return expr_m.GetRows();
}
/**
* True if this expression is a scalar.
*
* @return
*/
bool IsScalar() const {
return expr_m.IsScalar();
}
/**
* Create a string representation of this expression template.
* @return
*/
const std::string ToExpressionTemplateString() const {
std::stringstream ss;
ss << "atl::Floor<T," << expr_m.ToExpressionTemplateString() << " >";
return ss.str();
}
const EXPR& expr_m;
};
/**
* Returns an expression template representing floor.
*
* @param exp
* @return
*/
template<class REAL_T, class EXPR>
inline const Floor<REAL_T, EXPR> floor(const ExpressionBase<REAL_T, EXPR>& exp) {
return Floor<REAL_T, EXPR>(exp.Cast());
}
}//end namespace atl
#endif