File indexing completed on 2025-01-30 10:03:27
0001
0002
0003 #include "SymToArgAdaptor.hh"
0004 #include <assert.h>
0005 #include <iostream>
0006 #include <cfloat>
0007
0008 namespace Genfun {
0009
0010
0011
0012
0013 template <class F>
0014 inline
0015 FunctionComposition SymToArgAdaptor<F>::operator()(const AbsFunction & function) const
0016 {
0017 return AbsFunction::operator() (function);
0018 }
0019
0020 template <class F>
0021 inline
0022 SymToArgAdaptor<F> *SymToArgAdaptor<F>::clone () const {
0023 return (SymToArgAdaptor<F> *) _clone();
0024 }
0025
0026 template <class F>
0027 inline
0028 AbsFunction *SymToArgAdaptor<F>::_clone () const {
0029 return new SymToArgAdaptor<F>(*this);
0030 }
0031 template <class F>
0032 inline
0033 ParameterComposition SymToArgAdaptor<F>::operator()(const AbsParameter & p) const
0034 { \
0035 return AbsFunction::operator() (p); \
0036 }
0037
0038 template<class F>
0039 inline
0040 SymToArgAdaptor<F>::SymToArgAdaptor(F &function,
0041 const AbsFunction & f_expression,
0042 SymToArgAdaptor<F>::ScopedMethodPtr parameterFetchMethod,
0043 const AbsFunction * p_expression):
0044
0045 _function(function.clone()),
0046 _f_expression(f_expression.clone()),
0047 _parameterFetchMethod(parameterFetchMethod),
0048 _p_expression(p_expression->clone())
0049
0050 {
0051 _parameterFetchMethod(*_function).setLowerLimit(-DBL_MAX);
0052 _parameterFetchMethod(*_function).setUpperLimit(+DBL_MAX);
0053 assert(f_expression.dimensionality()==p_expression->dimensionality());
0054 }
0055
0056 template <class F>
0057 inline
0058 SymToArgAdaptor<F>::~SymToArgAdaptor() {
0059 delete _function;
0060 delete _f_expression;
0061 delete _p_expression;
0062 }
0063
0064 template <class F>
0065 inline
0066 SymToArgAdaptor<F>::SymToArgAdaptor(const SymToArgAdaptor & right):
0067 _function(right._function->clone()),
0068 _f_expression(right._f_expression->clone()),
0069 _parameterFetchMethod(right._parameterFetchMethod),
0070 _p_expression(right._p_expression->clone())
0071 {
0072 _parameterFetchMethod(*_function).setLowerLimit(-DBL_MAX);
0073 _parameterFetchMethod(*_function).setUpperLimit(+DBL_MAX);
0074 }
0075
0076
0077 template <class F>
0078 inline
0079 double SymToArgAdaptor<F>::operator ()(double x) const
0080 {
0081 std::cerr
0082 << "Warning. SymToArgAdaptor called with scalar argument"
0083 << std::endl;
0084 assert(0);
0085 return 0;
0086 }
0087
0088 template <class F>
0089 inline
0090 unsigned int SymToArgAdaptor<F>::dimensionality() const {
0091 return _f_expression->dimensionality();
0092 }
0093
0094 template <class F>
0095 inline
0096 double SymToArgAdaptor<F>::operator() (const Argument & a) const {
0097 if (dimensionality()!= a.dimension()) {
0098 std::cerr
0099 << "Warning: SymToArgAdaptor function/argument dimension mismatch"
0100 << std::endl;
0101 assert(0);
0102 return 0;
0103 }
0104
0105
0106 double pVal= (*_p_expression)(a);
0107
0108
0109 (_parameterFetchMethod(*_function)).setValue(pVal);
0110
0111
0112 return (*_function)((*_f_expression) (a));
0113 }
0114 }
0115
0116