<commit_before>#! /usr/bin/env python

"""
Copyright 2015-2018 <NAME> <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import numpy as np
import imgstore


class StoreReader:

    def __init__(self, path):
        self.store = imgstore.new_for_filename(path)
        self.metadata = self.store.get_frame_metadata()
        self.metaindex = np.array(self.metadata['frame_number'])

    def __len__(self):
        return self.index.shape[0]

    def get_data(self, indexes):
        indexes = self.metaindex[indexes]

        frames = []
        frame_numbers = []
        frame_timestamps = []
        for idx in indexes:
            if idx is self.store.frame_number + 1:
                frame, (frame_number, frame_timestamp) = self.store.get_next_framenumber(exact_only=False)
            else:
                frame, (frame_number, frame_timestamp) = self.store.get_image(idx, exact_only=False)
            frames.append(frame)
            frame_numbers.append(frame_number)
            frame_timestamps.append(frame_timestamp)
        frames = np.stack(frames)
        frame_numbers = np.array(frame_numbers)
        frame_timestamps = np.array(frame_timestamps)

        return frames, frame_numbers, frame_timestamps

    def _check_index(self, key):
        if isinstance(key, slice):
            start = key.start
            stop = key.stop
            if start is None:
                start = 0
            if stop is None:
                stop = len(self) - 1
            if stop < len(self):
                idx = range(start, stop)
            else:<commit_msg>Add empty axis for grayscale<commit_after>#! /usr/bin/env python

"""
Copyright 2015-2018 <NAME> <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import numpy as np
import imgstore


class StoreReader:

    def __init__(self, path):
        self.store = imgstore.new_for_filename(path)
        self.metadata = self.store.get_frame_metadata()
        self.metaindex = np.array(self.metadata['frame_number'])

    def __len__(self):
        return self.index.shape[0]

    def get_data(self, indexes):
        indexes = self.metaindex[indexes]

        frames = []
        frame_numbers = []
        frame_timestamps = []
        for idx in indexes:
            if idx is self.store.frame_number + 1:
                frame, (frame_number, frame_timestamp) = self.store.get_next_framenumber(exact_only=False)
            else:
                frame, (frame_number, frame_timestamp) = self.store.get_image(idx, exact_only=False)
            frames.append(frame)
            frame_numbers.append(frame_number)
            frame_timestamps.append(frame_timestamp)
        frames = np.stack(frames)
        if frames.ndim == 3:
            frames = frames[..., np.newaxis]
        frame_numbers = np.array(frame_numbers)
        frame_timestamps = np.array(frame_timestamps)

        return frames, frame_numbers, frame_timestamps

    def _check_index(self, key):
        if isinstance(key, slice):
            start = key.start
            stop = key.stop
            if start is None:
                start = 0
            if stop is None:
                stop = len(self) - 1
            if stop < len(self):
                idx = range(start, stop)
            else:
{'fraction_non_alphanumeric': 0.08481402511253258, 'fraction_numerical': 0.007818052594171997, 'mean_word_length': 2.4158576051779934, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2723823', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1156, 'n_words': 361}