22namespace OperatorOverloads {
36template <
typename LHSType,
typename RHSType,
typename ResultType>
38 bool lhsAsOutput,
bool child,
const std::string &
name,
bool rethrow) {
39 auto alg = AlgorithmManager::Instance().createUnmanaged(algorithmName);
41 alg->setRethrows(rethrow);
44 if (lhs->getName().empty()) {
45 alg->setProperty<LHSType>(
"LHSWorkspace", lhs);
47 alg->setPropertyValue(
"LHSWorkspace", lhs->getName());
49 if (
rhs->getName().empty()) {
50 alg->setProperty<RHSType>(
"RHSWorkspace",
rhs);
52 alg->setPropertyValue(
"RHSWorkspace",
rhs->getName());
55 if (!lhs->getName().empty()) {
56 alg->setPropertyValue(
"OutputWorkspace", lhs->getName());
58 alg->setAlwaysStoreInADS(
false);
59 alg->setPropertyValue(
"OutputWorkspace",
"dummy-output-name");
60 alg->setProperty<LHSType>(
"OutputWorkspace", lhs);
64 alg->setAlwaysStoreInADS(
false);
65 alg->setPropertyValue(
"OutputWorkspace",
"dummy-output-name");
67 alg->setPropertyValue(
"OutputWorkspace",
name);
73 if (!alg->isExecuted()) {
74 std::string message =
"Error while executing operation: " + algorithmName;
75 throw std::runtime_error(message);
79 if (!alg->getAlwaysStoreInADS()) {
81 return std::dynamic_pointer_cast<typename ResultType::element_type>(result);
84 API::AnalysisDataService::Instance().retrieve(alg->getPropertyValue(
"OutputWorkspace"));
85 return std::dynamic_pointer_cast<typename ResultType::element_type>(result);
91 const std::string &,
bool);
94 const std::string &,
bool);
97 const std::string &,
bool);
100 const std::string &,
bool);
104 const std::string &,
bool);
107 const std::string &,
bool);
110 const std::string &,
bool);
114 const std::string &,
bool);
117 const std::string &,
bool);
121 const std::string &,
bool);
124 const std::string &,
bool);
127 const std::string &,
bool);
140 auto alg = AlgorithmManager::Instance().createUnmanaged(
"CompareWorkspaces");
142 alg->setRethrows(
false);
146 alg->setProperty<
double>(
"Tolerance",
tolerance);
150 if (!alg->isExecuted()) {
151 std::string message =
"Error while executing operation: CompareWorkspaces";
152 throw std::runtime_error(message);
154 return alg->getProperty(
"Result");
163 retVal->dataY(0)[0] = rhsValue;
176 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Plus", lhs,
rhs);
185 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
195 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Minus", lhs,
rhs);
204 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
214 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
223 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Multiply", lhs,
rhs);
232 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
243 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
253 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Divide", lhs,
rhs);
262 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
273 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
283 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Plus", lhs,
rhs,
293 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
303 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Minus", lhs,
rhs,
313 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
323 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Multiply", lhs,
rhs,
333 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
343 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Divide", lhs,
rhs,
353 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
371 const std::shared_ptr<const MatrixWorkspace> &ws2,
const bool firstOnly) {
373 if (ws1->x(0).size() != ws2->x(0).size())
377 const double firstWS = std::accumulate(ws1->x(0).begin(), ws1->x(0).end(), 0.);
378 const double secondWS = std::accumulate(ws2->x(0).begin(), ws2->x(0).end(), 0.);
379 if (std::abs(firstWS) < 1.0E-7 && std::abs(secondWS) < 1.0E-7) {
380 for (
size_t i = 0; i < ws1->x(0).size(); i++) {
392 if (ws1->size() != ws2->size())
400 const size_t numHist = ws1->getNumberHistograms();
401 size_t numberToCheck = numHist / 10;
402 if (numberToCheck < 10)
404 if (numberToCheck > 100)
406 size_t step = numHist / numberToCheck;
409 for (
size_t i = step; i < numHist; i += step) {
410 const double firstWSLoop = std::accumulate(ws1->x(i).begin(), ws1->x(i).end(), 0.);
411 const double secondWSLoop = std::accumulate(ws2->x(i).begin(), ws2->x(i).end(), 0.);
412 if (std::abs(firstWSLoop) < 1.0E-7 && std::abs(secondWSLoop) < 1.0E-7) {
413 for (
size_t j = 0; j < ws1->x(i).size(); j++) {
426 const double &first = WS->x(0)[0];
427 const size_t numHist = WS->getNumberHistograms();
428 for (
size_t i = 1; i < numHist; ++i) {
429 if (&first != &(WS->x(i)[0]))
446 throw std::runtime_error(
"Event workspaces cannot be directly converted "
447 "into distributions.");
449 const size_t numberOfSpectra =
workspace->getNumberHistograms();
450 if (
workspace->histogram(0).xMode() == HistogramData::Histogram::XMode::Points) {
451 throw std::runtime_error(
"Workspace is using point data for x (should be bin edges).");
453 for (
size_t i = 0; i < numberOfSpectra; ++i) {
const std::vector< double > & rhs
IPeaksWorkspace_sptr workspace
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
DLLExport ResultType executeBinaryOperation(const std::string &algorithmName, const LHSType lhs, const RHSType rhs, bool lhsAsOutput=false, bool child=true, const std::string &name="", bool rethrow=false)
Performs a binary operation on two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator*(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Multiply two workspaces.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
bool MANTID_API_DLL equals(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs, double tolerance=0.0)
Performs a comparison operation on two workspaces, using the CompareWorkspaces algorithm.
MatrixWorkspace_sptr MANTID_API_DLL operator/=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Divide two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator+=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Adds two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator-=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Subtracts two workspaces.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
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.
MatrixWorkspace_sptr MANTID_API_DLL operator-(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Subtracts two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator*=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Multiply two workspaces.
MatrixWorkspace_sptr MANTID_API_DLL operator/(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Divide two workspaces.
static MatrixWorkspace_sptr createWorkspaceSingleValue(const double &rhsValue)
Creates a temporary single value workspace the error is set to zero.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
MatrixWorkspace_sptr MANTID_API_DLL operator+(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Adds two workspaces.
MANTID_KERNEL_DLL bool withinRelativeDifference(T const x, T const y, S const tolerance)
Test whether x, y are within relative tolerance tol.
MANTID_KERNEL_DLL bool withinAbsoluteDifference(T const x, T const y, S const tolerance)
Test whether x, y are within absolute tolerance tol.
static bool sharedXData(const std::shared_ptr< const MatrixWorkspace > &WS)
Checks whether all the X vectors in a workspace are the same one underneath.
static bool matchingBins(const std::shared_ptr< const MatrixWorkspace > &ws1, const std::shared_ptr< const MatrixWorkspace > &ws2, const bool firstOnly=false)
Checks whether the bins (X values) of two workspace are the same.
static void makeDistribution(const MatrixWorkspace_sptr &workspace, const bool forwards=true)
Divides the data in a workspace by the bin width to make it a distribution.