Skip to content

Commit

Permalink
Sped up of an additional 30%
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed Mar 1, 2020
1 parent 49b97b7 commit 068a14d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Expand Up @@ -4,7 +4,16 @@
import numpy as np
from .multivariate_gap_sequence import MultivariateGapSequence
from .utils import generate_synthetic_gaps
from numba import njit

@njit
def add_gaps(indices_masks:np.ndarray, y:np.ndarray, coordinates:np.ndarray):
# Making a deep copy of y, since we are going to edit the copy.
x = np.copy(y)
for i in range(indices_masks.shape[0]):
for j in coordinates[indices_masks[i]]:
x[i][j] = 0.25
return x

class MultivariateGapWindowsSequence(MultivariateGapSequence):
"""
Expand Down Expand Up @@ -37,9 +46,6 @@ def __getitem__(self, idx: int) -> Tuple[np.ndarray, np.ndarray]:
# Drop rows where none of the indices is present
indices_masks = masks[:, considered_rows]
coordinates = self._coordinates[considered_rows]
# Making a deep copy of y, since we are going to edit the copy.
x = np.copy(y)
# For i-th row of current batch we apply the nucletides mask
for i, indices_mask in enumerate(indices_masks):
x[i, coordinates[indices_mask]] = 0.25
x = add_gaps(indices_masks, y, coordinates)
return x, y
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -64,6 +64,7 @@ def find_version(*file_paths):
"tensorflow",
"pandas",
"numpy",
"numba",
"keras_bed_sequence>=1.0.13"
],
extras_require=extras,
Expand Down

0 comments on commit 068a14d

Please sign in to comment.