Add ToList method to Sparse/ExplicitBitVector (#4467)

* Add ToList method to Sparse/ExplicitBitVector

* Pushed a change to an older version of the file, reverting

* Fix function name

* Merge with the change that actually compiles

* Add SparseIntVect ToList, Update tests

* Fix test

* Update Code/DataStructs/Wrap/SparseIntVect.cpp

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

* Update Code/DataStructs/Wrap/wrap_SparseBV.cpp

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
This commit is contained in:
Brian Kelley
2021-09-09 00:26:15 -04:00
committed by GitHub
parent 58e6743df0
commit 549f318f29
5 changed files with 76 additions and 2 deletions

View File

@@ -57,6 +57,17 @@ python::dict pyGetNonzeroElements(SparseIntVect<IndexType> &vect) {
return res;
}
template <typename IndexType>
python::list pyToList(SparseIntVect<IndexType> &vect) {
python::list res;
res.append(0);
res *= vect.getLength();
for(auto iter: vect.getNonzeroElements()) {
res[iter.first] = iter.second;
}
return res;
}
template <typename T>
python::list BulkDice(const T &siv1, python::list sivs, bool returnDistance) {
python::list res;
@@ -167,6 +178,8 @@ struct sparseIntVec_wrapper {
"update the vector based on the values in the list or tuple")
.def("GetNonzeroElements", &pyGetNonzeroElements<IndexType>,
"returns a dictionary of the nonzero elements")
.def("ToList", pyToList<IndexType>,
"Return the SparseIntVect as a python list")
.def_pickle(siv_pickle_suite<IndexType>());
python::def(