Skip to content

Commit

Permalink
more efficient BitStrToIntList
Browse files Browse the repository at this point in the history
  • Loading branch information
eloyfelix committed Oct 24, 2024
1 parent 7a350de commit 6109fe7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion FPSim2/io/chem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, Iterable as IterableType, Dict, List, Tuple, Union
from typing import Any, Callable, Iterable as IterableType, Dict, Tuple, Union
from FPSim2.FPSim2lib.utils import BitStrToIntList, PyPopcount
from collections.abc import Iterable
from rdkit.Chem import rdMolDescriptors
Expand Down
9 changes: 7 additions & 2 deletions FPSim2/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ namespace utils {

py::list BitStrToIntList(const std::string &bit_string) {
py::list efp;
for (size_t i = 0; i < bit_string.length(); i += 64) {
efp.append(std::stoull(bit_string.substr(i, 64), 0, 2));
size_t len = bit_string.length();
for (size_t i = 0; i < len; i += 64) {
uint64_t value = 0;
for (size_t j = 0; j < 64 && (i + j) < len; ++j) {
value = (value << 1) | (bit_string[i + j] - '0');
}
efp.append(value);
}
return efp;
}
Expand Down

0 comments on commit 6109fe7

Please sign in to comment.