Browse Source

add BitVector binding

refactoring
Tom Janson 8 years ago
parent
commit
d955bcb1c2
  1. 2
      src/mod_storage.cpp
  2. 39
      src/storage/bitvector.cpp
  3. 8
      src/storage/bitvector.h

2
src/mod_storage.cpp

@ -1,10 +1,12 @@
#include "common.h"
#include "storage/bitvector.h"
#include "storage/model.h"
#include "storage/matrix.h"
PYBIND11_PLUGIN(storage) {
py::module m("storage");
define_bitvector(m);
define_model(m);
define_sparse_matrix(m);
return m.ptr();

39
src/storage/bitvector.cpp

@ -0,0 +1,39 @@
#include "bitvector.h"
#include "storm/storage/BitVector.h"
#include <sstream>
void define_bitvector(py::module& m) {
using BitVector = storm::storage::BitVector;
py::class_<BitVector>(m, "BitVector")
.def(py::init<>())
.def(py::init<BitVector>(), "other"_a)
.def(py::init<uint_fast64_t>(), "length"_a)
.def(py::init<uint_fast64_t, bool>(), "length"_a, "init"_a)
.def(py::init<uint_fast64_t, std::vector<uint_fast64_t>>(), "length"_a, "set_entries"_a)
.def("size", &BitVector::size)
.def("number_of_set_bits", &BitVector::getNumberOfSetBits)
//.def("get", &BitVector::get, "index"_a) // no idea why this does not work
.def("get", [](BitVector const& b, uint_fast64_t i) { return b.get(i); }, "index"_a)
.def(py::self == py::self)
.def(py::self != py::self)
.def(py::self < py::self)
.def(py::self & py::self)
.def(py::self | py::self)
.def(py::self ^ py::self)
.def(py::self % py::self)
.def(~py::self)
.def(py::self &= py::self)
.def(py::self |= py::self)
.def("__repr__", [](BitVector const& b) { std::ostringstream oss; oss << b; return oss.str(); })
// TODO (when needed): iterator
;
}

8
src/storage/bitvector.h

@ -0,0 +1,8 @@
#ifndef PYTHON_STORAGE_BITVECTOR_H_
#define PYTHON_STORAGE_BITVECTOR_H_
#include "common.h"
void define_bitvector(py::module& m);
#endif /* PYTHON_STORAGE_BITVECTOR_H_ */
Loading…
Cancel
Save