From 44d626f727f34152139bea7052333cc35dc4b70b Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Wed, 29 Dec 2021 21:06:52 +0100 Subject: [PATCH] BitArray indexing from the end --- external_dependencies/pybind11 | 2 +- libsrc/core/python_ngcore_export.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/external_dependencies/pybind11 b/external_dependencies/pybind11 index c16da993..e7e2c79f 160000 --- a/external_dependencies/pybind11 +++ b/external_dependencies/pybind11 @@ -1 +1 @@ -Subproject commit c16da993094988141101ac4d96a9b2c92f9ac714 +Subproject commit e7e2c79f3f520f78ffc39fcb34f7919003102733 diff --git a/libsrc/core/python_ngcore_export.cpp b/libsrc/core/python_ngcore_export.cpp index 9cb04d11..b53c6f47 100644 --- a/libsrc/core/python_ngcore_export.cpp +++ b/libsrc/core/python_ngcore_export.cpp @@ -37,12 +37,14 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT .def("__len__", &BitArray::Size) .def("__getitem__", [] (BitArray & self, int i) { + if (i < 0) i+=self.Size(); if (i < 0 || i >= self.Size()) throw py::index_error(); return self.Test(i); }, py::arg("pos"), "Returns bit from given position") .def("__setitem__", [] (BitArray & self, int i, bool b) { + if (i < 0) i+=self.Size(); if (i < 0 || i >= self.Size()) throw py::index_error(); if (b) self.SetBit(i); else self.Clear(i);