Mantid
Loading...
Searching...
No Matches
Namespaces | Classes | Functions
Mantid::PythonInterface Namespace Reference

Namespaces

namespace  Converters
 
namespace  detail
 
namespace  Policies
 
namespace  Registry
 

Classes

class  AlgorithmAdapter
 Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python object that is derived an Algorithm. More...
 
class  AlgorithmFactoryObserverAdapter
 A wrapper class helping to export AnalysisDataServiceObserver to python. More...
 
struct  AlgorithmIDProxy
 Provides a concrete type to wrap & return AlgorithmIDs that are actually just typedefs for void*. More...
 
class  AlgorithmObserverAdapter
 A wrapper class helping to export AlgorithmObserver to python. More...
 
class  AnalysisDataServiceObserverAdapter
 A wrapper class helping to export AnalysisDataServiceObserver to python. More...
 
class  DataProcessorAdapter
 Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python object that is derived an DataProcessorAlgorithm. More...
 
struct  DataServiceExporter
 A helper struct to export templated DataService<> types to Python. More...
 
struct  ExtractSharedPtr
 
struct  GILSharedPtrDeleter
 Special shared_ptr::deleter object that locks the GIL while deleting the underlying Python object. More...
 
struct  GILState
 
class  GlobalInterpreterLock
 Defines a structure for acquiring/releasing the Python GIL using the RAII pattern. More...
 
class  IFunction1DAdapter
 Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python object that is derived from IFunction1D. More...
 
class  IFunctionAdapter
 Provides a layer to hook into the protected functions of IFunction. More...
 
class  IPeakFunctionAdapter
 Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python object that is derived from IPeakFunction. More...
 
class  IPyTypeVisitor
 
class  NDArray
 Thin object wrapper around a numpy array. More...
 
struct  PropertyWithValueExporter
 A helper struct to export PropertyWithValue<> types to Python. More...
 
struct  PyNativeTypeExtractor
 
class  PythonException
 Exception type that captures the current Python error state as a generic C++ exception for any general Python exception. More...
 
class  PythonObjectInstantiator
 
class  ReleaseGlobalInterpreterLock
 Defines a structure for releasing the Python GIL using the RAII pattern. More...
 
class  RunPythonScript
 
class  SpectrumInfoPythonIterator
 SpectrumInfoPythonIterator. More...
 
struct  std_set_exporter
 std::set wrapper More...
 
struct  std_vector_exporter
 A struct to help export std::vector types. More...
 
struct  TypedValidatorExporter
 Declares a simple static struct to export a TypedValidator to Python. More...
 
struct  UndefinedAttributeError
 Defines an exception for an undefined attribute. More...
 
class  UninstallTrace
 RAII handler to temporarily remove and reinstall a Python trace function. More...
 
struct  WorkspacePropertyExporter
 A helper struct to export WorkspaceProperty<> types to Python. More...
 

Functions

template<typename ReturnType , typename... Args>
ReturnType callMethod (PyObject *obj, const char *methodName, const Args &...args)
 Wrapper around boost::python::call_method to acquire GIL for duration of call. More...
 
template<typename ReturnType , typename... Args>
ReturnType callMethodNoCheck (const boost::python::object &obj, const char *methodName, const Args &...args)
 Wrapper around boost::python::call_method to acquire GIL for duration of call. More...
 
template<typename ReturnType , typename... Args>
ReturnType callMethodNoCheck (PyObject *obj, const char *methodName, const Args &...args)
 Wrapper around boost::python::call_method to acquire GIL for duration of call. More...
 
PyObject * cloneDx (const API::MatrixWorkspace &self)
 Create a numpy array from the E values of the given workspace reference. More...
 
PyObject * cloneE (const API::MatrixWorkspace &self)
 Create a numpy array from the E values of the given workspace reference. More...
 
