<commit_before>import numpy as np

from PyPi.utils.dataset import parse_dataset


class ReplayMemory(object):
    def __init__(self, max_size):
        self._max_size = max_size
        self._idx = 0
        self._full = False

    def initialize(self, mdp_info):
        observation_space = mdp_info['observation_space']
        action_space = mdp_info['action_space']

        observation_shape = tuple([self._max_size]) + observation_space.shape
        action_shape = (self._max_size, action_space.shape)

        self._states = np.empty(observation_shape, dtype=np.float32)
        self._actions = np.empty(action_shape, dtype=np.float32)
        self._rewards = np.empty(self._max_size, dtype=np.float32)
        self._next_states = np.empty(observation_shape, dtype=np.float32)
        self._absorbing = np.empty(self._max_size, dtype=np.bool)
        self._last = np.empty(self._max_size, dtype=np.bool)

    def add(self, dataset):
        assert self._idx + len(dataset) <= self._max_size

        states, actions, rewards, next_states, absorbing, last = parse_dataset(
            dataset
        )

        self._states[self._idx:, ...] = states
        self._actions[self._idx:, ...] = actions
        self._rewards[self._idx:, ...] = rewards
        self._next_states[self._idx:, ...] = next_states
        self._absorbing[self._idx:, ...] = absorbing
        self._last[self._idx, ...] = last

        self._idx += len(dataset)
        if self._idx == self._max_size:
            self._full = True
            self._idx = 0

    def get(self, n_samples):
        idxs = np.random.randint(self.size, size=n_samples)

        return self._states[idxs, ...], self._actions[idxs, ...],\
            self._rewards[idxs, ...], self._next_states[idxs, ...],\
            self._absorbing[idxs, ...], self._last[idxs, ...]

    @property
    def size(self):
        return self._idx if not self._full else self._max_size<commit_msg>fix in replay_memory<commit_after>import numpy as np

from PyPi.utils.dataset import parse_dataset


class ReplayMemory(object):
    def __init__(self, max_size):
        self._max_size = max_size
        self._idx = 0
        self._full = False

    def initialize(self, mdp_info):
        observation_space = mdp_info['observation_space']
        action_space = mdp_info['action_space']

        observation_shape = tuple([self._max_size]) + observation_space.shape
        action_shape = (self._max_size, action_space.shape)

        self._states = np.empty(observation_shape, dtype=np.float32)
        self._actions = np.empty(action_shape, dtype=np.float32)
        self._rewards = np.empty(self._max_size, dtype=np.float32)
        self._next_states = np.empty(observation_shape, dtype=np.float32)
        self._absorbing = np.empty(self._max_size, dtype=np.bool)
        self._last = np.empty(self._max_size, dtype=np.bool)

    def add(self, dataset):
        assert self._idx + len(dataset) <= self._max_size

        states, actions, rewards, next_states, absorbing, last = parse_dataset(
            dataset
        )

        self._states[self._idx:self._idx + len(dataset), ...] = states
        self._actions[self._idx:self._idx + len(dataset), ...] = actions
        self._rewards[self._idx:self._idx + len(dataset), ...] = rewards
        self._next_states[self._idx:self._idx + len(dataset), ...] = next_states
        self._absorbing[self._idx:self._idx + len(dataset), ...] = absorbing
        self._last[self._idxself._idx + len(dataset), ...] = last

        self._idx += len(dataset)
        if self._idx == self._max_size:
            self._full = True
            self._idx = 0

    def get(self, n_samples):
        idxs = np.random.randint(self.size, size=n_samples)

        return self._states[idxs, ...], self._actions[idxs, ...],\
            self._rewards[idxs, ...], self._next_states[idxs, ...],\
            self._absorbing[idxs, ...], self._last[idxs, ...]

    @property
    def size(self):
        return self._idx if not self._full else self._max_size
{'fraction_non_alphanumeric': 0.13359821206853736, 'fraction_numerical': 0.004966476285075739, 'mean_word_length': 2.5240594925634294, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6509816', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1248, 'n_words': 225}