




from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import (
    BaseOutput,
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_onnx_available,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)

@dataclass
class     __a(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = 42
    lowerCAmelCase         = 42


try:
     if not (is_transformers_available() and is_torch_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
     from .pipeline_cycle_diffusion import CycleDiffusionPipeline
     from .pipeline_stable_diffusion import StableDiffusionPipeline
     from .pipeline_stable_diffusion_attend_and_excite import StableDiffusionAttendAndExcitePipeline
     from .pipeline_stable_diffusion_imgaimg import StableDiffusionImgaImgPipeline
     from .pipeline_stable_diffusion_inpaint import StableDiffusionInpaintPipeline
     from .pipeline_stable_diffusion_inpaint_legacy import StableDiffusionInpaintPipelineLegacy
     from .pipeline_stable_diffusion_instruct_pixapix import StableDiffusionInstructPixaPixPipeline
     from .pipeline_stable_diffusion_latent_upscale import StableDiffusionLatentUpscalePipeline
     from .pipeline_stable_diffusion_ldmad import StableDiffusionLDMaDPipeline
     from .pipeline_stable_diffusion_model_editing import StableDiffusionModelEditingPipeline
     from .pipeline_stable_diffusion_panorama import StableDiffusionPanoramaPipeline
     from .pipeline_stable_diffusion_paradigms import StableDiffusionParadigmsPipeline
     from .pipeline_stable_diffusion_sag import StableDiffusionSAGPipeline
     from .pipeline_stable_diffusion_upscale import StableDiffusionUpscalePipeline
     from .pipeline_stable_unclip import StableUnCLIPPipeline
     from .pipeline_stable_unclip_imgaimg import StableUnCLIPImgaImgPipeline
     from .safety_checker import StableDiffusionSafetyChecker
     from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer

try:
     if not (is_transformers_available() and is_torch_available() and is_transformers_version('>=', '4.25.0')):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from ...utils.dummy_torch_and_transformers_objects import StableDiffusionImageVariationPipeline
else:
     from .pipeline_stable_diffusion_image_variation import StableDiffusionImageVariationPipeline


try:
     if not (is_transformers_available() and is_torch_available() and is_transformers_version('>=', '4.26.0')):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from ...utils.dummy_torch_and_transformers_objects import (
         StableDiffusionDepthaImgPipeline,
         StableDiffusionDiffEditPipeline,
         StableDiffusionPixaPixZeroPipeline,
     )
else:
     from .pipeline_stable_diffusion_depthaimg import StableDiffusionDepthaImgPipeline
     from .pipeline_stable_diffusion_diffedit import StableDiffusionDiffEditPipeline
     from .pipeline_stable_diffusion_pixapix_zero import StableDiffusionPixaPixZeroPipeline


try:
     if not (
         is_torch_available()
         and is_transformers_available()
         and is_k_diffusion_available()
         and is_k_diffusion_version('>=', '0.0.12')
     ):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from ...utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
     from .pipeline_stable_diffusion_k_diffusion import StableDiffusionKDiffusionPipeline

try:
     if not (is_transformers_available() and is_onnx_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from ...utils.dummy_onnx_objects import *  # noqa F403
else:
     from .pipeline_onnx_stable_diffusion import OnnxStableDiffusionPipeline, StableDiffusionOnnxPipeline
     from .pipeline_onnx_stable_diffusion_imgaimg import OnnxStableDiffusionImgaImgPipeline
     from .pipeline_onnx_stable_diffusion_inpaint import OnnxStableDiffusionInpaintPipeline
     from .pipeline_onnx_stable_diffusion_inpaint_legacy import OnnxStableDiffusionInpaintPipelineLegacy
     from .pipeline_onnx_stable_diffusion_upscale import OnnxStableDiffusionUpscalePipeline

if is_transformers_available() and is_flax_available():
     import flax

     @flax.struct.dataclass
     class     __a(	_a  ):






         """simple docstring"""





         lowerCAmelCase         = 42
         lowerCAmelCase         = 42


     from ...schedulers.scheduling_pndm_flax import PNDMSchedulerState
     from .pipeline_flax_stable_diffusion import FlaxStableDiffusionPipeline
     from .pipeline_flax_stable_diffusion_imgaimg import FlaxStableDiffusionImgaImgPipeline
     from .pipeline_flax_stable_diffusion_inpaint import FlaxStableDiffusionInpaintPipeline
     from .safety_checker_flax import FlaxStableDiffusionSafetyChecker





import unittest

import numpy as np







def lowerCamelCase__  (     _lowercase					,		_lowercase					,		_lowercase					,		_lowercase = None					,		):

     '''simple docstring'''


     UpperCAmelCase_     :				Dict  =     np.shape(_lowercase )
     UpperCAmelCase_     :				Optional[Any]  =     np.shape(_lowercase )
     UpperCAmelCase_     :				Tuple  =     np.shape(_lowercase )

     if shape_a[0] != shape_b[0]:
          UpperCAmelCase_     :				Tuple  =     (
              '''Expected the same number of rows for A and B. '''
              f'''Instead found A of size {shape_a} and B of size {shape_b}'''
          )
          raise ValueError(_lowercase )

     if shape_b[1] != shape_c[1]:
          UpperCAmelCase_     :				List[Any]  =     (
              '''Expected the same number of columns for B and C. '''
              f'''Instead found B of size {shape_b} and C of size {shape_c}'''
          )
          raise ValueError(_lowercase )

     UpperCAmelCase_     :				Dict  =     pseudo_inv
     if a_inv is None:
          try:
               UpperCAmelCase_     :				Any  =     np.linalg.inv(_lowercase )
          except np.linalg.LinAlgError:
               raise ValueError(
                   '''Input matrix A is not invertible. Cannot compute Schur complement.''' )

     return mat_c - mat_b.T @ a_inv @ mat_b

class     __a(	unittest.TestCase  ):






    """simple docstring"""





    def 				a__ ( self    )					->						None:
         UpperCAmelCase_     :				str  =     np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]    )
         UpperCAmelCase_     :				Any  =     np.array([[0, 3], [3, 0], [2, 3]]    )
         UpperCAmelCase_     :				List[str]  =     np.array([[2, 1], [6, 3]]    )

         UpperCAmelCase_     :				Tuple  =     schur_complement(_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_     :				List[Any]  =     np.block([[a, b], [b.T, c]]    )

         UpperCAmelCase_     :				List[Any]  =     np.linalg.det(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				List[Any]  =     np.linalg.det(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Any  =     np.linalg.det(_SCREAMING_SNAKE_CASE    )

         self.assertAlmostEqual(_SCREAMING_SNAKE_CASE  ,det_a * det_s    )





    def 				a__ ( self    )					->						None:
         UpperCAmelCase_     :				str  =     np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]    )
         UpperCAmelCase_     :				Optional[int]  =     np.array([[0, 3], [3, 0], [2, 3]]    )
         UpperCAmelCase_     :				Optional[int]  =     np.array([[2, 1], [6, 3]]    )

         with self.assertRaises(_SCREAMING_SNAKE_CASE    ):
              schur_complement(_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE    )





    def 				a__ ( self    )					->						None:
         UpperCAmelCase_     :				Optional[int]  =     np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]    )
         UpperCAmelCase_     :				Optional[Any]  =     np.array([[0, 3], [3, 0], [2, 3]]    )
         UpperCAmelCase_     :				int  =     np.array([[2, 1, 3], [6, 3, 5]]    )

         with self.assertRaises(_SCREAMING_SNAKE_CASE    ):
              schur_complement(_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE    )


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     unittest.main()