13 #include <boost/python.hpp> 36 class_ < FunctionWrap, std::auto_ptr < FunctionWrap> >
38 "The base class for raw functions. FunctionBase objects need to\n" 39 "wrapped with Function objects to be displayed. FunctionBase\n" 40 "can be derived from and cloned so they can be added to the\n" 42 init < const FunctionBase & >
43 (
"FunctionBase () -> FunctionBase\n" 44 "FunctionBase ( FunctionBase ) -> FunctionBase\n" 46 "Constructors of the FunctionBase object.\n" ) )
50 .def ( init < const FunctionWrap & > () )
52 .def (
"initialize", &FunctionWrap::initialize,
53 "initialize () -> None\n" 55 "Initializes the function parameter values and the names.\n" 56 "The number of parameters is taken from the number of names." )
58 .def (
"name", &FunctionBase::name,
59 return_value_policy < copy_const_reference > (),
62 "Returns the name of the function." )
64 .def (
"setName", &FunctionWrap::setName,
65 "setName ( string ) -> None\n" 67 "Sets the name of the function." )
70 &FunctionBase::parmNames,
71 return_value_policy < copy_const_reference > (),
72 "parmNames () -> sequence\n" 74 "Returns the names of the parameters" )
76 .def (
"setParmNames",
77 &FunctionWrap::setParmNames,
78 "setParmNames ( sequence ) -> None\n" 80 "Sets the parameter names and re-sizes the parameters" )
82 .def (
"setParameters",
84 (
const std::vector < double > & ) )
85 &FunctionBase::setParameters,
86 "setParameters ( sequence ) -> None\n" 88 "Sets the values of the parameters." )
90 .def (
"getParameters", &FunctionBase::getParameters,
91 return_value_policy < copy_const_reference > (),
92 "getParameters () -> sequence\n" 94 "Returns the current function parameter values." )
124 #ifndef HAVE_OLD_PYTHON 125 PyGILState_STATE state = PyGILState_Ensure ();
127 extract<std::auto_ptr<FunctionWrap>&> x(
get_owner(
this));
128 if ( x.check() ) x().release();
130 PyGILState_Release ( state );
143 object ( handle<> ( borrowed ( detail::wrapper_base_::get_owner(*
this))));
150 unsigned int dims = 0;
151 #ifndef HAVE_OLD_PYTHON 152 PyGILState_STATE state = PyGILState_Ensure ();
154 if (
override member =
this -> get_override (
"dimensions" ) ) {
157 dims = call_method < unsigned int > (
self.ptr(),
"dimensions" );
162 PyGILState_Release ( state );
174 if (
override member =
this -> get_override (
"derivByParm" ) ) {
185 #ifndef HAVE_OLD_PYTHON 186 PyGILState_STATE state = PyGILState_Ensure ();
190 if (
override clone = this->get_override(
"clone")) {
194 py_result (
clone() );
195 }
catch ( error_already_set & ) {
198 PyGILState_Release ( state );
206 object my_class =
self.attr(
"__class__");
208 py_result = my_class ( );
209 }
catch ( error_already_set & ) {
212 PyGILState_Release ( state );
217 FunctionWrap* result = extract<FunctionWrap*>(py_result);
221 PyGILState_Release ( state );
257 #ifndef HAVE_OLD_PYTHON 259 PyGILState_STATE state = PyGILState_Ensure ();
265 value = call_method < double, int, double >
266 (
self.ptr(),
"derivByParm", i, x );
271 PyGILState_Release ( state );
285 #ifndef HAVE_OLD_PYTHON 286 PyGILState_STATE state = PyGILState_Ensure ();
290 call_method < void > (
self.ptr(),
"initialize" );
293 PyGILState_Release ( state );
307 #ifndef HAVE_OLD_PYTHON 308 PyGILState_STATE state = PyGILState_Ensure ();
313 value = call_method < double, double > (
self.ptr(),
"valueAt", x );
314 PyGILState_Release ( state );
316 catch (
const error_already_set & ) {
317 PyGILState_Release ( state );
333 #ifndef HAVE_OLD_PYTHON 334 PyGILState_STATE state = PyGILState_Ensure ();
337 unsigned int size = x.size();
341 value = call_method < double, double, double >
342 (
self.ptr(),
"valueAt", x[0], x[1] );
345 value = call_method < double, double, double, double >
346 (
self.ptr(),
"valueAt", x[0], x[1], x[2] );
351 PyGILState_Release ( state );
363 #endif // BOOST_DEFECT unsigned int dimensions() const
Returns the number of dimensions of the data coordinate.
virtual unsigned int dimensions() const
Returns the number of dimensions of the data coordinate.
std::vector< std::string > m_parm_names
The names of the function parameters.
virtual ~FunctionWrap()
The destructor.
boost::python::object invert_ownership
The new ownership.
A wrapper class for FunctionBase.
double derivByParm(int, double) const
void setName(const char *)
Sets the name of the function.
virtual int size() const
Returns the number of parameters.
FunctionBase * clone() const
Make copy of object, including copy of Python object.
void export_FunctionBase()
Export the FunctionBase and its FunctionWrap.
double operator()(double) const
void setParmNames(const std::vector< std::string > &names)
Sets the names of the parameters and re-sizes the number of parameters available. ...
virtual bool hasDerivatives() const
Returns true if the Python function has implemented returning partial derivatives.
A function that can be added to a DataRep and used in a fitter.
void initialParameters(const FunctionHelper *)
Sets the FunctionHelper so that the function can calculate a reasonable set of initial parameter valu...
hippodraw::FunctionWrap class interface.
An abstract base class to help FunctionBase objects perform some operations.
virtual void resize()
Re-sizes the appropriate vectors maintained in this base class.
FunctionWrap()
The default constructor.
const std::string & name() const
Returns the name of the function.
boost::python::object get_owner(T *me) const
Find the Python object that owns this object.
void setName(const std::string &name)
Sets the name of the function.