Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RoundRobinWriter #2

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
init
  • Loading branch information
vmoens committed Jun 19, 2023
commit 4d2c6df1df6779bc48a4ec2b75dd38737b0d99f5
12 changes: 2 additions & 10 deletions torchrl/data/replay_buffers/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,8 @@ def add(self, data: Any) -> int:
def extend(self, data: Sequence) -> torch.Tensor:
cur_size = self._cursor
batch_size = len(data)
if cur_size + batch_size <= self._storage.max_size:
index = np.arange(cur_size, cur_size + batch_size)
self._cursor = (self._cursor + batch_size) % self._storage.max_size
else:
d = self._storage.max_size - cur_size
index = np.empty(batch_size, dtype=np.int64)
index[:d] = np.arange(cur_size, self._storage.max_size)
index[d:] = np.arange(batch_size - d)
self._cursor = batch_size - d
# storage must convert the data to the appropriate format if needed
index = np.arange(cur_size, batch_size + cur_size) % self._storage.max_size
self._cursor = (batch_size + cur_size) % self._storage.max_size
self._storage[index] = data
return index

Expand Down