<commit_before>import numpy as np

import param

from ..core import Dimension, ElementOperation, CompositeOverlay, \
                   NdOverlay, Overlay, BoundingBox
from ..core.util import find_minmax
from ..element.chart import Histogram, VectorField, Curve
from ..element.annotation import Contours
from ..element.raster import Matrix
from ..element.tabular import ItemTable
from .normalization import raster_normalization


class chain(ElementOperation):
    """
    Defining an ElementOperation chain is an easy way to define a new
    ElementOperation from a series of existing ones. The single
    argument is a callable that accepts an input element and returns
    the final, transformed element. To create the custom
    ElementOperation, you will need to supply this argument to a new
    instance of chain. For example:

    chain.instance(
       chain=lambda x: colormap(operator(x, operator=np.add), cmap='jet'))

    This defines an ElementOperation that sums the data in the input
    and turns it into an RGB Matrix using the 'jet' colormap.
    """

    value = param.String(default='Chain', doc="""
        The value assigned to the result after having applied the chain.""")


    chain = param.Callable(doc="""A chain of existing ViewOperations.""")

    def _process(self, view, key=None):
        return self.p.chain(view).clone(value=self.p.value)


class transform(ElementOperation):
    """
    Generic ElementOperation to transform an input Matrix or RGBA
    element into an output Matrix. The transformation is defined by
    the supplied callable that accepts the data of the input Matrix
    (typically a numpy array) and returns the transformed data of the
    output Matrix.

    This operator is extremely versatile; for instance, you could
    implement an alternative to the explict threshold operator with:

    operator=lambda x: np.clip(x, 0, 0.5)

    Alternatively, you can implement a transform computing the 2D
    autocorrelation using the scipy library with:

    operator=lambda x: scipy.signal.correlate2d(x, x)
    """
<commit_msg>Added output_type parameter to chain operation<commit_after>import numpy as np

import param

from ..core import Dimension, ElementOperation, CompositeOverlay, \
                   NdOverlay, Overlay, BoundingBox
from ..core.util import find_minmax
from ..element.chart import Histogram, VectorField, Curve
from ..element.annotation import Contours
from ..element.raster import Matrix
from ..element.tabular import ItemTable
from .normalization import raster_normalization


class chain(ElementOperation):
    """
    Defining an ElementOperation chain is an easy way to define a new
    ElementOperation from a series of existing ones. The single
    argument is a callable that accepts an input element and returns
    the final, transformed element. To create the custom
    ElementOperation, you will need to supply this argument to a new
    instance of chain. For example:

    chain.instance(
       chain=lambda x: colormap(operator(x, operator=np.add), cmap='jet'))

    This defines an ElementOperation that sums the data in the input
    and turns it into an RGB Matrix using the 'jet' colormap.
    """

    output_type = param.Parameter(Matrix, doc="""
        The output type of the chain operation. Must be supplied if
        the chain is to be used as a channel operation.""")

    value = param.String(default='Chain', doc="""
        The value assigned to the result after having applied the chain.""")


    chain = param.Callable(doc="""A chain of existing ViewOperations.""")

    def _process(self, view, key=None):
        return self.p.chain(view).clone(value=self.p.value)


class transform(ElementOperation):
    """
    Generic ElementOperation to transform an input Matrix or RGBA
    element into an output Matrix. The transformation is defined by
    the supplied callable that accepts the data of the input Matrix
    (typically a numpy array) and returns the transformed data of the
    output Matrix.

    This operator is extremely versatile; for instance, you could
    implement an alternative to the explict threshold operator with:

    operator=lambda x: np.clip(x, 0, 0.5)

    Alternatively, you can implement a transform computing the 2D
    autocorrelation using the scipy library with:

    operator=lambda x: scipy.signal.correlate2d(x, x)
    """

{'fraction_non_alphanumeric': 0.06718464351005485, 'fraction_numerical': 0.0022851919561243145, 'mean_word_length': 3.554630593132154, 'pattern_counts': {'":': 0, '<': 3, '<?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': '792914', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1100, 'n_words': 509}