






from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
    import PIL


__lowerCamelCase	:					Optional[Any]			  =					logging.get_logger(__name__)



class  A__       (	__lowercase      ):
      _UpperCAmelCase     :Union[str, Any]						   =       ["pixel_values"]





      def __init__(			self	,							A_ = True	,							A_ = None	,							A_ = PIL.Image.BICUBIC	,							A_ = True	,							A_ = None	,							A_ = 1 / 255	,							A_ = True	,							A_ = True	,							A_ = None	,							A_ = None	,							**A_	,							):
       '''simple docstring'''




       super().__init__(**_a       )
       UpperCamelCase     : Dict	     =       size if size is not None else {'''height''': 256, '''width''': 256}
       UpperCamelCase     : int	     =       get_size_dict(_a       )
       UpperCamelCase     : Tuple	     =       crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
       UpperCamelCase     : Dict	     =       get_size_dict(_a	,							param_name="crop_size"       )

       UpperCamelCase     : Union[str, Any]	     =       do_resize
       UpperCamelCase     : Any	     =       size
       UpperCamelCase     : List[Any]	     =       resample
       UpperCamelCase     : List[Any]	     =       do_center_crop
       UpperCamelCase     : Union[str, Any]	     =       crop_size
       UpperCamelCase     : str	     =       do_rescale
       UpperCamelCase     : Union[str, Any]	     =       rescale_factor
       UpperCamelCase     : int	     =       do_normalize
       UpperCamelCase     : List[Any]	     =       image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
       UpperCamelCase     : Optional[Any]	     =       image_std if image_std is not None else IMAGENET_STANDARD_STD





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_ = PIL.Image.BICUBIC	,							A_ = None	,							**A_	,							):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       get_size_dict(_a       )
       if "height" not in size or "width" not in size:
        raise ValueError(F"""The size dictionary must have keys 'height' and 'width'. Got {size.keys()}"""       )
       return resize(
           _a	,							size=(size["height"], size["width"])	,							resample=_a	,							data_format=_a	,							**_a       )





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_ = None	,							**A_	,							):
       '''simple docstring'''




       UpperCamelCase     : Union[str, Any]	     =       get_size_dict(_a       )
       if "height" not in size or "width" not in size:
        raise ValueError(F"""The size dictionary must have keys 'height' and 'width'. Got {size.keys()}"""       )
       return center_crop(_a	,							size=(size["height"], size["width"])	,							data_format=_a	,							**_a       )





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_ = None	,							**A_	,							):
       '''simple docstring'''




       return rescale(_a	,							scale=_a	,							data_format=_a	,							**_a       )





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_ = None	,							**A_	,							):
       '''simple docstring'''




       return normalize(_a	,							mean=_a	,							std=_a	,							data_format=_a	,							**_a       )





      def 	__UpperCamelCase(			self	,							A_	,							A_ = None	,							A_ = None	,							A_=None	,							A_ = None	,							A_ = None	,							A_ = None	,							A_ = None	,							A_ = None	,							A_ = None	,							A_ = None	,							A_ = None	,							A_ = ChannelDimension.FIRST	,							**A_	,							):
       '''simple docstring'''




       UpperCamelCase     : int	     =       do_resize if do_resize is not None else self.do_resize
       UpperCamelCase     : int	     =       resample if resample is not None else self.resample
       UpperCamelCase     : Optional[Any]	     =       do_center_crop if do_center_crop is not None else self.do_center_crop
       UpperCamelCase     : Any	     =       do_rescale if do_rescale is not None else self.do_rescale
       UpperCamelCase     : Optional[int]	     =       rescale_factor if rescale_factor is not None else self.rescale_factor
       UpperCamelCase     : List[Any]	     =       do_normalize if do_normalize is not None else self.do_normalize
       UpperCamelCase     : Optional[int]	     =       image_mean if image_mean is not None else self.image_mean
       UpperCamelCase     : Tuple	     =       image_std if image_std is not None else self.image_std

       UpperCamelCase     : Any	     =       size if size is not None else self.size
       UpperCamelCase     : str	     =       get_size_dict(_a       )
       UpperCamelCase     : List[Any]	     =       crop_size if crop_size is not None else self.crop_size
       UpperCamelCase     : int	     =       get_size_dict(_a	,							param_name="crop_size"       )

       UpperCamelCase     : Union[str, Any]	     =       make_list_of_images(_a       )

       if not valid_images(_a       ):
        raise ValueError(
            "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
            "torch.Tensor, tf.Tensor or jax.ndarray."       )

       if do_resize and size is None or resample is None:
        raise ValueError("Size and resample must be specified if do_resize is True."       )

       if do_center_crop and crop_size is None:
        raise ValueError("Crop size must be specified if do_center_crop is True."       )

       if do_rescale and rescale_factor is None:
        raise ValueError("Rescale factor must be specified if do_rescale is True."       )

       if do_normalize and (image_mean is None or image_std is None):
        raise ValueError("Image mean and std must be specified if do_normalize is True."       )

       # All transformations expect numpy arrays.
       UpperCamelCase     : Dict	     =       [to_numpy_array(_a       ) for image in images]

       if do_resize:
        UpperCamelCase     : Optional[int]	     =       [self.resize(image=_a	,							size=_a	,							resample=_a       ) for image in images]

       if do_center_crop:
        UpperCamelCase     : Optional[Any]	     =       [self.center_crop(image=_a	,							size=_a       ) for image in images]

       if do_rescale:
        UpperCamelCase     : Optional[Any]	     =       [self.rescale(image=_a	,							scale=_a       ) for image in images]

       if do_normalize:
        UpperCamelCase     : Dict	     =       [self.normalize(image=_a	,							mean=_a	,							std=_a       ) for image in images]

       UpperCamelCase     : Tuple	     =       [to_channel_dimension_format(_a	,							_a       ) for image in images]

       UpperCamelCase     : Dict	     =       {'''pixel_values''': images}
       return BatchFeature(data=_a	,							tensor_type=_a       )







from scipy.stats import spearmanr

import datasets


__lowerCamelCase	:					List[str]			  =					"""
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
"""

__lowerCamelCase	:					List[Any]			  =					"""
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {'spearmanr': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results['spearmanr'])
        -0.7
        >>> print(round(results['spearmanr_pvalue'], 2))
        0.19
"""

__lowerCamelCase	:					Optional[int]			  =					r"""\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
"""



@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION	,       _KWARGS_DESCRIPTION      )
class  A__       (	datasets.Metric      ):





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       return datasets.MetricInfo(
           description=_DESCRIPTION	,							citation=_CITATION	,							inputs_description=_KWARGS_DESCRIPTION	,							features=datasets.Features(
               {
                   "predictions": datasets.Value("float"       ),
                   "references": datasets.Value("float"       ),
               }       )	,							reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"]	,							)





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_=False       ):
       '''simple docstring'''




       UpperCamelCase     : Tuple	     =       spearmanr(A_	,							A_       )
       if return_pvalue:
        return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
       else:
        return {"spearmanr": results[0]}
