diff --git a/Framework/API/inc/MantidAPI/MatrixWorkspace.h b/Framework/API/inc/MantidAPI/MatrixWorkspace.h index b343553b021140b7823673f2b5fbb383d74c3b55..850a9d63a6203df6149479d5782aefd5707dbe65 100644 --- a/Framework/API/inc/MantidAPI/MatrixWorkspace.h +++ b/Framework/API/inc/MantidAPI/MatrixWorkspace.h @@ -514,7 +514,7 @@ public: // Check if this class has an oriented lattice on a sample object virtual bool hasOrientedLattice() const override; - virtual std::pair<int64_t, int64_t> find(double value) const; + virtual int64_t find(double value) const; //===================================================================================== // End IMDWorkspace methods diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index 8e6306c4eb03f544a1046cbbb297594293383108..992c708ae2a084079d0e85bdbd1e164c6b49bb34 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -1931,7 +1931,7 @@ MantidImage_sptr MatrixWorkspace::getImage( return image; } -std::pair<int64_t, int64_t> MatrixWorkspace::find(double value) const { +int64_t MatrixWorkspace::find(double value) const { std::pair<int64_t, int64_t> out(-1, -1); const int64_t numHists = static_cast<int64_t>(this->getNumberHistograms()); for (int64_t i = 0; i < numHists; ++i) { @@ -1941,7 +1941,7 @@ std::pair<int64_t, int64_t> MatrixWorkspace::find(double value) const { break; } } - return out; + return out.first; } /** diff --git a/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp b/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp index 683ce4e5f38fb6e229b8bce0d7d54b9d2952b825..f7118126aac4995310317e34d47c07670f2fdea8 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp @@ -71,6 +71,32 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MatrixWorkspace_YUnitLabelOverloads, GNU_DIAG_ON("conversion") GNU_DIAG_ON("unused-local-typedef") +// Converts a std::pair instance to a Python tuple. +template <typename T1, typename T2> +struct std_pair_to_tuple +{ + static PyObject* convert(std::pair<T1, T2> const& p) + { + return boost::python::incref( + boost::python::make_tuple(p.first, p.second).ptr()); + } + static PyTypeObject const *get_pytype () {return &PyTuple_Type; } +}; + +// Helper for convenience. +template <typename T1, typename T2> +struct std_pair_to_python_converter +{ + std_pair_to_python_converter() + { + boost::python::to_python_converter< + std::pair<T1, T2>, + std_pair_to_tuple<T1, T2>, + true //std_pair_to_tuple has get_pytype + >(); + } +}; + /** * Set the values from an python array-style object into the given spectrum in * the workspace @@ -365,7 +391,7 @@ void export_MatrixWorkspace() { ":class:`~mantid.api.MatrixWorkspace.hasMaskedBins` MUST be called " "first to check if any bins are " "masked, otherwise an exception will be thrown") - .def("find", &find, (arg("self"), arg("value")), "find index of Y value") + .def("find", &MatrixWorkspace::find, (arg("self"), arg("value")), "find index of Y value") // Deprecated .def("getNumberBins", &getNumberBinsDeprecated, arg("self"), "Returns size of the Y data array (deprecated, use "