From 796e308d5a8f392e40030ef854ddef450ace838c Mon Sep 17 00:00:00 2001 From: Hristo Vrigazov Date: Wed, 23 Aug 2023 08:27:27 +0300 Subject: [PATCH] Remove unneeded print from debugging. --- MICROLIB.md | 29 +++++++++++++++++++++++++++++ python/mmap_ninja/base.py | 2 -- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/MICROLIB.md b/MICROLIB.md index 099ab1f..ef6d41d 100644 --- a/MICROLIB.md +++ b/MICROLIB.md @@ -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 @@ -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`. diff --git a/python/mmap_ninja/base.py b/python/mmap_ninja/base.py index 2048359..6ad5b30 100644 --- a/python/mmap_ninja/base.py +++ b/python/mmap_ninja/base.py @@ -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):