Skip to content

Commit

Permalink
refactor read_numpy_file.py
Browse files Browse the repository at this point in the history
  • Loading branch information
JackKelly committed Sep 29, 2023
1 parent 28aedb0 commit 097728d
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions examples/read_numpy_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@
class NumpyDataset(Dataset):
def prepare(self) -> None:
"""Create simple numpy file."""
# Generate an array of random numbers
rng = np.random.default_rng()
DTYPE = np.uint8
low, high = np.iinfo(DTYPE).min, np.iinfo(DTYPE).max
array = rng.integers(
low=low,
high=high,
size=(100, 100, 100, 100),
dtype=DTYPE,
)
print("Created array", flush=True)

# Save array to temporary file
array = _create_numpy_array()
with open(self.path, mode="wb") as fh:
np.save(fh, array)
np.save(fh, array)


class ReadNumpyFile(Workload):
Expand All @@ -35,3 +23,11 @@ def run(self):
@property
def n_repeats(self) -> int:
return 10


def _create_numpy_array() -> np.ndarray:
"""Generate an array of random numbers."""
DTYPE = np.uint8
low, high = np.iinfo(DTYPE).min, np.iinfo(DTYPE).max
rng = np.random.default_rng()
return rng.integers(low=low, high=high, size=(100, 100, 100, 100), dtype=DTYPE)

0 comments on commit 097728d

Please sign in to comment.