21namespace OperatorOverloads {
35template <
typename LHSType,
typename RHSType,
typename ResultType>
37 bool lhsAsOutput,
bool child,
const std::string &name,
bool rethrow) {
40 alg->setRethrows(rethrow);
43 if (lhs->getName().empty()) {
44 alg->setProperty<LHSType>(
"LHSWorkspace", lhs);
46 alg->setPropertyValue(
"LHSWorkspace", lhs->getName());
48 if (
rhs->getName().empty()) {
49 alg->setProperty<RHSType>(
"RHSWorkspace",
rhs);
51 alg->setPropertyValue(
"RHSWorkspace",
rhs->getName());
54 if (!lhs->getName().empty()) {
55 alg->setPropertyValue(
"OutputWorkspace", lhs->getName());
57 alg->setAlwaysStoreInADS(
false);
58 alg->setPropertyValue(
"OutputWorkspace",
"dummy-output-name");
59 alg->setProperty<LHSType>(
"OutputWorkspace", lhs);
63 alg->setAlwaysStoreInADS(
false);
64 alg->setPropertyValue(
"OutputWorkspace",
"dummy-output-name");
66 alg->setPropertyValue(
"OutputWorkspace", name);
72 if (!alg->isExecuted()) {
73 std::string message =
"Error while executing operation: " + algorithmName;
74 throw std::runtime_error(message);
78 if (!alg->getAlwaysStoreInADS()) {
80 return std::dynamic_pointer_cast<typename ResultType::element_type>(result);
84 return std::dynamic_pointer_cast<typename ResultType::element_type>(result);
90 const std::string &,
bool);
93 const std::string &,
bool);
96 const std::string &,
bool);
99 const std::string &,
bool);
103 const std::string &,
bool);
106 const std::string &,
bool);
109 const std::string &,
bool);
113 const std::string &,
bool);
116 const std::string &,
bool);
120 const std::string &,
bool);
123 const std::string &,
bool);
126 const std::string &,
bool);
141 alg->setRethrows(
false);
145 alg->setProperty<
double>(
"Tolerance",
tolerance);
149 if (!alg->isExecuted()) {
150 std::string message =
"Error while executing operation: CompareWorkspaces";
151 throw std::runtime_error(message);
153 return alg->getProperty(
"Result");
162 retVal->dataY(0)[0] = rhsValue;
175 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Plus", lhs,
rhs);
184 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
194 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Minus", lhs,
rhs);
203 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
213 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
222 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Multiply", lhs,
rhs);
231 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
242 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
252 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Divide", lhs,
rhs);
261 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
272 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
282 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Plus", lhs,
rhs,
292 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
302 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Minus", lhs,
rhs,
312 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
322 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Multiply", lhs,
rhs,
332 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
342 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Divide", lhs,
rhs,
352 return executeBinaryOperation<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
371 if (ws1.
x(0).size() != ws2.
x(0).size())
375 const double firstWS = std::accumulate(ws1.
x(0).begin(), ws1.
x(0).end(), 0.);
376 const double secondWS = std::accumulate(ws2.
x(0).begin(), ws2.
x(0).end(), 0.);
377 if (std::abs(firstWS) < 1.0E-7 && std::abs(secondWS) < 1.0E-7) {
378 for (
size_t i = 0; i < ws1.
x(0).size(); i++) {
379 if (std::abs(ws1.
x(0)[i] - ws2.
x(0)[i]) > 1.0E-7)
382 }
else if (std::abs(firstWS - secondWS) / std::max<double>(std::abs(firstWS), std::abs(secondWS)) > 1.0E-7)
399 size_t numberToCheck = numHist / 10;
400 if (numberToCheck < 10)
402 if (numberToCheck > 100)
404 size_t step = numHist / numberToCheck;
407 for (
size_t i = step; i < numHist; i += step) {
408 const double firstWSLoop = std::accumulate(ws1.
x(i).begin(), ws1.
x(i).end(), 0.);
409 const double secondWSLoop = std::accumulate(ws2.
x(i).begin(), ws2.
x(i).end(), 0.);
410 if (std::abs(firstWSLoop) < 1.0E-7 && std::abs(secondWSLoop) < 1.0E-7) {
411 for (
size_t j = 0; j < ws1.
x(i).size(); j++) {
412 if (std::abs(ws1.
x(i)[j] - ws2.
x(i)[j]) > 1.0E-7)
415 }
else if (std::abs(firstWSLoop - secondWSLoop) / std::max<double>(std::abs(firstWSLoop), std::abs(secondWSLoop)) >
425 const double &first = WS.
x(0)[0];
427 for (
size_t i = 1; i < numHist; ++i) {
428 if (&first != &(WS.
x(i)[0]))
445 throw std::runtime_error(
"Event workspaces cannot be directly converted "
446 "into distributions.");
448 const size_t numberOfSpectra =
workspace->getNumberHistograms();
449 if (
workspace->histogram(0).xMode() == HistogramData::Histogram::XMode::Points) {
450 throw std::runtime_error(
"Workspace is using point data for x (should be bin edges).");
452 for (
size_t i = 0; i < numberOfSpectra; ++i) {
const std::vector< double > & rhs
IPeaksWorkspace_sptr workspace
Base MatrixWorkspace Abstract Class.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
const HistogramData::HistogramX & x(const size_t index) const
virtual std::size_t size() const =0
Returns the number of single indexable items in the 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.
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.
static bool matchingBins(const MatrixWorkspace &ws1, const MatrixWorkspace &ws2, const bool firstOnly=false)
Checks whether the bins (X values) of two workspace are the same.
static bool sharedXData(const MatrixWorkspace &WS)
Checks whether all the X vectors in a workspace are the same one underneath.