<commit_before>from keras.engine import Layer

from .._backends import UnknownSize
from . import RearrangeMixin, ReduceMixin

__author__ = '<NAME>'


class Rearrange(RearrangeMixin, Layer):
    def compute_output_shape(self, input_shape):
        input_shape = tuple(UnknownSize() if d is None else int(d) for d in input_shape)
        init_shapes, reduced_axes, axes_reordering, final_shape = self.recipe().reconstruct_from_shape(input_shape)
        final_shape = tuple(None if isinstance(d, UnknownSize) else int(d) for d in final_shape)
        return final_shape

    def call(self, inputs):
        return self._apply_recipe(inputs)

    def get_config(self):
        return {'pattern': self.pattern, **self.axes_lengths}


class Reduce(ReduceMixin, Layer):
    def compute_output_shape(self, input_shape):
        input_shape = tuple(UnknownSize() if d is None else int(d) for d in input_shape)
        init_shapes, reduced_axes, axes_reordering, final_shape = self.recipe().reconstruct_from_shape(input_shape)
        final_shape = tuple(None if isinstance(d, UnknownSize) else int(d) for d in final_shape)
        return final_shape

    def call(self, inputs):
        return self._apply_recipe(inputs)<commit_msg>deprecate keras layers, separate a function<commit_after>from keras.engine import Layer

from .._backends import UnknownSize
from . import RearrangeMixin, ReduceMixin
import warnings

__author__ = '<NAME>'

warnings.warn(
    'Keras does not exist anymore as an independent framework, '
    'these layers (targeted at old multi-framework keras) will be removed, '
    'please use einops.layers.tensorflow.',
    DeprecationWarning,
)


def _compute_output_shape(self, input_shape):
    input_shape = tuple(UnknownSize() if d is None else int(d) for d in input_shape)
    init_shapes, reduced_axes, axes_reordering, added_axes, final_shape = \
        self.recipe().reconstruct_from_shape(input_shape)
    final_shape = tuple(None if isinstance(d, UnknownSize) else int(d) for d in final_shape)
    return final_shape


class Rearrange(RearrangeMixin, Layer):
    def compute_output_shape(self, input_shape):
        return _compute_output_shape(self, input_shape)

    def call(self, inputs):
        return self._apply_recipe(inputs)

    def get_config(self):
        return {'pattern': self.pattern, **self.axes_lengths}


class Reduce(ReduceMixin, Layer):
    def compute_output_shape(self, input_shape):
        return _compute_output_shape(self, input_shape)

    def call(self, inputs):
        return self._apply_recipe(inputs)
{'fraction_non_alphanumeric': 0.08558030480656506, 'fraction_numerical': 0.0, 'mean_word_length': 4.245901639344262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6473983', 'n_tokens_mistral': 813, 'n_tokens_neox': 771, 'n_words': 214}