1 // SWIG file OptimizationAlgorithmImplementation.i
2
3 %{
4 #include "openturns/OptimizationAlgorithmImplementation.hxx"
5 #include "openturns/PythonWrappingFunctions.hxx"
6
OptimizationAlgorithmImplementation_ProgressCallback(OT::Scalar percent,void * data)7 static void OptimizationAlgorithmImplementation_ProgressCallback(OT::Scalar percent, void * data) {
8 PyObject * pyObj = reinterpret_cast<PyObject *>(data);
9 OT::ScopedPyObjectPointer point(OT::convert< OT::Scalar, OT::_PyFloat_ >(percent));
10 OT::ScopedPyObjectPointer result(PyObject_CallFunctionObjArgs(pyObj, point.get(), NULL));
11 if (result.isNull())
12 OT::handleException();
13 }
14
OptimizationAlgorithmImplementation_StopCallback(void * data)15 static OT::Bool OptimizationAlgorithmImplementation_StopCallback(void * data) {
16 PyObject * pyObj = reinterpret_cast<PyObject *>(data);
17 OT::ScopedPyObjectPointer result(PyObject_CallFunctionObjArgs(pyObj, NULL));
18 if (result.isNull())
19 OT::handleException();
20 return OT::checkAndConvert< OT::_PyInt_, OT::UnsignedInteger >(result.get());
21 }
22 %}
23
24 %include OptimizationAlgorithmImplementation_doc.i
25
26 %ignore OT::OptimizationAlgorithmImplementation::setProgressCallback(ProgressCallback callBack, void * data);
27 %ignore OT::OptimizationAlgorithmImplementation::setStopCallback(StopCallback callBack, void * data);
28
29 %include openturns/OptimizationAlgorithmImplementation.hxx
30 namespace OT{ %extend OptimizationAlgorithmImplementation {
31
32
OptimizationAlgorithmImplementation(const OptimizationAlgorithmImplementation & other)33 OptimizationAlgorithmImplementation(const OptimizationAlgorithmImplementation & other) {
34 return new OT::OptimizationAlgorithmImplementation(other);
35 }
36
setProgressCallback(PyObject * callBack)37 void setProgressCallback(PyObject * callBack) {
38 if (PyCallable_Check(callBack)) {
39 self->setProgressCallback(&OptimizationAlgorithmImplementation_ProgressCallback, callBack);
40 }
41 else {
42 throw OT::InvalidArgumentException(HERE) << "Argument is not a callable object.";
43 }
44 }
45
setStopCallback(PyObject * callBack)46 void setStopCallback(PyObject * callBack) {
47 if (PyCallable_Check(callBack)) {
48 self->setStopCallback(&OptimizationAlgorithmImplementation_StopCallback, callBack);
49 }
50 else {
51 throw OT::InvalidArgumentException(HERE) << "Argument is not a callable object.";
52 }
53 }
54
55 } }
56