Loading...
Searching...
No Matches
SymEngine::LambdaDoubleVisitor< T > Class Template Reference
+ Inheritance diagram for SymEngine::LambdaDoubleVisitor< T >:
+ Collaboration diagram for SymEngine::LambdaDoubleVisitor< T >:

Public Member Functions

 LambdaDoubleVisitor (LambdaDoubleVisitor &&)=default
 
LambdaDoubleVisitoroperator= (LambdaDoubleVisitor &&)=default
 
 LambdaDoubleVisitor (const LambdaDoubleVisitor &)=delete
 
LambdaDoubleVisitoroperator= (const LambdaDoubleVisitor &)=delete
 
void init (const vec_basic &x, const Basic &b, bool cse=false)
 
void init (const vec_basic &inputs, const vec_basic &outputs, bool cse=false)
 
fn apply (const Basic &b)
 
call (const std::vector< T > &vec)
 
void call (T *outs, const T *inps)
 
void bvisit (const Symbol &x)
 
void bvisit (const Integer &x)
 
void bvisit (const Rational &x)
 
void bvisit (const RealDouble &x)
 
void bvisit (const Add &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Pow &x)
 
void bvisit (const Sin &x)
 
void bvisit (const Cos &x)
 
void bvisit (const Tan &x)
 
void bvisit (const Log &x)
 
void bvisit (const Cot &x)
 
void bvisit (const Csc &x)
 
void bvisit (const Sec &x)
 
void bvisit (const ASin &x)
 
void bvisit (const ACos &x)
 
void bvisit (const ASec &x)
 
void bvisit (const ACsc &x)
 
void bvisit (const ATan &x)
 
void bvisit (const ACot &x)
 
void bvisit (const Sinh &x)
 
void bvisit (const Csch &x)
 
void bvisit (const Cosh &x)
 
void bvisit (const Sech &x)
 
void bvisit (const Tanh &x)
 
void bvisit (const Coth &x)
 
void bvisit (const ASinh &x)
 
void bvisit (const ACsch &x)
 
void bvisit (const ACosh &x)
 
void bvisit (const ATanh &x)
 
void bvisit (const ACoth &x)
 
void bvisit (const ASech &x)
 
void bvisit (const Constant &x)
 
void bvisit (const Abs &x)
 
void bvisit (const Basic &)
 
void bvisit (const UnevaluatedExpr &x)
 

Protected Types

typedef std::function< T(const T *x)> fn
 

Protected Attributes

std::vector< fnresults
 
std::vector< T > cse_intermediate_results
 
std::map< RCP< const Basic >, size_t, RCPBasicKeyLesscse_intermediate_fns_map
 
std::vector< fncse_intermediate_fns
 
fn result_
 
vec_basic symbols
 

Detailed Description

template<typename T>
class SymEngine::LambdaDoubleVisitor< T >

Definition at line 14 of file lambda_double.h.

Member Typedef Documentation

◆ fn

template<typename T >
typedef std::function<T(const T *x)> SymEngine::LambdaDoubleVisitor< T >::fn
protected

Definition at line 25 of file lambda_double.h.

Member Function Documentation

◆ apply()

template<typename T >
fn SymEngine::LambdaDoubleVisitor< T >::apply ( const Basic b)
inline

Definition at line 86 of file lambda_double.h.

87 {
88 b.accept(*this);
89 return result_;
90 }

◆ bvisit() [1/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Abs x)
inline

Definition at line 349 of file lambda_double.h.

350 {
351 fn tmp = apply(*(x.get_arg()));
352 result_ = [=](const T *x) { return std::abs(tmp(x)); };
353 };

◆ bvisit() [2/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ACos x)
inline

Definition at line 241 of file lambda_double.h.

242 {
243 fn tmp = apply(*(x.get_arg()));
244 result_ = [=](const T *x) { return std::acos(tmp(x)); };
245 };
T acos(T... args)

◆ bvisit() [3/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ACosh x)
inline

Definition at line 319 of file lambda_double.h.

320 {
321 fn tmp = apply(*(x.get_arg()));
322 result_ = [=](const T *x) { return std::acosh(tmp(x)); };
323 };
T acosh(T... args)

◆ bvisit() [4/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ACot x)
inline

Definition at line 265 of file lambda_double.h.

266 {
267 fn tmp = apply(*(x.get_arg()));
268 result_ = [=](const T *x) { return std::atan(1.0 / tmp(x)); };
269 };
T atan(T... args)

