30 if ( pyself && pyself != Py_None ) {
31 pymethod = PyObject_GetAttrString( (
PyObject*)pyself,
const_cast< char*
>( method ) );
35 Py_XDECREF( pymethod );
54 result = PyObject_CallFunctionObjArgs( pymethod, arg1, arg2, arg3, NULL );
58 PyErr_Format( PyExc_AttributeError,
59 "method %s needs implementing in derived class",
const_cast< char*
>( method ) );
62 Py_XDECREF( pymethod );
100 throw std::runtime_error(
"Failure in TPyMultiGenFunction::NDim" );
103 unsigned int cppresult = (
unsigned int)PyLong_AsLong( pyresult );
104 Py_XDECREF( pyresult );
120 throw std::runtime_error(
"Failure in TPyMultiGenFunction::DoEval" );
123 double cppresult = (double)PyFloat_AsDouble( pyresult );
124 Py_XDECREF( pyresult );
139 Py_INCREF( Py_None );
163 throw std::runtime_error(
"Failure in TPyMultiGradFunction::NDim" );
166 unsigned int cppresult = (
unsigned int)PyLong_AsLong( pyresult );
167 Py_XDECREF( pyresult );
183 throw std::runtime_error(
"Failure in TPyMultiGradFunction::DoEval" );
186 double cppresult = (double)PyFloat_AsDouble( pyresult );
187 Py_XDECREF( pyresult );
207 throw std::runtime_error(
"Failure in TPyMultiGradFunction::Gradient" );
210 Py_DECREF( pyresult );
226 PyList_SetItem( pyf, 0, PyFloat_FromDouble(
f ) );
230 f = PyFloat_AsDouble( PyList_GetItem( pyf, 0 ) );
238 throw std::runtime_error(
"Failure in TPyMultiGradFunction::FdF" );
241 Py_DECREF( pyresult );
253 PyObject* pycoord = PyLong_FromLong( icoord );
256 Py_DECREF( pycoord );
261 throw std::runtime_error(
"Failure in TPyMultiGradFunction::DoDerivative" );
264 double cppresult = (double)PyFloat_AsDouble( pyresult );
265 Py_XDECREF( pyresult );
static PyObject * GetOverriddenPyMethod(PyObject *pyself, const char *method)
static PyObject * DispatchCall(PyObject *pyself, const char *method, PyObject *pymethod=NULL, PyObject *arg1=NULL, PyObject *arg2=NULL, PyObject *arg3=NULL)
PyObject * PyBuffer_FromMemory(Bool_t *buf, Py_ssize_t size=-1)
static TPyBufferFactory * Instance()
virtual void Gradient(const T *x, T *grad) const
Evaluate all the vector of function derivatives (gradient) at a point x.
virtual void FdF(const T *x, T &f, T *df) const
Optimized method to evaluate at the same time the function value and derivative at a point x.
virtual unsigned int NDim() const
Retrieve the dimension of the function.
TPyMultiGenFunction(PyObject *self=0)
virtual double DoEval(const double *x) const
Simply forward the call to python self.
virtual ~TPyMultiGenFunction()
Destructor. Only deref if still holding on to Py_None (circular otherwise).
TPyMultiGradFunction(PyObject *self=0)
virtual unsigned int NDim() const
Retrieve the dimension of the function.
virtual void Gradient(const double *x, double *grad) const
Simply forward the call to python self.
virtual double DoDerivative(const double *x, unsigned int icoord) const
Simply forward the call to python self.
virtual ~TPyMultiGradFunction()
Destructor. Only deref if still holding on to Py_None (circular otherwise).
virtual double DoEval(const double *x) const
Simply forward the call to python self.
virtual void FdF(const double *x, double &f, double *df) const
Simply forward the call to python self.
Bool_t MethodProxy_CheckExact(T *object)