Commit 8f8538f4 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

yapf

parent 4f64e430
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import hashlib

logger = logging.getLogger(__name__)


def hash_ecfp(ecfp, size):
  """
  Returns an int < size representing given ECFP fragment.
@@ -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.

@@ -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
@@ -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

+3 −0
Original line number Diff line number Diff line
@@ -2,13 +2,16 @@ import unittest
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):