






'''simple docstring'''







from scipy.stats import pearsonr

import datasets


_A	:			Optional[int]         ='''
Pearson correlation coefficient and p-value for testing non-correlation.
The Pearson correlation coefficient measures the linear relationship between two datasets. The calculation of the p-value relies on the assumption that each dataset is normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact linear relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases.
The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.
'''


_A	:			Optional[int]         ='''
Args:
    predictions (`list` of `int`): Predicted class labels, as returned by a model.
    references (`list` of `int`): Ground truth labels.
    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.

Returns:
    pearsonr (`float`): Pearson correlation coefficient. Minimum possible value is -1. Maximum possible value is 1. Values of 1 and -1 indicate exact linear positive and negative relationships, respectively. A value of 0 implies no correlation.
    p-value (`float`): P-value, which roughly indicates the probability of an The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate higher probabilities.

Examples:

    Example 1-A simple example using only predictions and references.
        >>> pearsonr_metric = datasets.load_metric("pearsonr")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])
        >>> print(round(results[\'pearsonr\'], 2))
        -0.74

    Example 2-The same as Example 1, but that also returns the `p-value`.
        >>> pearsonr_metric = datasets.load_metric("pearsonr")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)
        >>> print(sorted(list(results.keys())))
        [\'p-value\', \'pearsonr\']
        >>> print(round(results[\'pearsonr\'], 2))
        -0.74
        >>> print(round(results[\'p-value\'], 2))
        0.15
'''


