Skip to content

Commit

Permalink
Remove unneeded print from debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
hristo-vrigazov committed Aug 23, 2023
1 parent dbe29d7 commit 796e308
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 29 additions & 0 deletions MICROLIB.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ wrapped = Wrapped(dataset, wrapper_fn=torch.tensor)
print(wrapped[14])
```

Before the `wrapper_fn` is called, a copy of the sample is made to avoid warnings
about non-writeable underlying tensor. If you are going to only read from the sample,
you can pass `copy_before_wrapper_fn=False` when initializing the object.
For example:

```python
import numpy as np
import torch
from mmap_ninja.base import Wrapped

dataset = [np.array([1, 2, 3], np.array([-1, 10]))]
wrapped = Wrapped(dataset, wrapper_fn=torch.tensor, copy_before_wrapper_fn=False)

print(wrapped[14])
```

### Create a Numpy memmap from a Numpy array

The `mmap_ninja.numpy` module provides utilities for
Expand Down Expand Up @@ -179,6 +195,19 @@ images = RaggedMmap('val_images', wrapper_fn=torch.tensor)
assert isinstance(torch.Tensor, images[4])
```

Before the `wrapper_fn` is called, a copy of the sample is made to avoid warnings
about non-writeable underlying tensor. If you are going to only read from the sample,
you can pass `copy_before_wrapper_fn=False` when initializing the object.

```python
import numpy as np
import torch
from mmap_ninja.ragged import RaggedMmap

images = RaggedMmap('val_images', wrapper_fn=torch.tensor, copy_before_wrapper_fn=False)
assert isinstance(torch.Tensor, images[4])
```

### Append new samples to a RaggedMmap

To append a single sample, use `RaggedMmap.append`.
Expand Down
2 changes: 0 additions & 2 deletions python/mmap_ninja/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ def __getitem__(self, item):
sample = self.data[item]
if self.copy_before_wrapper_fn:
sample = copy(sample)
else:
print("Yo")
return self.wrapper_fn(sample)

def __len__(self):
Expand Down

0 comments on commit 796e308

Please sign in to comment.