-
Notifications
You must be signed in to change notification settings - Fork 128
Correct error propagation on PolarizationEfficienciesWildes algorithm #39300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 21 commits
1aae7be
7abffb7
c17ac36
bb5aed1
5618276
f020f2d
8cc319e
4963cd4
de8d735
39c7f46
184456c
64604ad
ebc1b34
87a7f2c
4dbf94f
978f31c
b05f9de
f01ae16
c143592
3705545
1482c70
77f62d2
ec82c91
2e641b4
ddc014d
a62caec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,7 +10,10 @@ | |||||
#include "MantidAPI/MatrixWorkspace.h" | ||||||
#include "MantidAPI/WorkspaceGroup.h" | ||||||
#include "MantidAlgorithms/DllConfig.h" | ||||||
#include "MantidKernel/MultiThreaded.h" | ||||||
#include <Eigen/Dense> | ||||||
#include <optional> | ||||||
#include <unsupported/Eigen/AutoDiff> | ||||||
|
||||||
namespace Mantid::Algorithms { | ||||||
namespace PolarizationCorrectionsHelpers { | ||||||
|
@@ -66,4 +69,88 @@ MANTID_ALGORITHMS_DLL const std::string &getORSONotationForSpinState(const std:: | |||||
MANTID_ALGORITHMS_DLL void addORSOLogForSpinState(const Mantid::API::MatrixWorkspace_sptr &ws, | ||||||
const std::string &spinState); | ||||||
} // namespace SpinStatesORSO | ||||||
|
||||||
namespace Arithmetic { | ||||||
|
||||||
template <size_t N> class ErrorTypeHelper { | ||||||
public: | ||||||
using DerType = Eigen::Matrix<double, N, 1>; | ||||||
using InputArray = DerType; | ||||||
using ADScalar = Eigen::AutoDiffScalar<DerType>; | ||||||
}; | ||||||
|
||||||
template <size_t N, typename Func> class ErrorPropagation { | ||||||
public: | ||||||
using Types = ErrorTypeHelper<N>; | ||||||
adriazalvarez marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
using DerType = Types::DerType; | ||||||
using ADScalar = Types::ADScalar; | ||||||
using InputArray = Types::InputArray; | ||||||
ErrorPropagation(Func func) : compute_func(std::move(func)) {} | ||||||
|
||||||
struct AutoDevResult { | ||||||
double value; | ||||||
double error; | ||||||
Eigen::Array<double, N, 1> derivatives; | ||||||
}; | ||||||
|
||||||
AutoDevResult evaluate(const InputArray &values, const InputArray &errors) const { | ||||||
std::array<ADScalar, N> x; | ||||||
for (size_t i = 0; i < N; ++i) { | ||||||
x[i] = ADScalar(values[i], DerType::Unit(N, i)); | ||||||
} | ||||||
const ADScalar y = compute_func(x); | ||||||
const auto &derivatives = y.derivatives(); | ||||||
return {y.value(), std::sqrt((derivatives.array().square() * errors.array().square()).sum()), derivatives}; | ||||||
} | ||||||
|
||||||
template <std::same_as<API::MatrixWorkspace_sptr>... Ts> | ||||||
API::MatrixWorkspace_sptr evaluateWorkspaces(const bool outputWorkspaceDistribution, Ts... args) const { | ||||||
return evaluateWorkspacesImpl(outputWorkspaceDistribution, std::forward<Ts>(args)...); | ||||||
} | ||||||
|
||||||
template <std::same_as<API::MatrixWorkspace_sptr>... Ts> | ||||||
API::MatrixWorkspace_sptr evaluateWorkspaces(Ts... args) const { | ||||||
return evaluateWorkspacesImpl(std::nullopt, std::forward<Ts>(args)...); | ||||||
} | ||||||
|
||||||
private: | ||||||
Func compute_func; | ||||||
|
Func compute_func; | |
Func computeFunc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template <std::same_as<API::MatrixWorkspace_sptr>... Ts>
API::MatrixWorkspace_sptr evaluateWorkspaces(Ts... args) const {
return evaluateWorkspacesImpl(false, std::forward<Ts>(args)...);
I think we can get away with just using a bool here?
API::MatrixWorkspace_sptr evaluateWorkspacesImpl(std::optional<bool> outputWorkspaceDistribution, Ts... args) const { | |
API::MatrixWorkspace_sptr evaluateWorkspacesImpl(bool outputWorkspaceDistribution, Ts... args) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I used a std::optional
here is that I wanted the user to be able to do three things:
- Specify no value, keep the distribution as it is on the LHS workspace
- Specify false, set the distribution flag to false
- Specify true, set the distribution flag to true.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be renamed differently? isThreadSafe
perhaps?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem previous camel case comment
Uh oh!
There was an error while loading. Please reload this page.