Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mantidproject/mantid into…
Browse files Browse the repository at this point in the history
… 28407_remove_algorithm_proxy

# Conflicts:
#	Framework/API/src/AlgorithmProxy.cpp
  • Loading branch information
NickDraper committed Mar 24, 2020
2 parents 4d1c566 + d306fe4 commit 96fd8f5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 22 deletions.
1 change: 0 additions & 1 deletion Framework/API/inc/MantidAPI/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ class MANTID_API_DLL Algorithm : public IAlgorithm,

std::atomic<ExecutionState> m_executionState; ///< the current execution state
std::atomic<ResultState> m_resultState; ///< the current result State
bool m_isExecuted; ///< Algorithm is executed flag
bool m_isChildAlgorithm; ///< Algorithm is a child algorithm
bool m_recordHistoryForChild; ///< Flag to indicate whether history should be
/// recorded. Applicable to child algs only
Expand Down
8 changes: 4 additions & 4 deletions Framework/API/src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ Algorithm::Algorithm()
m_log("Algorithm"), g_log(m_log), m_groupSize(0), m_executeAsync(nullptr),
m_notificationCenter(nullptr), m_progressObserver(nullptr),
m_executionState(ExecutionState::Uninitialized),
m_resultState(ResultState::NotFinished), m_isExecuted(false),
m_isChildAlgorithm(false), m_recordHistoryForChild(false),
m_alwaysStoreInADS(true), m_runningAsync(false), m_rethrow(false),
m_resultState(ResultState::NotFinished), m_isChildAlgorithm(false),
m_recordHistoryForChild(false), m_alwaysStoreInADS(true),
m_runningAsync(false), m_rethrow(false),
m_isAlgStartupLoggingEnabled(true), m_startChildProgress(0.),
m_endChildProgress(0.), m_algorithmID(this), m_singleGroup(-1),
m_groupsHaveSimilarNames(false), m_inputWorkspaceHistories(),
Expand Down Expand Up @@ -722,7 +722,7 @@ bool Algorithm::executeInternal() {
}

catch (...) {
// Execution
// Execution failed with an unknown exception object
setResultState(ResultState::Failed);
m_runningAsync = false;

Expand Down
2 changes: 1 addition & 1 deletion Framework/Algorithms/src/Rebin2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void Rebin2D::exec() {
"If it is a spectra axis try running ConvertSpectrumAxis first.");
}

const auto &oldXEdges = inputWS->x(0);
const auto &oldXEdges = inputWS->binEdges(0);
const size_t numXBins = inputWS->blocksize();
const size_t numYBins = inputWS->getNumberHistograms();
// This will convert plain NumericAxis to bin edges while
Expand Down
69 changes: 54 additions & 15 deletions Framework/Algorithms/test/Rebin2DTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#include "MantidAPI/BinEdgeAxis.h"
#include "MantidAlgorithms/Rebin2D.h"
#include "MantidDataObjects/RebinnedOutput.h"
#include "MantidHistogramData/Histogram.h"
#include "MantidKernel/Timer.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include <cxxtest/TestSuite.h>

#include "MantidKernel/Timer.h"
//#include "../../TestHelpers/src/WorkspaceCreationHelper.cpp"

using Mantid::Algorithms::Rebin2D;
using namespace Mantid::API;
Expand All @@ -26,7 +27,8 @@ namespace {
/// Return the input workspace. All Y values are 2 and E values sqrt(2)
MatrixWorkspace_sptr makeInputWS(const bool distribution,
const bool perf_test = false,
const bool small_bins = false) {
const bool small_bins = false,
const bool isHisto = true) {
size_t nhist(0), nbins(0);
double x0(0.0), deltax(0.0);

Expand All @@ -46,20 +48,31 @@ MatrixWorkspace_sptr makeInputWS(const bool distribution,
}
}

MatrixWorkspace_sptr ws = WorkspaceCreationHelper::create2DWorkspaceBinned(
int(nhist), int(nbins), x0, deltax);

// We need something other than a spectrum axis, call this one theta
auto thetaAxis = std::make_unique<BinEdgeAxis>(nhist + 1);
for (size_t i = 0; i < nhist + 1; ++i) {
thetaAxis->setValue(i, -0.5 + static_cast<double>(i));
}
ws->replaceAxis(1, std::move(thetaAxis));
MatrixWorkspace_sptr ws;

if (distribution) {
Mantid::API::WorkspaceHelpers::makeDistribution(ws);
if (isHisto) {
ws = WorkspaceCreationHelper::create2DWorkspaceBinned(
int(nhist), int(nbins), x0, deltax);
// We need something other than a spectrum axis, call this one theta
auto thetaAxis = std::make_unique<BinEdgeAxis>(nhist + 1);
for (size_t i = 0; i < nhist + 1; ++i) {
thetaAxis->setValue(i, -0.5 + static_cast<double>(i));
}
ws->replaceAxis(1, std::move(thetaAxis));
if (distribution) {
Mantid::API::WorkspaceHelpers::makeDistribution(ws);
}
} else {
// create histograms with points (which cannot be a distirbution)
ws = WorkspaceCreationHelper::create2DWorkspacePoints(
int(nhist), int(nbins), x0 + 0.5, deltax);
// convert axis from spectrum to theta
auto thetaAxis = std::make_unique<NumericAxis>(nhist);
for (size_t i = 0; i < nhist; ++i) {
thetaAxis->setValue(i, static_cast<double>(i));
}
ws->replaceAxis(1, std::move(thetaAxis));
}

return ws;
}

Expand Down Expand Up @@ -185,6 +198,32 @@ class Rebin2DTest : public CxxTest::TestSuite {
}
}

