Skip to content

Commit

Permalink
yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharath Ramsundar authored and Bharath Ramsundar committed May 1, 2020
1 parent 4f64e43 commit 8f8538f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions deepchem/utils/hash_utils.py
Expand Up @@ -7,6 +7,7 @@

logger = logging.getLogger(__name__)


def hash_ecfp(ecfp, size):
"""
Returns an int < size representing given ECFP fragment.
Expand All @@ -28,6 +29,7 @@ def hash_ecfp(ecfp, size):
ecfp_hash = int(digest, 16) % (size)
return (ecfp_hash)


def hash_ecfp_pair(ecfp_pair, size):
"""Returns an int < size representing that ECFP pair.
Expand All @@ -52,9 +54,8 @@ def hash_ecfp_pair(ecfp_pair, size):
ecfp_hash = int(digest, 16) % (size)
return (ecfp_hash)

def vectorize(hash_function,
feature_dict=None,
size=1024):

def vectorize(hash_function, feature_dict=None, size=1024):
"""Helper function to vectorize a spatial description from a hash.
Hash functions are used to perform spatial featurizations in
Expand All @@ -80,8 +81,7 @@ def vectorize(hash_function,
feature_vector = np.zeros(size)
if feature_dict is not None:
on_channels = [
hash_function(feature, size)
for key, feature in feature_dict.items()
hash_function(feature, size) for key, feature in feature_dict.items()
]
feature_vector[on_channels] += 1

Expand Down
3 changes: 3 additions & 0 deletions deepchem/utils/test/test_hash_utils.py
Expand Up @@ -2,13 +2,16 @@
import numpy as np
from deepchem.utils import hash_utils


def random_string(length, chars=None):
import string
if chars is None:
chars = list(string.ascii_letters + string.ascii_letters + '()[]+-.=#@/\\')
return ''.join(np.random.choice(chars, length))


class TestHashUtils(unittest.TestCase):

def test_hash_ecfp(self):
for power in (2, 16, 64):
for _ in range(10):
Expand Down

0 comments on commit 8f8538f

Please sign in to comment.