20#include <boost/python/def.hpp>
21#include <boost/python/return_value_policy.hpp>
30 const std::string &, bool, bool);
32 const std::string &,
const std::string &, bool, bool);
34 const std::string &,
const std::string &, bool, bool);
36 const std::string &,
const std::string &, bool, bool);
39 const std::string &,
const std::string &, bool, bool);
41 using binary_fn_md_db =
44 const std::string &, bool, bool);
45 using binary_fn_gp_db =
49 using ReturnWorkspaceSptr = return_value_policy<AsType<Workspace_sptr>>;
52 using boost::python::def;
56 def(
"performBinaryOp", (binary_fn_md_md)&performBinaryOp, ReturnWorkspaceSptr());
57 def(
"performBinaryOp", (binary_fn_md_gp)&performBinaryOp, ReturnWorkspaceSptr());
58 def(
"performBinaryOp", (binary_fn_gp_md)&performBinaryOp, ReturnWorkspaceSptr());
59 def(
"performBinaryOp", (binary_fn_gp_gp)&performBinaryOp, ReturnWorkspaceSptr());
60 def(
"performBinaryOp", (binary_fn_mh_mh)&performBinaryOp, ReturnWorkspaceSptr());
62 def(
"performBinaryOp", (binary_fn_md_db)&performBinaryOpWithDouble, ReturnWorkspaceSptr());
63 def(
"performBinaryOp", (binary_fn_mh_db)&performBinaryOpWithDouble, ReturnWorkspaceSptr());
64 def(
"performBinaryOp", (binary_fn_gp_db)&performBinaryOpWithDouble, ReturnWorkspaceSptr());
83template <
typename LHSType,
typename RHSType,
typename ResultType>
84ResultType
performBinaryOp(
const LHSType lhs,
const RHSType
rhs,
const std::string &op,
const std::string &name,
85 bool inplace,
bool reverse) {
92 const auto algoName = (lhs_mat || lhs_grp) && (rhs_mat || rhs_grp) ? op : op +
"MD";
99 result = API::OperatorOverloads::executeBinaryOperation<RHSType, LHSType, ResultType>(algoName,
rhs, lhs, inplace,
102 result = API::OperatorOverloads::executeBinaryOperation<LHSType, RHSType, ResultType>(algoName, lhs,
rhs, inplace,
105 }
catch (std::runtime_error &exc) {
107 if (
error ==
"algorithm") {
108 error =
"Unknown binary operation requested: " + op;
109 throw std::runtime_error(
error);
131template <
typename LHSType,
typename ResultType>
133 const std::string &name,
bool inplace,
bool reverse) {
135 struct ScopedADSEntry {
137 ads.addOrReplace(entryName,
value);
139 ~ScopedADSEntry() { ads.remove(name); }
141 const std::string &name;
154 alg->setChild(
false);
157 alg->setAlwaysStoreInADS(
false);
159 alg->setProperty<
double>(
"DataValue",
value);
160 const std::string tmpName(
"__python_binary_op_single_value");
161 alg->setPropertyValue(
"OutputWorkspace", tmpName);
168 if (alg->isExecuted()) {
169 singleValue = alg->getProperty(
"OutputWorkspace");
171 throw std::runtime_error(
"performBinaryOp: Error in execution of "
172 "CreateSingleValuedWorkspace");
174 ScopedADSEntry removeOnExit(tmpName, singleValue);
176 performBinaryOp<LHSType, MatrixWorkspace_sptr, ResultType>(inputWS, singleValue, op, name, inplace, reverse);
182 const std::string &name,
bool,
bool);
184 const std::string &name,
bool,
bool);
186 const std::string &name,
bool,
bool);
188 const std::string &name,
bool,
bool);
191 const std::string &,
const std::string &name,
bool,
bool);
193 const std::string &,
const std::string &name,
bool,
bool);
197 const std::string &,
bool,
bool);
199 const std::string &op,
const std::string &,
bool,
bool);
201 const std::string &,
bool,
bool);
void export_BinaryOperations()
const std::vector< double > & rhs
double value
The value of the point.
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Defines a structure for releasing the Python GIL using the RAII pattern.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< IMDHistoWorkspace > IMDHistoWorkspace_sptr
shared pointer to Mantid::API::IMDHistoWorkspace
std::shared_ptr< IMDWorkspace > IMDWorkspace_sptr
Shared pointer to the IMDWorkspace base class.
std::shared_ptr< const WorkspaceGroup > WorkspaceGroup_const_sptr
shared pointer to Mantid::API::WorkspaceGroup, pointer to const version
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
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.
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.