Skip to content

Commit

Permalink
Translate python errors to exceptions during fit func calls.
Browse files Browse the repository at this point in the history
Avoiding the boost python wrappers means we have to handle this too.
Refs #970
  • Loading branch information
martyngigg committed Apr 19, 2013
1 parent 29e2087 commit ef94fe0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ namespace Mantid
// boost::python::objects whn using boost::python::call_method

PyObject *result = PyEval_CallMethod(getSelf(), "function1D", "(O)", xvals);
PyArrayObject *nparray = (PyArrayObject *)(result);
if(PyErr_Occurred()) Environment::translateErrorToException(true);

PyArrayObject *nparray = (PyArrayObject *)(result);
if(PyArray_TYPE(nparray) == NPY_DOUBLE) // dtype matches so use memcpy for speed
{
std::memcpy(static_cast<void*>(out), PyArray_DATA(nparray), nData*sizeof(npy_double));
Expand Down Expand Up @@ -98,7 +99,8 @@ namespace Mantid
// Deliberately avoids using the CallMethod wrappers. They lock the GIL again and
// will check for each function call whether the wrapped method exists. It also avoid unnecessary construction of
// boost::python::objects when using boost::python::call_method
PyEval_CallMethod(getSelf(), "functionDerivLocal", "(OO)", xvals,jacobian);
PyEval_CallMethod(getSelf(), "functionDeriv1D", "(OO)", xvals,jacobian);
if(PyErr_Occurred()) Environment::translateErrorToException(true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ namespace Mantid
// boost::python::objects whn using boost::python::call_method

PyObject *result = PyEval_CallMethod(getSelf(), "functionLocal", "(O)", xvals);
PyArrayObject *nparray = (PyArrayObject *)(result);
if(PyErr_Occurred()) Environment::translateErrorToException(true);

PyArrayObject *nparray = (PyArrayObject *)(result);
if(PyArray_TYPE(nparray) == NPY_DOUBLE) // dtype matches so use memcpy for speed
{
std::memcpy(static_cast<void*>(out), PyArray_DATA(nparray), nData*sizeof(npy_double));
Expand Down Expand Up @@ -148,6 +149,7 @@ namespace Mantid
// will check for each function call whether the wrapped method exists. It also avoid unnecessary construction of
// boost::python::objects when using boost::python::call_method
PyEval_CallMethod(getSelf(), "functionDerivLocal", "(OO)", xvals,jacobian);
if(PyErr_Occurred()) Environment::translateErrorToException(true);
}

/**
Expand Down

0 comments on commit ef94fe0

Please sign in to comment.