From 698e94e0d276238bbed244c4e9b15aa3ad2cdbf0 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Sun, 11 Mar 2018 23:55:00 +0100 Subject: [PATCH] simpler --- src/python/axis.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/python/axis.cpp b/src/python/axis.cpp index 9a0f8c50..807ada1a 100644 --- a/src/python/axis.cpp +++ b/src/python/axis.cpp @@ -140,22 +140,6 @@ bp::object category_init(bp::tuple args, bp::dict kwargs) { return self.attr("__init__")(bha::category<>(c.begin(), c.end(), label)); } -template bp::object axis_getitem_impl(std::true_type, const A &a, int i) { - return bp::make_tuple(a.lower(i), a.lower(i+1)); -} - -template bp::object axis_getitem_impl(std::false_type, const A &a, int i) { - return bp::object(a.value(i)); -} - -template bp::object axis_getitem(const A &a, int i) { - if (i < -1 * a.uoflow() || i >= a.size() + 1 * a.uoflow()) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - bp::throw_error_already_set(); - } - return axis_getitem_impl(bh::detail::has_method_lower_t(), a, i); -} - template void axis_set_label(T& t, bp::str s) { t.label({bp::extract(s)(), static_cast(bp::len(s))}); @@ -166,9 +150,25 @@ template bp::str axis_get_label(const T& t) { return {s.data(), s.size()}; } +template bp::object axis_getitem(const A &a, int i) { + if (i < -1 * a.uoflow() || i >= a.size() + 1 * a.uoflow()) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + bp::throw_error_already_set(); + } + return bp::make_tuple(a.lower(i), a.lower(i+1)); +} + +template <> bp::object axis_getitem>(const A &a, int i) { + if (i < 0 || i >= a.size()) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + bp::throw_error_already_set(); + } + return bp::object(a.value(i)); +} + #ifdef HAVE_NUMPY template bp::object axis_array_interface(const Axis& axis) { - using T = typename std::decay::type; + using T = typename std::decay::type; bp::dict d; auto shape = bp::make_tuple(axis.size()+1); d["shape"] = shape;