Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/Power.h"
#include "MantidKernel/Exception.h"
using namespace Mantid::API;
using namespace Mantid::Kernel;
namespace Mantid
{
namespace Algorithms
{
// Register the class into the algorithm factory
DECLARE_ALGORITHM( Power)
///////////////////////////////////
void Power::performBinaryOperation(const MantidVec& lhsX,
const MantidVec& lhsY, const MantidVec& lhsE, const MantidVec& rhsY,
const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut)
{
if (rhsY.size() > 1)
{
throw std::invalid_argument("RHSWorkspace must be single valued.");
}
const int bins = lhsE.size();
for (int j = 0; j < bins; ++j)
{
// Get references to the input Y's
const double& leftY = lhsY[j];
const double& rightY = rhsY[j];
const double& leftE = lhsE[j];
CheckExponent(rightY);
double yOut = CalculatePower(leftY, rightY);
EOut[j] = rightY * yOut * (leftE / leftY);
YOut[j] = yOut;
}
}
void Power::performBinaryOperation(const MantidVec& lhsX,
const MantidVec& lhsY, const MantidVec& lhsE, const double& rhsY,
const double& rhsE, MantidVec& YOut, MantidVec& EOut)
{
CheckExponent(rhsY);
const int bins = lhsE.size();
for (int j = 0; j < bins; ++j)
{
// Get reference to input Y
const double& leftY = lhsY[j];
const double& leftE = lhsE[j];
double yOut = CalculatePower(leftY, rhsY);
EOut[j] = rhsY * yOut * (leftE / leftY);
YOut[j] = yOut;
}
}
inline void Power::CheckExponent(double exponent) {
if (exponent < 0)
{
throw std::invalid_argument("Cannot have exponent < 0");
}
}
inline double Power::CalculatePower(double base, double exponent)
{
return std::pow(base, exponent);
}
void Power::setOutputUnits(const API::MatrixWorkspace_const_sptr lhs,
const API::MatrixWorkspace_const_sptr rhs,
API::MatrixWorkspace_sptr out)
{
//TODO
}
}
}