





import os
import sys
import unittest


_lowerCAmelCase 				=     os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, """utils"""))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
_lowerCAmelCase 				=     os.path.join(git_repo_path, """src""", """diffusers""")

class    _UpperCAmelCase							(		unittest.TestCase     ):
      def 		_lowerCamelCase      (		self       ):
         A_     :				int			      =	find_backend("""    if not is_torch_available():"""       )
         self.assertEqual(a__      ,       """torch"""       )

         # backend_with_underscore = find_backend("    if not is_tensorflow_text_available():")
         # self.assertEqual(backend_with_underscore, "tensorflow_text")

         A_     :				str			      =	find_backend("""    if not (is_torch_available() and is_transformers_available()):"""       )
         self.assertEqual(a__      ,       """torch_and_transformers"""       )

         # double_backend_with_underscore = find_backend(
         #    "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"
         # )
         # self.assertEqual(double_backend_with_underscore, "sentencepiece_and_tensorflow_text")

         A_     :				Union[str, Any]			      =	find_backend(
             """    if not (is_torch_available() and is_transformers_available() and is_onnx_available()):"""       )
         self.assertEqual(a__      ,       """torch_and_transformers_and_onnx"""       )
      def 		_lowerCamelCase      (		self       ):
         A_     :				Any			      =	read_init()
         # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
         self.assertIn("""torch"""      ,       a__       )
         self.assertIn("""torch_and_transformers"""      ,       a__       )
         self.assertIn("""flax_and_transformers"""      ,       a__       )
         self.assertIn("""torch_and_transformers_and_onnx"""      ,       a__       )

         # Likewise, we can't assert on the exact content of a key
         self.assertIn("""UNet2DModel"""      ,       objects["""torch"""]       )
         self.assertIn("""FlaxUNet2DConditionModel"""      ,       objects["""flax"""]       )
         self.assertIn("""StableDiffusionPipeline"""      ,       objects["""torch_and_transformers"""]       )
         self.assertIn("""FlaxStableDiffusionPipeline"""      ,       objects["""flax_and_transformers"""]       )
         self.assertIn("""LMSDiscreteScheduler"""      ,       objects["""torch_and_scipy"""]       )
         self.assertIn("""OnnxStableDiffusionPipeline"""      ,       objects["""torch_and_transformers_and_onnx"""]       )
      def 		_lowerCamelCase      (		self       ):
         A_     :				str			      =	create_dummy_object("""CONSTANT"""      ,       """'torch'"""       )
         self.assertEqual(a__      ,       """\nCONSTANT = None\n"""       )

         A_     :				Tuple			      =	create_dummy_object("""function"""      ,       """'torch'"""       )
         self.assertEqual(
             a__      ,       """\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"""       )

         A_     :				Dict			      =	"""
class FakeClass(metaclass=DummyObject):
    _backends = 'torch'

    def __init__(self, *args, **kwargs):
        requires_backends(self, 'torch')

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, 'torch')

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, 'torch')
"""
         A_     :				Optional[int]			      =	create_dummy_object("""FakeClass"""      ,       """'torch'"""       )
         self.assertEqual(a__      ,       a__       )






      def 		_lowerCamelCase      (		self       ):
         A_     :				Optional[int]			      =	"""# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, [\"torch\"])


class FakeClass(metaclass=DummyObject):
    _backends = [\"torch\"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, [\"torch\"])

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, [\"torch\"])

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, [\"torch\"])
"""
         A_     :				Any			      =	create_dummy_files({"""torch""": ["""CONSTANT""", """function""", """FakeClass"""]}       )
         self.assertEqual(dummy_files["""torch"""]      ,       a__       )










from __future__ import annotations

import numpy as np
from numpy import floataa
from numpy.typing import NDArray



def     _lowerCAmelCase		(  _lowerCAmelCase  ,_lowerCAmelCase  ,_lowerCAmelCase  ,_lowerCAmelCase  ,):
   '''simple docstring'''


   A_      ,				A_     :				int			      =	coefficient_matrix.shape
   A_      ,				A_     :				Tuple			      =	constant_matrix.shape

   if rowsa != colsa:
      A_     :				int			      =	f"""Coefficient matrix dimensions must be nxn but received {rowsa}x{colsa}"""
      raise ValueError(_lowerCAmelCase     )

   if colsa != 1:
      A_     :				List[Any]			      =	f"""Constant matrix must be nx1 but received {rowsa}x{colsa}"""
      raise ValueError(_lowerCAmelCase     )

   if rowsa != rowsa:
      A_     :				str			      =	(
          """Coefficient and constant matrices dimensions must be nxn and nx1 but """
          f"""received {rowsa}x{colsa} and {rowsa}x{colsa}"""
      )
      raise ValueError(_lowerCAmelCase     )

   if len(_lowerCAmelCase     ) != rowsa:
      A_     :				Any			      =	(
          """Number of initial values must be equal to number of rows in coefficient """
          f"""matrix but received {len(_lowerCAmelCase     )} and {rowsa}"""
      )
      raise ValueError(_lowerCAmelCase     )

   if iterations <= 0:
      raise ValueError("""Iterations must be at least 1"""     )

   A_     :				NDArray[floataa]			      =	np.concatenate(
       (coefficient_matrix, constant_matrix)  ,axis=1     )

   A_      ,				A_     :				str			      =	table.shape

   strictly_diagonally_dominant(_lowerCAmelCase     )

   # Iterates the whole matrix for given number of times
   for _ in range(_lowerCAmelCase     ):
      A_     :				Union[str, Any]			      =	[]
      for row in range(_lowerCAmelCase     ):
         A_     :				str			      =	0
         for col in range(_lowerCAmelCase     ):
            if col == row:
               A_     :				Optional[Any]			      =	table[row][col]
            elif col == cols - 1:
               A_     :				List[str]			      =	table[row][col]
            else:
               temp += (-1) * table[row][col] * init_val[col]
         A_     :				str			      =	(temp + val) / denom
         new_val.append(_lowerCAmelCase     )
      A_     :				List[str]			      =	new_val

   return [float(_lowerCAmelCase     ) for i in new_val]



def     _lowerCAmelCase		(  _lowerCAmelCase     ):
   '''simple docstring'''


   A_      ,				A_     :				str			      =	table.shape

   A_     :				Any			      =	True

   for i in range(0  ,_lowerCAmelCase     ):
      A_     :				Optional[Any]			      =	0
      for j in range(0  ,cols - 1     ):
         if i == j:
            continue
         else:
            total += table[i][j]

      if table[i][i] <= total:
         raise ValueError("""Coefficient matrix is not strictly diagonally dominant"""     )

   return is_diagonally_dominant


# Test Cases
if __name__ == "__main__":
      import doctest

      doctest.testmod()






