<commit_before>from matplotlib import pyplot as plt
import numpy as np

import param

from ..core import ViewOperation
from ..views import ItemTable, SheetMatrix, VectorField, Contours


class chain(ViewOperation):
    """
    Definining a viewoperation chain is an easy way to define a new
    ViewOperation from a series of existing ones. The single argument
    is a callable that accepts an input view and returns a list of
    output views. To create the custom ViewOperation, you will need to
    supply this argument to a new instance of chain. For example:

    chain.instance(chain=lambda x: [cmap2rgb(operator(x).N, cmap='jet')])

    This is now a ViewOperation that sums the data in the input
    overlay and turns it into an RGB SheetMatrix with the 'jet'
    colormap.
    """

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

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


class operator(ViewOperation):
    """
    Applies any arbitrary operator on the data (currently only
    supports SheetViews) and returns the result.
    """

    operator = param.Callable(np.add, doc="""
        The binary operator to apply between the data attributes of
        the supplied Views. By default, performs elementwise addition
        across the SheetMatrix arrays.""")

    label = param.String(default='Operation', doc="""
        The label for the result after having applied the operator.""")

    def _process(self, overlay, key=None):

        if not isinstance(overlay, Overlay):
            raise Exception("Operation requires an Overlay as input")

        new_data = self.p.operator(*[el.data for el in overlay.data])
        return [SheetMatrix(new_data, bounds=overlay.bounds, label=self.p.label,
                          roi_bounds=overlay.roi_bounds)]


class contours(ViewOperation):
    """<commit_msg>Fixed operations/views.py<commit_after>from matplotlib import pyplot as plt
import numpy as np

import param

from ..core import Dimension, ViewOperation, Overlay
from ..views import ItemTable, SheetMatrix, VectorField, Contours


class chain(ViewOperation):
    """
    Definining a viewoperation chain is an easy way to define a new
    ViewOperation from a series of existing ones. The single argument
    is a callable that accepts an input view and returns a list of
    output views. To create the custom ViewOperation, you will need to
    supply this argument to a new instance of chain. For example:

    chain.instance(chain=lambda x: [cmap2rgb(operator(x).N, cmap='jet')])

    This is now a ViewOperation that sums the data in the input
    overlay and turns it into an RGB SheetMatrix with the 'jet'
    colormap.
    """

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

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


class operator(ViewOperation):
    """
    Applies any arbitrary operator on the data (currently only
    supports SheetViews) and returns the result.
    """

    operator = param.Callable(np.add, doc="""
        The binary operator to apply between the data attributes of
        the supplied Views. By default, performs elementwise addition
        across the SheetMatrix arrays.""")

    label = param.String(default='Operation', doc="""
        The label for the result after having applied the operator.""")

    def _process(self, overlay, key=None):

        if not isinstance(overlay, Overlay):
            raise Exception("Operation requires an Overlay as input")

        new_data = self.p.operator(*[el.data for el in overlay.data])
        return [SheetMatrix(new_data, bounds=overlay[0].bounds, label=self.p.label,
                            roi_bounds=overlay[0].roi_bounds)]


class contours(ViewOperation):
    """
{'fraction_non_alphanumeric': 0.08267509215376515, 'fraction_numerical': 0.00105318588730911, 'mean_word_length': 3.230512249443207, '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': '1049183', 'n_tokens_mistral': 1032, 'n_tokens_neox': 989, 'n_words': 413}