Commit c480d6be authored by Rob Applin's avatar Rob Applin
Browse files

Refs #0. Get the bin of histogram zero by default.

parent 2b27c26d
......@@ -136,7 +136,7 @@ public:
/// spectra.
virtual std::size_t blocksize() const = 0;
/// Returns the number of bins for a given histogram index.
virtual std::size_t getNumberBins(const std::size_t &index) const = 0;
virtual std::size_t getNumberBins(const std::size_t &index = 0) const = 0;
/// Returns the maximum number of bins in a workspace (works on ragged data).
virtual std::size_t getMaxNumberBins() const = 0;
/// Returns the number of histograms in the workspace
......
......@@ -69,7 +69,7 @@ public:
// Get the blocksize, aka the number of bins in the histogram
std::size_t blocksize() const override;
/// Returns the number of bins for a given histogram index.
std::size_t getNumberBins(const std::size_t &index) const override;
std::size_t getNumberBins(const std::size_t &index = 0) const override;
/// Returns the maximum number of bins in a workspace (works on ragged data).
std::size_t getMaxNumberBins() const override;
......
......@@ -56,7 +56,7 @@ public:
std::size_t blocksize() const override;
/// Returns the number of bins for a given histogram index.
std::size_t getNumberBins(const std::size_t &index) const override;
std::size_t getNumberBins(const std::size_t &index = 0) const override;
/// Returns the maximum number of bins in a workspace (works on ragged data).
std::size_t getMaxNumberBins() const override;
......
......@@ -48,7 +48,7 @@ public:
/// Returns the size of each block of data returned by the dataX accessors
std::size_t blocksize() const override { return 1; }
/// Returns the number of bins for a given histogram index.
std::size_t getNumberBins(const std::size_t &index) const override {
std::size_t getNumberBins(const std::size_t &index = 0) const override {
UNUSED_ARG(index);
return 1;
}
......
......@@ -163,6 +163,14 @@ public:
TS_ASSERT_THROWS(ew->blocksize(), const std::logic_error &);
}
void
test_that_getNumberBins_returns_the_number_of_bins_in_the_first_histogram_by_default() {
ew = createEventWorkspace(true, false);
ew->getSpectrum(0).setHistogram(BinEdges({0., 10., 20.}));
TS_ASSERT_EQUALS(ew->getNumberBins(), 2);
}
void
test_that_getNumberBins_returns_the_correct_number_of_bins_for_different_histograms_in_a_ragged_EventWorkspace() {
ew = createEventWorkspace(true, false);
......
......@@ -94,6 +94,14 @@ public:
TS_ASSERT_THROWS(cloned->blocksize(), const std::logic_error &);
}
void
test_that_getNumberBins_returns_the_number_of_bins_in_the_first_histogram_by_default() {
Workspace2D_sptr cloned(ws->clone());
cloned->setHistogram(0, Points(0), Counts(0));
TS_ASSERT_EQUALS(cloned->getNumberBins(), 0);
}
void
test_that_getNumberBins_returns_the_correct_number_of_bins_for_different_histograms_in_a_ragged_Workspace2D() {
Workspace2D_sptr cloned(ws->clone());
......
......@@ -109,6 +109,7 @@ public:
void
test_that_getNumberBins_and_getMaxNumberBins_returns_one_for_a_WorkspaceSingleValue() {
WorkspaceSingleValue ws;
TS_ASSERT_EQUALS(ws.getNumberBins(), 1);
TS_ASSERT_EQUALS(ws.getNumberBins(0), 1);
TS_ASSERT_EQUALS(ws.getMaxNumberBins(), 1);
}
......
......@@ -64,6 +64,9 @@ GNU_DIAG_OFF("unused-local-typedef")
// Ignore -Wconversion warnings coming from boost::python
// Seen with GCC 7.1.1 and Boost 1.63.0
GNU_DIAG_OFF("conversion")
// Overloads for getNumberBins function which has 1 optional argument
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MatrixWorkspace_getNumberBinsOverloads,
MatrixWorkspace::getNumberBins, 0, 1)
// Overloads for yIndexOfX function which has 2 optional argument
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MatrixWorkspace_yIndexOfXOverloads,
MatrixWorkspace::yIndexOfX, 1, 3)
......@@ -339,8 +342,10 @@ void export_MatrixWorkspace() {
.def("blocksize", &MatrixWorkspace::blocksize, arg("self"),
"Returns size of the Y data array")
.def("getNumberBins", &MatrixWorkspace::getNumberBins,
(arg("self"), arg("index")),
"Returns the number of bins for a given histogram index.")
MatrixWorkspace_getNumberBinsOverloads(
(arg("self"), arg("index")), "Returns the number of bins for a "
"given histogram index. Default is "
"the zeroth histogram index."))
.def("getMaxNumberBins", &MatrixWorkspace::getMaxNumberBins, arg("self"),
"Returns the maximum number of bins in a workspace (works on ragged "
"data).")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment