


'''simple docstring'''


import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin







@skip_mps
class        __magic_name__  (					lowerCAmelCase						,		lowerCAmelCase						,		unittest.TestCase   ):

     """simple docstring"""






     lowerCamelCase__						=							IFImgaImgPipeline
     lowerCamelCase__						=							TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
     lowerCamelCase__						=							TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
     lowerCamelCase__						=							PipelineTesterMixin.required_optional_params - {'latents'}


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          return self._get_dummy_components()


     def lowerCAmelCase__     (      self ,    lowerCamelCase ,    lowerCamelCase=0		):


          '''simple docstring'''





          if str(lowerCamelCase		).startswith("mps"		):
               __A  :					Optional[Any]						     =       torch.manual_seed(lowerCamelCase		)
          else:
               __A  :					Union[str, Any]						     =       torch.Generator(device=lowerCamelCase		).manual_seed(lowerCamelCase		)

          __A  :					Any						     =       floats_tensor((1, 3, 32, 32) ,    rng=random.Random(lowerCamelCase		)		).to(lowerCamelCase		)

          __A  :					Any						     =       {
              "prompt": "A painting of a squirrel eating a burger",
              "image": image,
              "generator": generator,
              "num_inference_steps": 2,
              "output_type": "numpy",
          }

          return inputs


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_save_load_optional_components()


     @unittest.skipIf(
         torch_device != "cuda" or not is_xformers_available() ,    reason="XFormers attention is only available with CUDA and `xformers` installed" ,    )
     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3		)


     @unittest.skipIf(torch_device != "cuda" ,    reason="float16 requires CUDA"		)
     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          super().test_save_load_floataa(expected_max_diff=1E-1		)


     @unittest.skipIf(torch_device != "cuda" ,    reason="float16 requires CUDA"		)
     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          super().test_floataa_inference(expected_max_diff=1E-1		)


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_attention_slicing_forward_pass(expected_max_diff=1E-2		)


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_save_load_local()


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          self._test_inference_batch_single_identical(
              expected_max_diff=1E-2 ,    )





'''simple docstring'''


from sklearn.metrics import accuracy_score

import datasets


_UpperCamelCase          =     """
Accuracy is the proportion of correct predictions among the total number of cases processed. It can be computed with:
Accuracy = (TP + TN) / (TP + TN + FP + FN)
 Where:
TP: True positive
TN: True negative
FP: False positive
FN: False negative
"""


_UpperCamelCase          =     """
Args:
    predictions (`list` of `int`): Predicted labels.
    references (`list` of `int`): Ground truth labels.
    normalize (`boolean`): If set to False, returns the number of correctly classified samples. Otherwise, returns the fraction of correctly classified samples. Defaults to True.
    sample_weight (`list` of `float`): Sample weights Defaults to None.

Returns:
    accuracy (`float` or `int`): Accuracy score. Minimum possible value is 0. Maximum possible value is 1.0, or the number of examples input, if `normalize` is set to `True`.. A higher score means higher accuracy.

Examples:

    Example 1-A simple example
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0])
        >>> print(results)
        {'accuracy': 0.5}

    Example 2-The same as Example 1, except with `normalize` set to `False`.
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], normalize=False)
        >>> print(results)
        {'accuracy': 3.0}

    Example 3-The same as Example 1, except with `sample_weight` set.
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], sample_weight=[0.5, 2, 0.7, 0.5, 9, 0.4])
        >>> print(results)
        {'accuracy': 0.8778625954198473}
"""


_UpperCamelCase          =     """
@article{scikit-learn,
  title={Scikit-learn: Machine Learning in {P}ython},
  author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
  journal={Journal of Machine Learning Research},
  volume={12},
  pages={2825--2830},
  year={2011}
}
"""







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

     """simple docstring"""






     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          return datasets.MetricInfo(
              description=_DESCRIPTION ,    citation=_CITATION ,    inputs_description=_KWARGS_DESCRIPTION ,    features=datasets.Features(
                  {
                      "predictions": datasets.Sequence(datasets.Value("int32"		)		),
                      "references": datasets.Sequence(datasets.Value("int32"		)		),
                  }
                  if self.config_name == "multilabel"
                  else {
                      "predictions": datasets.Value("int32"		),
                      "references": datasets.Value("int32"		),
                  }		) ,    reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html"] ,    )


     def lowerCAmelCase__     (      self ,    lowerCamelCase ,    lowerCamelCase ,    lowerCamelCase=True ,    lowerCamelCase=None		):


          '''simple docstring'''





          return {
              "accuracy": float(
                  accuracy_score(lowerCamelCase ,    lowerCamelCase ,    normalize=lowerCamelCase ,    sample_weight=lowerCamelCase		)		)
          }

