


"""simple docstring"""

from scipy.stats import spearmanr

import datasets


UpperCamelCase			:       List[str]									=				"\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"

UpperCamelCase			:       str									=				"\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"

UpperCamelCase			:       str									=				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    ):





     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			,  __UpperCAmelCase			,  __UpperCAmelCase			,  __UpperCAmelCase=False   ):

      '''simple docstring'''




      __UpperCamelCase       						= spearmanr(__UpperCAmelCase			,  __UpperCAmelCase   )
      if return_pvalue:
       return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
      else:
       return {"spearmanr": results[0]}





"""simple docstring"""

import unittest
from typing import Dict, List, Optional, Union

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import BridgeTowerImageProcessor

class __lowerCAmelCase	(   unittest.TestCase    ):





     def __init__(			self			,  __UpperCAmelCase			,  __UpperCAmelCase = True			,  __UpperCAmelCase = None			,  __UpperCAmelCase = 32			,  __UpperCAmelCase = True			,  __UpperCAmelCase = 1 / 255			,  __UpperCAmelCase = True			,  __UpperCAmelCase = True			,  __UpperCAmelCase = [0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]			,  __UpperCAmelCase = [0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]			,  __UpperCAmelCase = True			,  __UpperCAmelCase=7			,  __UpperCAmelCase=30			,  __UpperCAmelCase=400			,  __UpperCAmelCase=3			,  ):

      '''simple docstring'''




      __UpperCamelCase       						= parent
      __UpperCamelCase       						= do_resize
      __UpperCamelCase       						= size if size is not None else {'shortest_edge': 288}
      __UpperCamelCase       						= size_divisor
      __UpperCamelCase       						= do_rescale
      __UpperCamelCase       						= rescale_factor
      __UpperCamelCase       						= do_normalize
      __UpperCamelCase       						= do_center_crop
      __UpperCamelCase       						= image_mean
      __UpperCamelCase       						= image_std
      __UpperCamelCase       						= do_pad
      __UpperCamelCase       						= batch_size
      __UpperCamelCase       						= num_channels
      __UpperCamelCase       						= min_resolution
      __UpperCamelCase       						= max_resolution





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      return {
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_normalize": self.do_normalize,
          "do_resize": self.do_resize,
          "size": self.size,
          "size_divisor": self.size_divisor,
      }







     def 		UpperCAmelCase      (			self			,  __UpperCAmelCase			,  __UpperCAmelCase=False   ):

      '''simple docstring'''




      if not batched:
       __UpperCamelCase       						= self.size['shortest_edge']
       __UpperCamelCase       						= image_inputs[0]
       if isinstance(__UpperCAmelCase			,  Image.Image   ):
        __UpperCamelCase						,			__UpperCamelCase       						= image.size
       else:
        __UpperCamelCase						,			__UpperCamelCase       						= image.shape[1], image.shape[2]
       __UpperCamelCase       						= size / min(__UpperCAmelCase			,  __UpperCAmelCase   )
       if h < w:
        __UpperCamelCase						,			__UpperCamelCase       						= size, scale * w
       else:
        __UpperCamelCase						,			__UpperCamelCase       						= scale * h, size

       __UpperCamelCase       						= int((1333 / 800) * size   )
       if max(__UpperCAmelCase			,  __UpperCAmelCase   ) > max_size:
        __UpperCamelCase       						= max_size / max(__UpperCAmelCase			,  __UpperCAmelCase   )
        __UpperCamelCase       						= newh * scale
        __UpperCamelCase       						= neww * scale

       __UpperCamelCase						,			__UpperCamelCase       						= int(newh + 0.5   ), int(neww + 0.5   )
       __UpperCamelCase						,			__UpperCamelCase       						= (
           newh // self.size_divisor * self.size_divisor,
           neww // self.size_divisor * self.size_divisor,
       )

      else:
       __UpperCamelCase       						= []
       for image in image_inputs:
        __UpperCamelCase						,			__UpperCamelCase       						= self.get_expected_values([image]   )
        expected_values.append((expected_height, expected_width)   )
       __UpperCamelCase       						= max(__UpperCAmelCase			,  key=lambda __UpperCAmelCase   : item[0]   )[0]
       __UpperCamelCase       						= max(__UpperCAmelCase			,  key=lambda __UpperCAmelCase   : item[1]   )[1]

      return expected_height, expected_width


