





'''simple docstring'''

import random
import unittest

import torch

from diffusers import IFInpaintingPipeline
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_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin






@skip_mps
class        UpperCAmelCase     (	__lowerCamelCase      ,	__lowerCamelCase      ,	unittest.TestCase    ):
 __lowercase       		=    IFInpaintingPipeline
 __lowercase       		=    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {'width', 'height'}
 __lowercase       		=    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
 __lowercase       		=    PipelineTesterMixin.required_optional_params - {'latents'}
 def 					UpperCAmelCase_							(    self				:List[str]							)->							Union[str, Any]:
     return self._get_dummy_components()
 def 					UpperCAmelCase_							(    self				:int						,	lowercase_				:Dict						,	lowercase_				:str=0							)->							List[Any]:
     if str(UpperCamelCase_							).startswith("mps"							):
         A__    =      torch.manual_seed(UpperCamelCase_							)
     else:
         A__    =      torch.Generator(device=UpperCamelCase_							).manual_seed(UpperCamelCase_							)

     A__    =      floats_tensor((1, 3, 32, 32)						,	rng=random.Random(UpperCamelCase_							)							).to(UpperCamelCase_							)
     A__    =      floats_tensor((1, 3, 32, 32)						,	rng=random.Random(UpperCamelCase_							)							).to(UpperCamelCase_							)

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

     return inputs
 @unittest.skipIf(
     torch_device != "cuda" or not is_xformers_available()						,	reason="XFormers attention is only available with CUDA and `xformers` installed"						,	)
 def 					UpperCAmelCase_							(    self				:Union[str, Any]							)->							int:
     self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3							)
 def 					UpperCAmelCase_							(    self				:Union[str, Any]							)->							str:
     self._test_save_load_optional_components()
 @unittest.skipIf(torch_device != "cuda"						,	reason="float16 requires CUDA"							)
 def 					UpperCAmelCase_							(    self				:Optional[int]							)->							Dict:
     # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
     super().test_save_load_floataa(expected_max_diff=1E-1							)
 def 					UpperCAmelCase_							(    self				:Any							)->							Union[str, Any]:
     self._test_attention_slicing_forward_pass(expected_max_diff=1E-2							)
 def 					UpperCAmelCase_							(    self				:str							)->							List[str]:
     self._test_save_load_local()



 def 					UpperCAmelCase_							(    self				:str							)->							Any:
     self._test_inference_batch_single_identical(
         expected_max_diff=1E-2						,	)










'''simple docstring'''

import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812





def 						UpperCamelCase    (							):
    print("Making key files..."	)
    make_key_files("rsa"						,	10_24	)
    print("Key files generation successful."	)





def 						UpperCamelCase    (							_lowerCamelCase : int	):
    print("Generating prime p..."	)
    A__    =      rabinMiller.generate_large_prime(_lowerCamelCase	)
    print("Generating prime q..."	)
    A__    =      rabinMiller.generate_large_prime(_lowerCamelCase	)
    A__    =      p * q

    print("Generating e that is relatively prime to (p - 1) * (q - 1)..."	)
    while True:
        A__    =      random.randrange(2 ** (key_size - 1)						,	2 ** (key_size)	)
        if cryptoMath.gcd(_lowerCamelCase						,	(p - 1) * (q - 1)	) == 1:
            break

    print("Calculating d that is mod inverse of e..."	)
    A__    =      cryptoMath.find_mod_inverse(_lowerCamelCase						,	(p - 1) * (q - 1)	)

    A__    =      (n, e)
    A__    =      (n, d)
    return (public_key, private_key)





def 						UpperCamelCase    (							_lowerCamelCase : str						,	_lowerCamelCase : int	):
    if os.path.exists(F"{name}_pubkey.txt"	) or os.path.exists(F"{name}_privkey.txt"	):
        print("\nWARNING:"	)
        print(
            F"\"{name}_pubkey.txt\" or \"{name}_privkey.txt\" already exists. \n"
            "Use a different name or delete these files and re-run this program."	)
        sys.exit()

    A__,     A__    =      generate_key(_lowerCamelCase	)
    print(F"\nWriting public key to file {name}_pubkey.txt..."	)
    with open(F"{name}_pubkey.txt"						,	"w"	) as out_file:
        out_file.write(F"{key_size},{public_key[0]},{public_key[1]}"	)

    print(F"Writing private key to file {name}_privkey.txt..."	)
    with open(F"{name}_privkey.txt"						,	"w"	) as out_file:
        out_file.write(F"{key_size},{private_key[0]},{private_key[1]}"	)


if __name__ == "__main__":
  main()



