mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-06 22:39:55 +08:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user