




"""simple docstring"""







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 convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_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


__A   :  int					=      logging.get_logger(__name__)




class       lowerCAmelCase__       (			_UpperCamelCase    ):


				"""simple docstring"""





				__UpperCAmelCase :     str       =      ["pixel_values"]



				def __init__(     self					:	int    ,   lowercase__					:	bool = True    ,   lowercase__					:	Dict[str, int] = None    ,   lowercase__					:	PILImageResampling = PILImageResampling.BICUBIC    ,   lowercase__					:	bool = True    ,   lowercase__					:	Union[int, float] = 1 / 2_5_5    ,   lowercase__					:	bool = True    ,   lowercase__					:	Optional[Union[float, List[float]]] = None    ,   lowercase__					:	Optional[Union[float, List[float]]] = None    ,   lowercase__					:	bool = True    ,   **lowercase__					:	str    ,   ):
						super().__init__(**__a						)
						__lowercase				:		Optional[Any]												=				size if size is not None else {"height": 3_8_4, "width": 3_8_4}
						__lowercase				:		str												=				get_size_dict(__a    ,   default_to_square=__a						)

						__lowercase				:		Optional[Any]												=				do_resize
						__lowercase				:		List[str]												=				size
						__lowercase				:		Dict												=				resample
						__lowercase				:		List[str]												=				do_rescale
						__lowercase				:		str												=				rescale_factor
						__lowercase				:		Tuple												=				do_normalize
						__lowercase				:		Any												=				image_mean if image_mean is not None else OPENAI_CLIP_MEAN
						__lowercase				:		str												=				image_std if image_std is not None else OPENAI_CLIP_STD
						__lowercase				:		str												=				do_convert_rgb



				def       snake_case    (     self					:	Optional[int]    ,   lowercase__					:	np.ndarray    ,   lowercase__					:	Dict[str, int]    ,   lowercase__					:	PILImageResampling = PILImageResampling.BICUBIC    ,   lowercase__					:	Optional[Union[str, ChannelDimension]] = None    ,   **lowercase__					:	List[str]    ,   ):
						__lowercase				:		int												=				get_size_dict(__a    ,   default_to_square=__a						)
						if "height" not in size or "width" not in size:
								raise ValueError(f'The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'						)
						__lowercase				:		str												=				(size["height"], size["width"])
						return resize(__a    ,   size=__a    ,   resample=__a    ,   data_format=__a    ,   **__a						)



				def       snake_case    (     self					:	Optional[int]    ,   lowercase__					:	np.ndarray    ,   lowercase__					:	Union[int, float]    ,   lowercase__					:	Optional[Union[str, ChannelDimension]] = None    ,   **lowercase__					:	List[Any]    ,   ):
						return rescale(__a    ,   scale=__a    ,   data_format=__a    ,   **__a						)



				def       snake_case    (     self					:	List[str]    ,   lowercase__					:	np.ndarray    ,   lowercase__					:	Union[float, List[float]]    ,   lowercase__					:	Union[float, List[float]]    ,   lowercase__					:	Optional[Union[str, ChannelDimension]] = None    ,   **lowercase__					:	Tuple    ,   ):
						return normalize(__a    ,   mean=__a    ,   std=__a    ,   data_format=__a    ,   **__a						)



				def       snake_case    (     self					:	Union[str, Any]    ,   lowercase__					:	ImageInput    ,   lowercase__					:	Optional[bool] = None    ,   lowercase__					:	Optional[Dict[str, int]] = None    ,   lowercase__					:	PILImageResampling = None    ,   lowercase__					:	Optional[bool] = None    ,   lowercase__					:	Optional[float] = None    ,   lowercase__					:	Optional[bool] = None    ,   lowercase__					:	Optional[Union[float, List[float]]] = None    ,   lowercase__					:	Optional[Union[float, List[float]]] = None    ,   lowercase__					:	Optional[Union[str, TensorType]] = None    ,   lowercase__					:	bool = None    ,   lowercase__					:	ChannelDimension = ChannelDimension.FIRST    ,   **lowercase__					:	Tuple    ,   ):
						__lowercase				:		Optional[int]												=				do_resize if do_resize is not None else self.do_resize
						__lowercase				:		Dict												=				resample if resample is not None else self.resample
						__lowercase				:		Dict												=				do_rescale if do_rescale is not None else self.do_rescale
						__lowercase				:		Optional[int]												=				rescale_factor if rescale_factor is not None else self.rescale_factor
						__lowercase				:		Union[str, Any]												=				do_normalize if do_normalize is not None else self.do_normalize
						__lowercase				:		int												=				image_mean if image_mean is not None else self.image_mean
						__lowercase				:		List[Any]												=				image_std if image_std is not None else self.image_std
						__lowercase				:		str												=				do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

						__lowercase				:		Union[str, Any]												=				size if size is not None else self.size
						__lowercase				:		Union[str, Any]												=				get_size_dict(__a    ,   default_to_square=__a						)

						__lowercase				:		List[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_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."						)

						# PIL RGBA images are converted to RGB
						if do_convert_rgb:
								__lowercase				:		List[Any]												=				[convert_to_rgb(__a						) for image in images]

						# All transformations expect numpy arrays.
						__lowercase				:		List[str]												=				[to_numpy_array(__a						) for image in images]

						if do_resize:
								__lowercase				:		List[str]												=				[self.resize(image=__a    ,   size=__a    ,   resample=__a						) for image in images]

						if do_rescale:
								__lowercase				:		int												=				[self.rescale(image=__a    ,   scale=__a						) for image in images]

						if do_normalize:
								__lowercase				:		int												=				[self.normalize(image=__a    ,   mean=__a    ,   std=__a						) for image in images]

						__lowercase				:		Union[str, Any]												=				[to_channel_dimension_format(__a    ,   __a						) for image in images]

						__lowercase				:		Union[str, Any]												=				BatchFeature(data={"pixel_values": images}    ,   tensor_type=__a						)

						return encoded_outputs






"""simple docstring"""







from scipy.stats import spearmanr

import datasets


__A   :  Optional[int]					=      '\nThe Spearman rank-order correlation coefficient is a measure of the\nrelationship between two datasets. Like other correlation coefficients,\nthis one varies between -1 and +1 with 0 implying no correlation.\nPositive correlations imply that as data in dataset x increases, so\ndoes data in dataset y. Negative correlations imply that as x increases,\ny decreases. Correlations of -1 or +1 imply an exact monotonic relationship.\n\nUnlike the Pearson correlation, the Spearman correlation does not\nassume that both datasets are normally distributed.\n\nThe p-value roughly indicates the probability of an uncorrelated system\nproducing datasets that have a Spearman correlation at least as extreme\nas the one computed from these datasets. The p-values are not entirely\nreliable but are probably reasonable for datasets larger than 500 or so.\n'

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

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




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


				"""simple docstring"""





				def       snake_case    (     self					:	List[str]						):
						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       snake_case    (     self					:	Optional[int]    ,   lowercase__					:	str    ,   lowercase__					:	Any    ,   lowercase__					:	int=False						):
						__lowercase				:		Optional[int]												=				spearmanr(lowercase__    ,   lowercase__						)
						if return_pvalue:
								return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
						else:
								return {"spearmanr": results[0]}