void test_BothAxes_PointData() {
MatrixWorkspace_sptr inputWS =
makeInputWS(false, false, false, false); // 10 spectra, 10 points
MatrixWorkspace_sptr outputWS =
runAlgorithm(inputWS, "5.,1.8,15", "-0.5,2.5,9.5");
TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 4);
TS_ASSERT_EQUALS(outputWS->blocksize(), 6);

double errors[6] = {3., 3., 3., 3., 3., 2.236067977};
const double epsilon(1e-08);
for (size_t i = 0; i < outputWS->getNumberHistograms(); ++i) {
const auto &y = outputWS->y(i);
const auto &e = outputWS->e(i);
const size_t numBins = y.size();
for (size_t j = 0; j < numBins; ++j) {
if (j < 5) {
TS_ASSERT_DELTA(y[j], 9, epsilon);
} else {
// Last bin
TS_ASSERT_DELTA(y[j], 5, epsilon);
}
TS_ASSERT_DELTA(e[j], errors[j], epsilon);
}
}
}

void test_Zero_Area_Bins_NoFractionalBinning() {
MatrixWorkspace_sptr inputWS = makeInputWS(false);
const auto nhist = inputWS->getNumberHistograms();
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataObjects/src/FractionalRebinning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ void rebinToFractionalOutput(const Quadrilateral &inputQ,
RebinnedOutput &outputWS,
const std::vector<double> &verticalAxis,
const RebinnedOutput_const_sptr &inputRB) {
const auto &inX = inputWS->x(i);
const auto &inX = inputWS->binEdges(i);
const auto &inY = inputWS->y(i);
const auto &inE = inputWS->e(i);
double signal = inY[j];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ Mantid::DataObjects::Workspace2D_sptr
create2DWorkspaceBinned(size_t nhist, size_t numVals, double x0 = 0.0,
double deltax = 1.0);

/** Create a 2D workspace with this many point-histograms and bins.
* Filled with Y = 2.0 and E = M_SQRT2
*/
Mantid::DataObjects::Workspace2D_sptr
create2DWorkspacePoints(size_t nhist, size_t numVals, double x0 = 0.0,
double deltax = 1.0);

/** Create a 2D workspace with this many histograms and bins. The bins are
* assumed to be non-uniform and given by the input array
* Filled with Y = 2.0 and E = sqrt(2.0)w
Expand Down
11 changes: 11 additions & 0 deletions Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ Workspace2D_sptr create2DWorkspaceBinned(size_t nhist, size_t numVals,
return create<Workspace2D>(nhist, Histogram(x, y, e));
}

/** Create a 2D workspace with this many point-histograms and bins.
* Filled with Y = 2.0 and E = M_SQRT2w
*/
Workspace2D_sptr create2DWorkspacePoints(size_t nhist, size_t numVals,
double x0, double deltax) {
Points x(numVals, LinearGenerator(x0, deltax));
Counts y(numVals, 2);
CountStandardDeviations e(numVals, M_SQRT2);
return create<Workspace2D>(nhist, Histogram(x, y, e));
}

/** Create a 2D workspace with this many histograms and bins. The bins are
* assumed to be non-uniform and given by the input array
* Filled with Y = 2.0 and E = M_SQRT2w
Expand Down

0 comments on commit 96fd8f5

Please sign in to comment.