◆ bvisit() [5/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ACoth x)
inline

Definition at line 331 of file lambda_double.h.

332 {
333 fn tmp = apply(*(x.get_arg()));
334 result_ = [=](const T *x) { return std::atanh(1.0 / tmp(x)); };
335 };
T atanh(T... args)

◆ bvisit() [6/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ACsc x)
inline

Definition at line 253 of file lambda_double.h.

254 {
255 fn tmp = apply(*(x.get_arg()));
256 result_ = [=](const T *x) { return std::asin(1.0 / tmp(x)); };
257 };
T asin(T... args)

◆ bvisit() [7/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ACsch x)
inline

Definition at line 313 of file lambda_double.h.

314 {
315 fn tmp = apply(*(x.get_arg()));
316 result_ = [=](const T *x) { return std::asinh(1.0 / tmp(x)); };
317 };
T asinh(T... args)

◆ bvisit() [8/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Add x)
inline

Definition at line 156 of file lambda_double.h.

157 {
158 fn tmp = apply(*x.get_coef());
159 fn tmp1, tmp2;
160 for (const auto &p : x.get_dict()) {
161 tmp1 = apply(*(p.first));
162 tmp2 = apply(*(p.second));
163 tmp = [=](const T *x) { return tmp(x) + tmp1(x) * tmp2(x); };
164 }
165 result_ = tmp;
166 }

◆ bvisit() [9/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ASec x)
inline

Definition at line 247 of file lambda_double.h.

248 {
249 fn tmp = apply(*(x.get_arg()));
250 result_ = [=](const T *x) { return std::acos(1.0 / tmp(x)); };
251 };

◆ bvisit() [10/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ASech x)
inline

Definition at line 337 of file lambda_double.h.

338 {
339 fn tmp = apply(*(x.get_arg()));
340 result_ = [=](const T *x) { return std::acosh(1.0 / tmp(x)); };
341 };

◆ bvisit() [11/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ASin x)
inline

Definition at line 235 of file lambda_double.h.

236 {
237 fn tmp = apply(*(x.get_arg()));
238 result_ = [=](const T *x) { return std::asin(tmp(x)); };
239 };

◆ bvisit() [12/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ASinh x)
inline

Definition at line 307 of file lambda_double.h.

308 {
309 fn tmp = apply(*(x.get_arg()));
310 result_ = [=](const T *x) { return std::asinh(tmp(x)); };
311 };

◆ bvisit() [13/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ATan x)
inline

Definition at line 259 of file lambda_double.h.

260 {
261 fn tmp = apply(*(x.get_arg()));
262 result_ = [=](const T *x) { return std::atan(tmp(x)); };
263 };

◆ bvisit() [14/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const ATanh x)
inline

Definition at line 325 of file lambda_double.h.

326 {
327 fn tmp = apply(*(x.get_arg()));
328 result_ = [=](const T *x) { return std::atanh(tmp(x)); };
329 };

◆ bvisit() [15/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Basic )
inline

Definition at line 355 of file lambda_double.h.

356 {
357 throw NotImplementedError("Not Implemented");
358 };

◆ bvisit() [16/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Constant x)
inline

Definition at line 343 of file lambda_double.h.

344 {
345 T tmp = eval_double(x);
346 result_ = [=](const T *x) { return tmp; };
347 };

◆ bvisit() [17/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Cos x)
inline

Definition at line 199 of file lambda_double.h.

200 {
201 fn tmp = apply(*(x.get_arg()));
202 result_ = [=](const T *x) { return std::cos(tmp(x)); };
203 }
T cos(T... args)

◆ bvisit() [18/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Cosh x)
inline

Definition at line 283 of file lambda_double.h.

284 {
285 fn tmp = apply(*(x.get_arg()));
286 result_ = [=](const T *x) { return std::cosh(tmp(x)); };
287 };
T cosh(T... args)

◆ bvisit() [19/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Cot x)
inline

Definition at line 217 of file lambda_double.h.

218 {
219 fn tmp = apply(*(x.get_arg()));
220 result_ = [=](const T *x) { return 1.0 / std::tan(tmp(x)); };
221 };
T tan(T... args)

◆ bvisit() [20/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Coth x)
inline

Definition at line 301 of file lambda_double.h.

302 {
303 fn tmp = apply(*(x.get_arg()));
304 result_ = [=](const T *x) { return 1.0 / std::tanh(tmp(x)); };
305 };
T tanh(T... args)