_A	:			List[str]         ='''
@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, Ilhan 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, Antonio 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 		lowerCamelCase_				(							self:				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.pearsonr.html"""]			,							)




							def 		lowerCamelCase_				(							self:				Optional[int]			,							UpperCamelCase__:				Any			,							UpperCamelCase__:				Union[str, Any]			,							UpperCamelCase__:				Any=False     ):
														if return_pvalue:
																					lowerCamelCase__					:	str         =       pearsonr(UpperCamelCase__			,							UpperCamelCase__     )
																					return {"pearsonr": results[0], "p-value": results[1]}
														else:
																					return {"pearsonr": float(pearsonr(UpperCamelCase__			,							UpperCamelCase__     )[0]     )}









'''simple docstring'''







import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import MobileNetVaForImageClassification, MobileNetVaModel
			from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import MobileNetVaImageProcessor

class _lowercase	(				_lowercase		):




							def 		lowerCamelCase_				(							self:				Any     ):
														lowerCamelCase__					:	str         =       self.config_class(**self.inputs_dict     )
														self.parent.assertTrue(hasattr(UpperCamelCase__			,							"""tf_padding"""     )     )
														self.parent.assertTrue(hasattr(UpperCamelCase__			,							"""depth_multiplier"""     )     )



class _lowercase	:




							def __init__(							self:				str			,							UpperCamelCase__:				Dict			,							UpperCamelCase__:				Tuple=13			,							UpperCamelCase__:				Optional[int]=3			,							UpperCamelCase__:				List[Any]=32			,							UpperCamelCase__:				Optional[Any]=0.25			,							UpperCamelCase__:				int=8			,							UpperCamelCase__:				Any=True			,							UpperCamelCase__:				Dict=1_024			,							UpperCamelCase__:				Optional[int]=32			,							UpperCamelCase__:				Tuple="relu6"			,							UpperCamelCase__:				int=0.1			,							UpperCamelCase__:				List[Any]=0.02			,							UpperCamelCase__:				Optional[Any]=True			,							UpperCamelCase__:				Union[str, Any]=True			,							UpperCamelCase__:				Union[str, Any]=10			,							UpperCamelCase__:				str=None			,							):
														lowerCamelCase__					:	Optional[Any]         =       parent
														lowerCamelCase__					:	List[str]         =       batch_size
														lowerCamelCase__					:	Optional[int]         =       num_channels
														lowerCamelCase__					:	Optional[int]         =       image_size
														lowerCamelCase__					:	Optional[Any]         =       depth_multiplier
														lowerCamelCase__					:	Union[str, Any]         =       min_depth
														lowerCamelCase__					:	Optional[Any]         =       tf_padding
														lowerCamelCase__					:	str         =       int(last_hidden_size * depth_multiplier     )
														lowerCamelCase__					:	Any         =       output_stride
														lowerCamelCase__					:	int         =       hidden_act
														lowerCamelCase__					:	Tuple         =       classifier_dropout_prob
														lowerCamelCase__					:	Dict         =       use_labels
														lowerCamelCase__					:	Tuple         =       is_training
														lowerCamelCase__					:	Optional[Any]         =       num_labels
														lowerCamelCase__					:	Union[str, Any]         =       initializer_range
														lowerCamelCase__					:	Optional[Any]         =       scope




							def 		lowerCamelCase_				(							self:				List[str]     ):
														lowerCamelCase__					:	Optional[Any]         =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

														lowerCamelCase__					:	Optional[Any]         =       None
														lowerCamelCase__					:	Dict         =       None
														if self.use_labels:
																					lowerCamelCase__					:	Union[str, Any]         =       ids_tensor([self.batch_size]			,							self.num_labels     )
																					lowerCamelCase__					:	Dict         =       ids_tensor([self.batch_size, self.image_size, self.image_size]			,							self.num_labels     )

														lowerCamelCase__					:	Dict         =       self.get_config()

														return config, pixel_values, labels, pixel_labels




							def 		lowerCamelCase_				(							self:				str     ):
														return MobileNetVaConfig(
														    num_channels=self.num_channels			,							image_size=self.image_size			,							depth_multiplier=self.depth_multiplier			,							min_depth=self.min_depth			,							tf_padding=self.tf_padding			,							hidden_act=self.hidden_act			,							classifier_dropout_prob=self.classifier_dropout_prob			,							initializer_range=self.initializer_range			,							)




							def 		lowerCamelCase_				(							self:				Tuple			,							UpperCamelCase__:				int			,							UpperCamelCase__:				str			,							UpperCamelCase__:				Any			,							UpperCamelCase__:				Optional[int]     ):
														lowerCamelCase__					:	List[str]         =       MobileNetVaModel(config=UpperCamelCase__     )
														model.to(UpperCamelCase__     )
														model.eval()
														lowerCamelCase__					:	List[str]         =       model(UpperCamelCase__     )
														self.parent.assertEqual(
														    result.last_hidden_state.shape			,							(
														        self.batch_size,
														        self.last_hidden_size,
														        self.image_size // self.output_stride,
														        self.image_size // self.output_stride,
														    )			,							)




							def 		lowerCamelCase_				(							self:				str			,							UpperCamelCase__:				Tuple			,							UpperCamelCase__:				Optional[int]			,							UpperCamelCase__:				List[Any]			,							UpperCamelCase__:				Union[str, Any]     ):
														lowerCamelCase__					:	List[str]         =       self.num_labels
														lowerCamelCase__					:	Optional[Any]         =       MobileNetVaForImageClassification(UpperCamelCase__     )
														model.to(UpperCamelCase__     )
														model.eval()
														lowerCamelCase__					:	List[Any]         =       model(UpperCamelCase__			,							labels=UpperCamelCase__     )
														self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.num_labels)     )




							def 		lowerCamelCase_				(							self:				Optional[Any]     ):
														lowerCamelCase__					:	str         =       self.prepare_config_and_inputs()
														lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__					:	int         =       config_and_inputs
														lowerCamelCase__					:	Optional[int]         =       {"""pixel_values""": pixel_values}
														return config, inputs_dict



@require_torch
class _lowercase	(				_lowercase				,      _lowercase				,      unittest.TestCase		):
							a				      =       (MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
							a				      =       (
							    {"""feature-extraction""": MobileNetVaModel, """image-classification""": MobileNetVaForImageClassification}
							    if is_torch_available()
							    else {}
							)

							a				      =       False
							a				      =       False
							a				      =       False
							a				      =       False




							def 		lowerCamelCase_				(							self:				List[str]     ):
														lowerCamelCase__					:	Optional[int]         =       MobileNetVaModelTester(self     )
														lowerCamelCase__					:	List[str]         =       MobileNetVaConfigTester(self			,							config_class=UpperCamelCase__			,							has_text_modality=UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				Union[str, Any]     ):
														self.config_tester.run_common_tests()




							@unittest.skip(reason="""MobileNetV1 does not use inputs_embeds"""     )
							def 		lowerCamelCase_				(							self:				Optional[int]     ):
														pass




							@unittest.skip(reason="""MobileNetV1 does not support input and output embeddings"""     )
							def 		lowerCamelCase_				(							self:				Optional[Any]     ):
														pass




							@unittest.skip(reason="""MobileNetV1 does not output attentions"""     )
							def 		lowerCamelCase_				(							self:				Any     ):
														pass




							def 		lowerCamelCase_				(							self:				Any     ):
														lowerCamelCase__  ,		lowerCamelCase__					:	Optional[Any]         =       self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					lowerCamelCase__					:	Dict         =       model_class(UpperCamelCase__     )
																					lowerCamelCase__					:	Dict         =       inspect.signature(model.forward     )
																					# signature.parameters is an OrderedDict => so arg_names order is deterministic
																					lowerCamelCase__					:	List[Any]         =       [*signature.parameters.keys()]

																					lowerCamelCase__					:	Dict         =       ["""pixel_values"""]
																					self.assertListEqual(arg_names[:1]			,							UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				str     ):
														lowerCamelCase__					:	Tuple         =       self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				str     ):
														def check_hidden_states_output(UpperCamelCase__:				List[Any]			,							UpperCamelCase__:				Dict			,							UpperCamelCase__:				List[Any]     ):
																					lowerCamelCase__					:	str         =       model_class(UpperCamelCase__     )
																					model.to(UpperCamelCase__     )
																					model.eval()

																					with torch.no_grad():
																												lowerCamelCase__					:	Union[str, Any]         =       model(**self._prepare_for_class(UpperCamelCase__			,							UpperCamelCase__     )     )

																					lowerCamelCase__					:	List[Any]         =       outputs.hidden_states

																					lowerCamelCase__					:	Tuple         =       26
																					self.assertEqual(len(UpperCamelCase__     )			,							UpperCamelCase__     )

														lowerCamelCase__  ,		lowerCamelCase__					:	List[str]         =       self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					lowerCamelCase__					:	List[Any]         =       True
																					check_hidden_states_output(UpperCamelCase__			,							UpperCamelCase__			,							UpperCamelCase__     )

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					lowerCamelCase__					:	Optional[Any]         =       True

																					check_hidden_states_output(UpperCamelCase__			,							UpperCamelCase__			,							UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				Dict     ):
														lowerCamelCase__					:	int         =       self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_image_classification(*UpperCamelCase__     )




							@slow
							def 		lowerCamelCase_				(							self:				List[str]     ):
														for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					lowerCamelCase__					:	Dict         =       MobileNetVaModel.from_pretrained(UpperCamelCase__     )
																					self.assertIsNotNone(UpperCamelCase__     )





def  SCREAMING_SNAKE_CASE_       ()      ->       Union[str, Any]:
							lowerCamelCase__					:	Optional[int]         =       Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""      )
							return image



@require_torch
@require_vision
class _lowercase	(				unittest.TestCase		):




							@cached_property
							def 		lowerCamelCase_				(							self:				Optional[int]     ):
														return (
														    MobileNetVaImageProcessor.from_pretrained("""google/mobilenet_v1_1.0_224"""     ) if is_vision_available() else None
														)




							@slow
							def 		lowerCamelCase_				(							self:				Dict     ):
														lowerCamelCase__					:	List[Any]         =       MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v1_1.0_224"""     ).to(UpperCamelCase__     )

														lowerCamelCase__					:	Dict         =       self.default_image_processor
														lowerCamelCase__					:	int         =       prepare_img()
														lowerCamelCase__					:	List[Any]         =       image_processor(images=UpperCamelCase__			,							return_tensors="""pt"""     ).to(UpperCamelCase__     )

														# forward pass
														with torch.no_grad():
																					lowerCamelCase__					:	str         =       model(**UpperCamelCase__     )

														# verify the logits
														lowerCamelCase__					:	List[str]         =       torch.Size((1, 1_001)     )
														self.assertEqual(outputs.logits.shape			,							UpperCamelCase__     )

														lowerCamelCase__					:	List[str]         =       torch.tensor([-4.1_739, -1.1_233, 3.1_205]     ).to(UpperCamelCase__     )

														self.assertTrue(torch.allclose(outputs.logits[0, :3]			,							UpperCamelCase__			,							atol=1e-4     )     )

