Skip to content

ding.data.buffer.middleware.sample_range_view

ding.data.buffer.middleware.sample_range_view

sample_range_view(buffer_, start=None, end=None)

Overview

The middleware that places restrictions on the range of indices during sampling.

Arguments: - start (:obj:int): The starting index. - end (:obj:int): One above the ending index.

Full Source Code

../ding/data/buffer/middleware/sample_range_view.py

1from typing import Callable, Any, List, Optional, Union, TYPE_CHECKING 2from ding.data.buffer import BufferedData 3if TYPE_CHECKING: 4 from ding.data.buffer.buffer import Buffer 5 6 7def sample_range_view(buffer_: 'Buffer', start: Optional[int] = None, end: Optional[int] = None) -> Callable: 8 """ 9 Overview: 10 The middleware that places restrictions on the range of indices during sampling. 11 Arguments: 12 - start (:obj:`int`): The starting index. 13 - end (:obj:`int`): One above the ending index. 14 """ 15 assert start is not None or end is not None 16 if start and start < 0: 17 start = buffer_.size + start 18 if end and end < 0: 19 end = buffer_.size + end 20 sample_range = slice(start, end) 21 22 def _sample_range_view(action: str, chain: Callable, *args, **kwargs) -> Any: 23 if action == "sample": 24 return chain(*args, sample_range=sample_range) 25 return chain(*args, **kwargs) 26 27 return _sample_range_view