-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: ⚡️ Refactor to clean code and catch bugs.
Also begin working on sampler.
- Loading branch information
1 parent
504eda9
commit 4b4589b
Showing
5 changed files
with
48 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .sampler import CellMapSampler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Callable, Optional, Sequence, Sized | ||
import torch | ||
from torch.utils.data import Sampler | ||
|
||
|
||
class CellMapSampler(Sampler): | ||
def __init__( | ||
self, | ||
data_source: Sized, | ||
indices: Sequence[int], | ||
check_function: Optional[Callable] = None, | ||
generator: Optional[torch.Generator] = None, | ||
): | ||
super().__init__() | ||
self.data_source = data_source | ||
self.indices = indices | ||
self.check_function = check_function | ||
self.generator = generator | ||
|
||
def __iter__(self): | ||
for i in torch.randperm(len(self.indices), generator=self.generator): | ||
if self.check_function is None or self.check_function(self.indices[i]): | ||
yield self.indices[i] | ||
|
||
def __len__(self): | ||
return len(self.indices) |