From 48e4865fee72166e1effbbf8daa24a82270dcea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 11 Mar 2020 21:33:53 +0100 Subject: [PATCH] copy BitArray --- libsrc/core/python_ngcore_export.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libsrc/core/python_ngcore_export.cpp b/libsrc/core/python_ngcore_export.cpp index d6cc9d6e..953dea59 100644 --- a/libsrc/core/python_ngcore_export.cpp +++ b/libsrc/core/python_ngcore_export.cpp @@ -69,6 +69,29 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT } }, py::arg("inds"), py::arg("value"), "Clear/Set bit at given positions") + .def("__setitem__", [] (BitArray & self, py::slice inds, BitArray & ba) + { + size_t start, step, stop, n; + if (!inds.compute(self.Size(), &start, &stop, &step, &n)) + throw py::error_already_set(); + + if (start == 0 && n == self.Size() && step == 1) + { + self = ba; + } + else + { + for (size_t i = 0; i < n; i++, start += step) + { + bool b = ba.Test(i); + if (b) + self.SetBit(start); + else + self.Clear(start); + } + } + }, py::arg("inds"), py::arg("ba"), "copy BitArray") + .def("__setitem__", [](BitArray & self, IntRange range, bool b) { if (b)