From 5ac9f9b1445574dd152c98b71352c7009d5865db Mon Sep 17 00:00:00 2001 From: Alexis DUBURCQ Date: Thu, 25 Jun 2020 15:06:35 +0200 Subject: [PATCH] Do not check bounds since it is always valid when everything is fine. (#95) --- tianshou/data/batch.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/tianshou/data/batch.py b/tianshou/data/batch.py index 21df4a4..7d13f97 100644 --- a/tianshou/data/batch.py +++ b/tianshou/data/batch.py @@ -171,18 +171,12 @@ class Batch: b[k] = Batch() elif hasattr(v, '__len__') and (not isinstance( v, (np.ndarray, torch.Tensor)) or v.ndim > 0): - if _valid_bounds(len(v), index): - if isinstance(index, (int, np.integer)) or \ - (isinstance(index, np.ndarray) and - index.ndim == 0) or \ - not isinstance(v, list): - b[k] = v[index] - else: - b[k] = [v[i] for i in index] + if isinstance(index, (int, np.integer)) or \ + (isinstance(index, np.ndarray) and + index.ndim == 0) or not isinstance(v, list): + b[k] = v[index] else: - raise IndexError( - f"Index {index} out of bounds for {type(v)} of " - f"len {len(self)}.") + b[k] = [v[i] for i in index] return b def __setitem__(self, index: Union[