
from scipy.stats import spearmanr

import datasets


_UpperCAmelCase					: Any      =       """
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.
"""

_UpperCAmelCase					: Optional[int]      =       """
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
"""

_UpperCAmelCase					: Dict      =       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 				lowercase					(		datasets.Metric   ):



		def __UpperCamelCase ( self       )  ->					Any:
				"""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       )  ->					Tuple:
				"""simple docstring"""
				UpperCamelCase		=     spearmanr(_a				,      _a       )
				if return_pvalue:
						return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
				else:
						return {"spearmanr": results[0]}






"""simple docstring"""




import json
import os
import shutil
import tempfile
import unittest

import numpy as np

from transformers import BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES, BertTokenizer
from transformers.testing_utils import require_tokenizers, require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
					from PIL import Image

					from transformers import VisionTextDualEncoderProcessor, ViTImageProcessor






@require_tokenizers
@require_vision
class     __magic_name__							(       unittest.TestCase				):






				'''simple docstring'''





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					tempfile.mkdtemp()

							# fmt: off
							lowerCamelCase			      =					["""[UNK]""", """[CLS]""", """[SEP]""", """[PAD]""", """[MASK]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing""", """,""", """low""", """lowest"""]
							# fmt: on
							lowerCamelCase			      =					os.path.join(self.tmpdirname		, VOCAB_FILES_NAMES["""vocab_file"""] )
							with open(self.vocab_file		, """w"""		, encoding="""utf-8""" ) as vocab_writer:
										vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens] ) )

							lowerCamelCase			      =					{
							    """do_resize""": True,
							    """size""": {"""height""": 18, """width""": 18},
							    """do_normalize""": True,
							    """image_mean""": [0.5, 0.5, 0.5],
							    """image_std""": [0.5, 0.5, 0.5],
							}
							lowerCamelCase			      =					os.path.join(self.tmpdirname		, _a )
							with open(self.image_processor_file		, """w"""		, encoding="""utf-8""" ) as fp:
										json.dump(_a		, _a )





				def    _lowerCAmelCase				(       self		, **_a ):





							"""simple docstring"""
							return BertTokenizer.from_pretrained(self.tmpdirname		, **_a )





				def    _lowerCAmelCase				(       self		, **_a ):





							"""simple docstring"""
							return ViTImageProcessor.from_pretrained(self.tmpdirname		, **_a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							shutil.rmtree(self.tmpdirname )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					[np.random.randint(255		, size=(3, 30, 400)		, dtype=np.uinta )]

							lowerCamelCase			      =					[Image.fromarray(np.moveaxis(_a		, 0		, -1 ) ) for x in image_inputs]

							return image_inputs





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					self.get_tokenizer()
							lowerCamelCase			      =					self.get_image_processor()

							lowerCamelCase			      =					VisionTextDualEncoderProcessor(tokenizer=_a		, image_processor=_a )

							processor.save_pretrained(self.tmpdirname )
							lowerCamelCase			      =					VisionTextDualEncoderProcessor.from_pretrained(self.tmpdirname )

							self.assertEqual(processor.tokenizer.get_vocab()		, tokenizer.get_vocab() )
							self.assertIsInstance(processor.tokenizer		, (BertTokenizer, BertTokenizerFast) )

							self.assertEqual(processor.image_processor.to_json_string()		, image_processor.to_json_string() )
							self.assertIsInstance(processor.image_processor		, _a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					VisionTextDualEncoderProcessor(
							    tokenizer=self.get_tokenizer()		, image_processor=self.get_image_processor() )
							processor.save_pretrained(self.tmpdirname )

							lowerCamelCase			      =					self.get_tokenizer(bos_token="""(BOS)"""		, eos_token="""(EOS)""" )
							lowerCamelCase			      =					self.get_image_processor(do_normalize=_a		, padding_value=1.0 )

							lowerCamelCase			      =					VisionTextDualEncoderProcessor.from_pretrained(
							    self.tmpdirname		, bos_token="""(BOS)"""		, eos_token="""(EOS)"""		, do_normalize=_a		, padding_value=1.0 )

							self.assertEqual(processor.tokenizer.get_vocab()		, tokenizer_add_kwargs.get_vocab() )
							self.assertIsInstance(processor.tokenizer		, (BertTokenizer, BertTokenizerFast) )

							self.assertEqual(processor.image_processor.to_json_string()		, image_processor_add_kwargs.to_json_string() )
							self.assertIsInstance(processor.image_processor		, _a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					self.get_image_processor()
							lowerCamelCase			      =					self.get_tokenizer()

							lowerCamelCase			      =					VisionTextDualEncoderProcessor(tokenizer=_a		, image_processor=_a )

							lowerCamelCase			      =					self.prepare_image_inputs()

							lowerCamelCase			      =					image_processor(_a		, return_tensors="""np""" )
							lowerCamelCase			      =					processor(images=_a		, return_tensors="""np""" )

							for key in input_feat_extract.keys():
										self.assertAlmostEqual(input_feat_extract[key].sum()		, input_processor[key].sum()		, delta=1e-2 )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					self.get_image_processor()
							lowerCamelCase			      =					self.get_tokenizer()

							lowerCamelCase			      =					VisionTextDualEncoderProcessor(tokenizer=_a		, image_processor=_a )

							lowerCamelCase			      =					"""lower newer"""

							lowerCamelCase			      =					processor(text=_a )

							lowerCamelCase			      =					tokenizer(_a )

							for key in encoded_tok.keys():
										self.assertListEqual(encoded_tok[key]		, encoded_processor[key] )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					self.get_image_processor()
							lowerCamelCase			      =					self.get_tokenizer()

							lowerCamelCase			      =					VisionTextDualEncoderProcessor(tokenizer=_a		, image_processor=_a )

							lowerCamelCase			      =					"""lower newer"""
							lowerCamelCase			      =					self.prepare_image_inputs()

							lowerCamelCase			      =					processor(text=_a		, images=_a )

							self.assertListEqual(list(inputs.keys() )		, ["""input_ids""", """token_type_ids""", """attention_mask""", """pixel_values"""] )

							# test if it raises when no input is passed
							with self.assertRaises(_a ):
										processor()





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					self.get_image_processor()
							lowerCamelCase			      =					self.get_tokenizer()

							lowerCamelCase			      =					VisionTextDualEncoderProcessor(tokenizer=_a		, image_processor=_a )

							lowerCamelCase			      =					[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

							lowerCamelCase			      =					processor.batch_decode(_a )
							lowerCamelCase			      =					tokenizer.batch_decode(_a )

							self.assertListEqual(_a		, _a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					self.get_image_processor()
							lowerCamelCase			      =					self.get_tokenizer()

							lowerCamelCase			      =					VisionTextDualEncoderProcessor(tokenizer=_a		, image_processor=_a )

							lowerCamelCase			      =					"""lower newer"""
							lowerCamelCase			      =					self.prepare_image_inputs()

							lowerCamelCase			      =					processor(text=_a		, images=_a )

							self.assertListEqual(list(inputs.keys() )		, processor.model_input_names )