◆ bvisit() [21/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Csc x)
inline

Definition at line 223 of file lambda_double.h.

224 {
225 fn tmp = apply(*(x.get_arg()));
226 result_ = [=](const T *x) { return 1.0 / std::sin(tmp(x)); };
227 };
T sin(T... args)

◆ bvisit() [22/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Csch x)
inline

Definition at line 277 of file lambda_double.h.

278 {
279 fn tmp = apply(*(x.get_arg()));
280 result_ = [=](const T *x) { return 1.0 / std::sinh(tmp(x)); };
281 };
T sinh(T... args)

◆ bvisit() [23/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Integer x)
inline

Definition at line 130 of file lambda_double.h.

131 {
132 T tmp = mp_get_d(x.as_integer_class());
133 result_ = [=](const T *x_) { return tmp; };
134 }

◆ bvisit() [24/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Log x)
inline

Definition at line 211 of file lambda_double.h.

212 {
213 fn tmp = apply(*(x.get_arg()));
214 result_ = [=](const T *x) { return std::log(tmp(x)); };
215 };
T log(T... args)

◆ bvisit() [25/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Mul x)
inline

Definition at line 168 of file lambda_double.h.

169 {
170 fn tmp = apply(*x.get_coef());
171 fn tmp1, tmp2;
172 for (const auto &p : x.get_dict()) {
173 tmp1 = apply(*(p.first));
174 tmp2 = apply(*(p.second));
175 tmp = [=](const T *x) {
176 return tmp(x) * std::pow(tmp1(x), tmp2(x));
177 };
178 }
179 result_ = tmp;
180 }
T pow(T... args)

◆ bvisit() [26/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Pow x)
inline

Definition at line 182 of file lambda_double.h.

183 {
184 fn exp_ = apply(*(x.get_exp()));
185 if (eq(*(x.get_base()), *E)) {
186 result_ = [=](const T *x) { return std::exp(exp_(x)); };
187 } else {
188 fn base_ = apply(*(x.get_base()));
189 result_ = [=](const T *x) { return std::pow(base_(x), exp_(x)); };
190 }
191 }
T exp(T... args)
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21

◆ bvisit() [27/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Rational x)
inline

Definition at line 136 of file lambda_double.h.

137 {
138 T tmp = mp_get_d(x.as_rational_class());
139 result_ = [=](const T *x) { return tmp; };
140 }

◆ bvisit() [28/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const RealDouble x)
inline

Definition at line 142 of file lambda_double.h.

143 {
144 T tmp = x.i;
145 result_ = [=](const T *x) { return tmp; };
146 }

◆ bvisit() [29/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Sec x)
inline

Definition at line 229 of file lambda_double.h.

230 {
231 fn tmp = apply(*(x.get_arg()));
232 result_ = [=](const T *x) { return 1.0 / std::cos(tmp(x)); };
233 };

◆ bvisit() [30/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Sech x)
inline

Definition at line 289 of file lambda_double.h.

290 {
291 fn tmp = apply(*(x.get_arg()));
292 result_ = [=](const T *x) { return 1.0 / std::cosh(tmp(x)); };
293 };

◆ bvisit() [31/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Sin x)
inline

Definition at line 193 of file lambda_double.h.

194 {
195 fn tmp = apply(*(x.get_arg()));
196 result_ = [=](const T *x) { return std::sin(tmp(x)); };
197 }

◆ bvisit() [32/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Sinh x)
inline

Definition at line 271 of file lambda_double.h.

272 {
273 fn tmp = apply(*(x.get_arg()));
274 result_ = [=](const T *x) { return std::sinh(tmp(x)); };
275 };

◆ bvisit() [33/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Symbol x)
inline

Definition at line 112 of file lambda_double.h.

113 {
114 for (unsigned i = 0; i < symbols.size(); ++i) {
115 if (eq(x, *symbols[i])) {
116 result_ = [=](const T *x) { return x[i]; };
117 return;
118 }
119 }
120 auto it = cse_intermediate_fns_map.find(x.rcp_from_this());
121 if (it != cse_intermediate_fns_map.end()) {
122 auto index = it->second;
123 T *cse_intermediate_result = &(cse_intermediate_results[index]);
124 result_ = [=](const T *x) { return *cse_intermediate_result; };
125 return;
126 }
127 throw SymEngineException("Symbol not in the symbols vector.");
128 };
T size(T... args)

◆ bvisit() [34/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Tan x)
inline