@require_torch
@require_vision
class __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ,						unittest.TestCase    ):
     lowercase		     =		BridgeTowerImageProcessor if is_vision_available() else None





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= BridgeTowerImageProcessingTester(self   )





     @property
     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      return self.image_processor_tester.prepare_image_processor_dict()





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class(**self.image_processor_dict   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'image_mean'   )   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'image_std'   )   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'do_normalize'   )   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'do_resize'   )   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'size'   )   )
      self.assertTrue(hasattr(__UpperCAmelCase			,  'size_divisor'   )   )





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      pass





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class(**self.image_processor_dict   )
      # create random PIL images
      __UpperCamelCase       						= prepare_image_inputs(self.image_processor_tester			,  equal_resolution=__UpperCAmelCase   )
      for image in image_inputs:
       self.assertIsInstance(__UpperCAmelCase			,  Image.Image   )

      # Test not batched input
      __UpperCamelCase       						= image_processing(image_inputs[0]			,  return_tensors='pt'   ).pixel_values

      __UpperCamelCase						,			__UpperCamelCase       						= self.image_processor_tester.get_expected_values(__UpperCAmelCase   )
      self.assertEqual(
          encoded_images.shape			,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)			,  )

      # Test batched
      __UpperCamelCase       						= image_processing(__UpperCAmelCase			,  return_tensors='pt'   ).pixel_values

      __UpperCamelCase						,			__UpperCamelCase       						= self.image_processor_tester.get_expected_values(__UpperCAmelCase			,  batched=__UpperCAmelCase   )
      self.assertEqual(
          encoded_images.shape			,  (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          )			,  )





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class(**self.image_processor_dict   )
      # create random numpy tensors
      __UpperCamelCase       						= prepare_image_inputs(self.image_processor_tester			,  equal_resolution=__UpperCAmelCase			,  numpify=__UpperCAmelCase   )
      for image in image_inputs:
       self.assertIsInstance(__UpperCAmelCase			,  np.ndarray   )

      # Test not batched input
      __UpperCamelCase       						= image_processing(image_inputs[0]			,  return_tensors='pt'   ).pixel_values

      __UpperCamelCase						,			__UpperCamelCase       						= self.image_processor_tester.get_expected_values(__UpperCAmelCase   )
      self.assertEqual(
          encoded_images.shape			,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)			,  )

      # Test batched
      __UpperCamelCase       						= image_processing(__UpperCAmelCase			,  return_tensors='pt'   ).pixel_values

      __UpperCamelCase						,			__UpperCamelCase       						= self.image_processor_tester.get_expected_values(__UpperCAmelCase			,  batched=__UpperCAmelCase   )
      self.assertEqual(
          encoded_images.shape			,  (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          )			,  )







     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.image_processing_class(**self.image_processor_dict   )
      # create random PyTorch tensors
      __UpperCamelCase       						= prepare_image_inputs(self.image_processor_tester			,  equal_resolution=__UpperCAmelCase			,  torchify=__UpperCAmelCase   )
      for image in image_inputs:
       self.assertIsInstance(__UpperCAmelCase			,  torch.Tensor   )

      # Test not batched input
      __UpperCamelCase       						= image_processing(image_inputs[0]			,  return_tensors='pt'   ).pixel_values

      __UpperCamelCase						,			__UpperCamelCase       						= self.image_processor_tester.get_expected_values(__UpperCAmelCase   )
      self.assertEqual(
          encoded_images.shape			,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)			,  )

      # Test batched
      __UpperCamelCase       						= image_processing(__UpperCAmelCase			,  return_tensors='pt'   ).pixel_values

      __UpperCamelCase						,			__UpperCamelCase       						= self.image_processor_tester.get_expected_values(__UpperCAmelCase			,  batched=__UpperCAmelCase   )
      self.assertEqual(
          encoded_images.shape			,  (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          )			,  )



