-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
43 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import numpy as np | ||
from typing import Optional | ||
|
||
class DeeplakeRandom(object): | ||
def __new__(cls): | ||
if not hasattr(cls, 'instance'): | ||
cls.instance = super(DeeplakeRandom, cls).__new__(cls) | ||
cls.instance.internal_seed = None | ||
return cls.instance | ||
|
||
def seed(self, seed: Optional[int] = None): | ||
if isinstance(seed, Optional[int]): | ||
self.internal_seed = seed | ||
else: | ||
raise TypeError(f"provided seed type `{type(seed)}` is increect seed must be an integer") | ||
|
||
def get_seed(self) -> Optional[int]: | ||
return self.internal_seed | ||
|
||
|
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
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import numpy as np | ||
from deeplake.core.seed import DeeplakeRandom | ||
|
||
|
||
|
||
def shuffle(ds): | ||
"""Returns a shuffled wrapper of a given Dataset.""" | ||
prev_state = np.random.get_state() | ||
np.random.seed(DeeplakeRandom().get_seed()) | ||
idxs = np.arange(len(ds)) | ||
np.random.shuffle(idxs) | ||
np.random.set_state(prev_state) | ||
return ds[idxs.tolist()] |