PyObject * cloneX (const API::MatrixWorkspace &self)
 { Create a numpy array from the X values of the given workspace reference More...
 
PyObject * cloneY (const API::MatrixWorkspace &self)
 Create a numpy array from the Y values of the given workspace reference. More...
 
template<typename Copyable >
boost::python::object generic__copy__ (const bp::object &copyable)
 Create a shallow copy of type Copyable providing Copyable is newable and has a public copy constructor. More...
 
template<typename Copyable >
bp::object generic__deepcopy__ (const bp::object &copyable, bp::dict &memo)
 Create a deep copy of type Copyable providing Copyable is newable and has a public copy constructor. More...
 
MANTID_PYTHONINTERFACE_CORE_DLL void importNumpy ()
 Initialize the numpy array api for this DLL. More...
 
bool isNone (const boost::python::object &obj)
 
bool isNone (PyObject *ptr)
 
template<typename T >
PyObject * managingPyObject (T *p)
 Create a new object handle around arg. More...
 
MANTID_PYTHONINTERFACE_CORE_DLL PyTypeObject * ndarrayType ()
 Return the type object for a numpy.NDArray. More...
 
template IMDHistoWorkspace_sptr performBinaryOp (const IMDHistoWorkspace_sptr, const IMDHistoWorkspace_sptr, const std::string &, const std::string &name, bool, bool)
 
template IMDHistoWorkspace_sptr performBinaryOp (const IMDHistoWorkspace_sptr, const MatrixWorkspace_sptr, const std::string &, const std::string &name, bool, bool)
 
template IMDWorkspace_sptr performBinaryOp (const IMDWorkspace_sptr, const IMDWorkspace_sptr, const std::string &, const std::string &name, bool, bool)
 
template WorkspaceGroup_sptr performBinaryOp (const IMDWorkspace_sptr, const WorkspaceGroup_sptr, const std::string &, const std::string &name, bool, bool)
 
template WorkspaceGroup_sptr performBinaryOp (const WorkspaceGroup_sptr, const IMDWorkspace_sptr, const std::string &, const std::string &name, bool, bool)
 
template WorkspaceGroup_sptr performBinaryOp (const WorkspaceGroup_sptr, const WorkspaceGroup_sptr, const std::string &, const std::string &name, bool, bool)
 
template IMDHistoWorkspace_sptr performBinaryOpWithDouble (const IMDHistoWorkspace_sptr, const double, const std::string &op, const std::string &, bool, bool)
 
template IMDWorkspace_sptr performBinaryOpWithDouble (const IMDWorkspace_sptr, const double, const std::string &op, const std::string &, bool, bool)
 
template WorkspaceGroup_sptr performBinaryOpWithDouble (const WorkspaceGroup_sptr, const double, const std::string &op, const std::string &, bool, bool)
 
template<typename ElementType >
std::string toString (const ElementType &value)
 Convert an element type within a sequence to a string for printing. More...
 
template<typename SequenceType , typename ElementType >
std::string toString (const SequenceType &values)
 Convert a sequence of values to a string for printing. More...
 
template<>
std::string toString (const std::string &value)
 Convert a string element within a sequence to a string for printing. More...
 
bool MANTID_PYTHONINTERFACE_CORE_DLL typeHasAttribute (const boost::python::detail::wrapper_base &wrapper, const char *attr)
 An overload for the above taking a wrapper reference. More...
 
bool MANTID_PYTHONINTERFACE_CORE_DLL typeHasAttribute (PyObject *obj, const char *attr)
 This namespace contains helper functions for classes that are overridden in Python. More...
 
Binary operation helpers

Defines helpers to run the binary operation algorithms

template<typename LHSType , typename RHSType , typename ResultType >
ResultType performBinaryOp (const LHSType lhs, const RHSType rhs, const std::string &op, const std::string &name, bool inplace, bool reverse)
 Binary op for two workspaces. More...
 
template<typename LHSType , typename RHSType , typename ResultType >
ResultType performBinaryOpMD (const LHSType lhs, const RHSType rhs, const std::string &op, const std::string &name, bool inplace, bool reverse)
 Binary op for two MDworkspaces. More...
 
template<typename LHSType , typename ResultType >
ResultType performBinaryOpWithDouble (const LHSType inputWS, const double value, const std::string &op, const std::string &name, bool inplace, bool reverse)
 Binary op for a workspace and a double. More...
 
template<typename LHSType , typename ResultType >
ResultType performBinaryOpMDWithDouble (const LHSType lhs, const double value, const std::string &op, const std::string &name, bool inplace, bool reverse)
 Binary op for MDworkspaces + double. More...
 

Function Documentation

◆ callMethod()

template<typename ReturnType , typename... Args>
ReturnType Mantid::PythonInterface::callMethod ( PyObject *  obj,
const char *  methodName,
const Args &...  args 
)

Wrapper around boost::python::call_method to acquire GIL for duration of call.

If the attribute does not exist then an UndefinedAttributeError is thrown, if the call raises a Python error then this is translated to a C++ exception object inheriting from std::exception or std::runtime_error depending on the type of Python error.

Parameters
objPointer to Python object
methodNameName of the method call
argsA list of arguments to forward to call_method

Definition at line 87 of file CallMethod.h.

References callMethod(), Mantid::PythonInterface::detail::callMethodImpl(), obj, and typeHasAttribute().

Referenced by callMethod().

◆ callMethodNoCheck() [1/2]

template<typename ReturnType , typename... Args>
ReturnType Mantid::PythonInterface::callMethodNoCheck ( const boost::python::object &  obj,
const char *  methodName,
const Args &...  args 
)

Wrapper around boost::python::call_method to acquire GIL for duration of call.

If the call raises a Python error then this is translated to a C++ exception object inheriting from std::exception or std::runtime_error depending on the type of Python error. Overload for boost::python::object

Parameters
objReference to boost.python.object wrapper
methodNameName of the method call
argsA list of arguments to forward to call_method

Definition at line 71 of file CallMethod.h.

References Mantid::PythonInterface::detail::callMethodImpl(), callMethodNoCheck(), and obj.

◆ callMethodNoCheck() [2/2]

template<typename ReturnType , typename... Args>
ReturnType Mantid::PythonInterface::callMethodNoCheck ( PyObject *  obj,
const char *  methodName,
const Args &...  args 
)

Wrapper around boost::python::call_method to acquire GIL for duration of call.

If the call raises a Python error then this is translated to a C++ exception object inheriting from std::exception or std::runtime_error depending on the type of Python error.

Parameters
objPointer to Python object
methodNameName of the method call
argsA list of arguments to forward to call_method

Definition at line 56 of file CallMethod.h.

References Mantid::PythonInterface::detail::callMethodImpl(), callMethodNoCheck(), and obj.

Referenced by callMethodNoCheck().

◆ cloneDx()

PyObject * Mantid::PythonInterface::cloneDx ( const API::MatrixWorkspace self)

Create a numpy array from the E values of the given workspace reference.

Definition at line 114 of file CloneMatrixWorkspace.cpp.

References Mantid::API::MatrixWorkspace::getNumberHistograms().

Referenced by export_MatrixWorkspace().

◆ cloneE()

PyObject * Mantid::PythonInterface::cloneE ( const API::MatrixWorkspace self)

Create a numpy array from the E values of the given workspace reference.

Definition at line 105 of file CloneMatrixWorkspace.cpp.

References Mantid::API::MatrixWorkspace::getNumberHistograms().

Referenced by export_MatrixWorkspace().

◆ cloneX()

PyObject * Mantid::PythonInterface::cloneX ( const API::MatrixWorkspace self)

{ Create a numpy array from the X values of the given workspace reference

Definition at line 88 of file CloneMatrixWorkspace.cpp.

References Mantid::API::MatrixWorkspace::getNumberHistograms().

Referenced by export_MatrixWorkspace().

◆ cloneY()

PyObject * Mantid::PythonInterface::cloneY ( const API::MatrixWorkspace self)

Create a numpy array from the Y values of the given workspace reference.

Definition at line 96 of file CloneMatrixWorkspace.cpp.

References Mantid::API::MatrixWorkspace::getNumberHistograms().

Referenced by export_MatrixWorkspace().

◆ generic__copy__()

template<typename Copyable >
boost::python::object Mantid::PythonInterface::generic__copy__ ( const bp::object &  copyable)

Create a shallow copy of type Copyable providing Copyable is newable and has a public copy constructor.

Definition at line 31 of file Copyable.h.

References managingPyObject().

◆ generic__deepcopy__()

template<typename Copyable >
bp::object Mantid::PythonInterface::generic__deepcopy__ ( const bp::object &  copyable,
bp::dict &  memo 
)

Create a deep copy of type Copyable providing Copyable is newable and has a public copy constructor.

Definition at line 44 of file Copyable.h.

References managingPyObject().

◆ importNumpy()

void Mantid::PythonInterface::importNumpy ( )

Initialize the numpy array api for this DLL.

Exceptions
runtime_errorif Python is not initialized

Definition at line 22 of file NDArray.cpp.

Referenced by PythonInterpreterGlobalFixture::setUpWorld().

◆ isNone() [1/2]

bool Mantid::PythonInterface::isNone ( const boost::python::object &  obj)
inline
Parameters
objA const reference to boost python object wrapper
Returns
true if the given boost python object is of type None

Definition at line 32 of file IsNone.h.

References isNone(), and obj.

◆ isNone() [2/2]

bool Mantid::PythonInterface::isNone ( PyObject *  ptr)
inline

◆ managingPyObject()

template<typename T >
PyObject * Mantid::PythonInterface::managingPyObject ( T *  p)
inline

Create a new object handle around arg.

Caller is owner.

Definition at line 23 of file Copyable.h.

Referenced by generic__copy__(), and generic__deepcopy__().

◆ ndarrayType()

PyTypeObject * Mantid::PythonInterface::ndarrayType ( )

Return the type object for a numpy.NDArray.

Returns
PyTypeObject* to the Python C-type of nump.NDArray

Definition at line 38 of file NDArray.cpp.

◆ performBinaryOp() [1/7]

template IMDHistoWorkspace_sptr Mantid::PythonInterface::performBinaryOp ( const  IMDHistoWorkspace_sptr,
const  IMDHistoWorkspace_sptr,
const std::string &  ,
const std::string &  name,
bool  ,
bool   
)

◆ performBinaryOp() [2/7]

template IMDHistoWorkspace_sptr Mantid::PythonInterface::performBinaryOp ( const  IMDHistoWorkspace_sptr,
const  MatrixWorkspace_sptr,
const std::string &  ,
const std::string &  name,
bool  ,
bool   
)

◆ performBinaryOp() [3/7]

template IMDWorkspace_sptr Mantid::PythonInterface::performBinaryOp ( const  IMDWorkspace_sptr,
const  IMDWorkspace_sptr,
const std::string &  ,
const std::string &  name,
bool  ,
bool   
)

◆ performBinaryOp() [4/7]

template WorkspaceGroup_sptr Mantid::PythonInterface::performBinaryOp ( const  IMDWorkspace_sptr,
const  WorkspaceGroup_sptr,
const std::string &  ,
const std::string &  name,
bool  ,
bool   
)

◆ performBinaryOp() [5/7]

template<typename LHSType , typename RHSType , typename ResultType >
ResultType Mantid::PythonInterface::performBinaryOp ( const LHSType  lhs,
const RHSType  rhs,
const std::string &  op,
const std::string &  name,
bool  inplace,
bool  reverse 
)

Binary op for two workspaces.

Binary operation for two workspaces.

Generic for IMDWorkspaces or MatrixWorkspaces... Called by python overloads for _binary_op (see api_exports.cpp)

Parameters
lhs:: the left hand side workspace of the operation
rhs:: the right hand side workspace of the operation
op:: The operation
name:: The output name
inplace:: is this is an inplace operation (i.e. does the output overwrite the lhs
reverse:: Unused parameter. Here for consistent interface
Returns
The resulting workspace

Definition at line 84 of file BinaryOperations.cpp.

References error, and rhs.

Referenced by export_BinaryOperations().

◆ performBinaryOp() [6/7]

template WorkspaceGroup_sptr Mantid::PythonInterface::performBinaryOp ( const  WorkspaceGroup_sptr,
const  IMDWorkspace_sptr,
const std::string &  ,
const std::string &  name,
bool  ,
bool   
)

◆ performBinaryOp() [7/7]

template WorkspaceGroup_sptr Mantid::PythonInterface::performBinaryOp ( const  WorkspaceGroup_sptr,
const  WorkspaceGroup_sptr,
const std::string &  ,
const std::string &  name,
bool  ,
bool   
)

◆ performBinaryOpMD()

template<typename LHSType , typename RHSType , typename ResultType >
ResultType Mantid::PythonInterface::performBinaryOpMD ( const LHSType  lhs,
const RHSType  rhs,
const std::string &  op,
const std::string &  name,
bool  inplace,
bool  reverse 
)

Binary op for two MDworkspaces.

◆ performBinaryOpMDWithDouble()

template<typename LHSType , typename ResultType >
ResultType Mantid::PythonInterface::performBinaryOpMDWithDouble ( const LHSType  lhs,
const double  value,
const std::string &  op,
const std::string &  name,
bool  inplace,
bool  reverse 
)

Binary op for MDworkspaces + double.

◆ performBinaryOpWithDouble() [1/4]

template IMDHistoWorkspace_sptr Mantid::PythonInterface::performBinaryOpWithDouble ( const  IMDHistoWorkspace_sptr,
const double  ,
const std::string &  op,
const std::string &  ,
bool  ,
bool   
)

◆ performBinaryOpWithDouble() [2/4]

template IMDWorkspace_sptr Mantid::PythonInterface::performBinaryOpWithDouble ( const  IMDWorkspace_sptr,
const double  ,
const std::string &  op,
const std::string &  ,
bool  ,
bool   
)

◆ performBinaryOpWithDouble() [3/4]

template<typename LHSType , typename ResultType >
ResultType Mantid::PythonInterface::performBinaryOpWithDouble ( const LHSType  inputWS,
const double  value,
const std::string &  op,
const std::string &  name,
bool  inplace,
bool  reverse 
)

Binary op for a workspace and a double.

Perform the given binary operation on a workspace and a double.

Generic to MDWorkspaces. Called by python overloads for _binary_op (see api_exports.cpp)

Parameters
inputWS:: The input workspace
value:: The input value
op:: The operation
name:: The output name
inplace:: If true, then the lhs argument is replaced by the result of the operation.
reverse:: If true then the double is the lhs argument
Returns
A shared pointer to the result workspace

Definition at line 132 of file BinaryOperations.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), and value.

Referenced by export_BinaryOperations().

◆ performBinaryOpWithDouble() [4/4]

template WorkspaceGroup_sptr Mantid::PythonInterface::performBinaryOpWithDouble ( const  WorkspaceGroup_sptr,
const double  ,
const std::string &  op,
const std::string &  ,
bool  ,
bool   
)

◆ toString() [1/3]

template<typename ElementType >
std::string Mantid::PythonInterface::toString ( const ElementType &  value)
inline

Convert an element type within a sequence to a string for printing.

Parameters
value:: The elements value
Returns
A string representation of the value for printing within a sequence

Definition at line 31 of file StlExportDefinitions.h.

References value.

◆ toString() [2/3]

template<typename SequenceType , typename ElementType >
std::string Mantid::PythonInterface::toString ( const SequenceType &  values)

Convert a sequence of values to a string for printing.

Definition at line 51 of file StlExportDefinitions.h.

◆ toString() [3/3]

template<>
std::string Mantid::PythonInterface::toString ( const std::string &  value)
inline

Convert a string element within a sequence to a string for printing.

Parameters
value:: The elements value
Returns
A string representation of the value for printing within a sequence, i.e. wrapped in single quotes to emulate printing a python sequence of strings

Definition at line 44 of file StlExportDefinitions.h.

References value.

◆ typeHasAttribute() [1/2]

bool Mantid::PythonInterface::typeHasAttribute ( const boost::python::detail::wrapper_base &  wrapper,
const char *  attr 
)

An overload for the above taking a wrapper reference.

Same as above but taking a wrapper reference instead.

Parameters
wrapper:: A reference to a Wrapper object
attr:: A string containin the attribute name
Returns
True if the type dictionary contains the attribute

Definition at line 43 of file WrapperHelpers.cpp.

References typeHasAttribute().

◆ typeHasAttribute() [2/2]

bool Mantid::PythonInterface::typeHasAttribute ( PyObject *  obj,
const char *  attr 
)

This namespace contains helper functions for classes that are overridden in Python.

Checks whether the given object's type dictionary contains the named attribute.

Usually boost::python::get_override is used for this check but if the object's overridden function is declared on a superclass of the wrapped class then get_override always returns true, regardless of whether the method has been overridden in Python.

An example is the algorithm hierachy. We export the IAlgorithm interface with the name method attach to it. If a class in Python does not override the name method then get_override still claims that the override exists because it has found the IAlgorithm one

Parameters
obj:: A pointer to a PyObject
attr:: A string containin the attribute name
Returns
True if the type dictionary contains the attribute

Definition at line 32 of file WrapperHelpers.cpp.

References obj.

Referenced by Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::AlgorithmAdapter(), callMethod(), Mantid::PythonInterface::IFunctionAdapter::IFunctionAdapter(), and typeHasAttribute().