Definition at line 205 of file lambda_double.h.

206 {
207 fn tmp = apply(*(x.get_arg()));
208 result_ = [=](const T *x) { return std::tan(tmp(x)); };
209 }

◆ bvisit() [35/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const Tanh x)
inline

Definition at line 295 of file lambda_double.h.

296 {
297 fn tmp = apply(*(x.get_arg()));
298 result_ = [=](const T *x) { return std::tanh(tmp(x)); };
299 };

◆ bvisit() [36/36]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::bvisit ( const UnevaluatedExpr x)
inline

Definition at line 360 of file lambda_double.h.

361 {
362 apply(*x.get_arg());
363 };

◆ call() [1/2]

template<typename T >
T SymEngine::LambdaDoubleVisitor< T >::call ( const std::vector< T > &  vec)
inline

Definition at line 92 of file lambda_double.h.

93 {
94 T res;
95 call(&res, vec.data());
96 return res;
97 }
T data(T... args)

◆ call() [2/2]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::call ( T *  outs,
const T *  inps 
)
inline

Definition at line 99 of file lambda_double.h.

100 {
101 if (cse_intermediate_fns.size() > 0) {
102 for (unsigned i = 0; i < cse_intermediate_fns.size(); ++i) {
103 cse_intermediate_results[i] = cse_intermediate_fns[i](inps);
104 }
105 }
106 for (unsigned i = 0; i < results.size(); ++i) {
107 outs[i] = results[i](inps);
108 }
109 return;
110 }

◆ init() [1/2]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::init ( const vec_basic inputs,
const vec_basic outputs,
bool  cse = false 
)
inline

Definition at line 50 of file lambda_double.h.

52 {
53 results.clear();
54 cse_intermediate_fns.clear();
55 symbols = inputs;
56 if (not cse) {
57 for (auto &p : outputs) {
58 results.push_back(apply(*p));
59 }
60 } else {
61 vec_basic reduced_exprs;
62 vec_pair replacements;
63 // cse the outputs
64 SymEngine::cse(replacements, reduced_exprs, outputs);
65 cse_intermediate_results.resize(replacements.size());
66 for (auto &rep : replacements) {
67 auto res = apply(*(rep.second));
68 // Store the replacement symbol values in a dictionary for
69 // faster
70 // lookup for initialization
71 cse_intermediate_fns_map[rep.first]
72 = cse_intermediate_fns.size();
73 // Store it in a vector for faster use in call
74 cse_intermediate_fns.push_back(res);
75 }
76 // Generate functions for all the reduced exprs and save it
77 for (unsigned i = 0; i < outputs.size(); i++) {
78 results.push_back(apply(*reduced_exprs[i]));
79 }
80 // We don't need the cse_intermediate_fns_map anymore
81 cse_intermediate_fns_map.clear();
82 symbols.clear();
83 }
84 }
T clear(T... args)

◆ init() [2/2]

template<typename T >
void SymEngine::LambdaDoubleVisitor< T >::init ( const vec_basic x,
const Basic b,
bool  cse = false 
)
inline

Definition at line 44 of file lambda_double.h.

45 {
46 vec_basic outputs = {b.rcp_from_this()};
47 init(x, outputs, cse);
48 }

Field Documentation

◆ cse_intermediate_fns

template<typename T >
std::vector<fn> SymEngine::LambdaDoubleVisitor< T >::cse_intermediate_fns
protected

Definition at line 31 of file lambda_double.h.

◆ cse_intermediate_fns_map

template<typename T >
std::map<RCP<const Basic>, size_t, RCPBasicKeyLess> SymEngine::LambdaDoubleVisitor< T >::cse_intermediate_fns_map
protected

Definition at line 30 of file lambda_double.h.

◆ cse_intermediate_results

template<typename T >
std::vector<T> SymEngine::LambdaDoubleVisitor< T >::cse_intermediate_results
protected

Definition at line 27 of file lambda_double.h.

◆ result_

template<typename T >
fn SymEngine::LambdaDoubleVisitor< T >::result_
protected

Definition at line 32 of file lambda_double.h.

◆ results

template<typename T >
std::vector<fn> SymEngine::LambdaDoubleVisitor< T >::results
protected

Definition at line 26 of file lambda_double.h.

◆ symbols

template<typename T >
vec_basic SymEngine::LambdaDoubleVisitor< T >::symbols
protected

Definition at line 33 of file lambda_double.h.


The documentation for this class was generated from the following file: