Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time boost in folds generation #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions tscv/_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,17 @@ def __complement_masks(self, masks):

def __complement_indices(self, indices, n_samples):
before, after = self.gap_before, self.gap_after
allindices = np.arange(n_samples)
for index in indices:
complement = np.arange(n_samples)
for i in index:
begin = max(i - before, 0)
end = min(i + after + 1, n_samples)
complement = np.setdiff1d(complement, np.arange(begin, end))
# split index in subarrays of contiguous elements
subindexes = np.split(index, np.where(np.diff(index) != 1)[0] + 1)
complement = allindices
# find complement on arrays of contiguous elements
for subindex in subindexes:
begin = max(0, subindex[0] - before)
end = min(subindex[-1] + after + 1, n_samples)
complement = np.intersect1d(complement,
np.setdiff1d(allindices, allindices[begin:end]))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this line by using the fact $A \cap B^C = A \setminus B$.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @WenjieZ , I'm sorry, I didn't get it, can you reformulate your statement?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

complement = np.setdiff1d(complement, allindices[begin:end])

math

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, right! fixed!
Thank you

yield complement

@abstractmethod
Expand Down