




'''simple docstring'''




import logging

# standard libraries
import sys

import numpy as np
import pytest  # type: ignore

# Custom/local libraries
from matrix import matrix_operation as matop

UpperCAmelCase_       				=      [[1_2, 1_0], [3, 9]]
UpperCAmelCase_       				=      [[3, 4], [7, 4]]
UpperCAmelCase_       				=      [[3, 0, 2], [2, 0, -2], [0, 1, 1]]
UpperCAmelCase_       				=      [[3, 0, -2], [2, 0, 2], [0, 1, 1]]
UpperCAmelCase_       				=      [[3, 0, 2], [2, 0, -2], [0, 1, 1], [2, 0, -2]]
UpperCAmelCase_       				=      [1]
UpperCAmelCase_       				=      [2]

UpperCAmelCase_       				=      logging.getLogger()
UpperCAmelCase_       				=      logging.DEBUG
UpperCAmelCase_       				=      logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)

@pytest.mark.mat_ops
@pytest.mark.parametrize(
    ("""mat1""", """mat2""")       ,						[(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]       )
def    _UpperCamelCase      (				SCREAMING_SNAKE_CASE__			:      Optional[int]       ,						SCREAMING_SNAKE_CASE__			:      Tuple       ):
	'''simple docstring'''





	if (np.array(__lowerCamelCase       )).shape < (2, 2) or (np.array(__lowerCamelCase       )).shape < (2, 2):
		with pytest.raises(__lowerCamelCase       ):
			logger.info(F'''\n\t{test_addition.__name__} returned integer'''       )
			matop.add(__lowerCamelCase       ,						__lowerCamelCase       )
	elif (np.array(__lowerCamelCase       )).shape == (np.array(__lowerCamelCase       )).shape:
		logger.info(F'''\n\t{test_addition.__name__} with same matrix dims'''       )
		UpperCAmelCase__										=    (np.array(__lowerCamelCase       ) + np.array(__lowerCamelCase       )).tolist()
		UpperCAmelCase__										=    matop.add(__lowerCamelCase       ,						__lowerCamelCase       )
		assert theo == act
	else:
		with pytest.raises(__lowerCamelCase       ):
			logger.info(F'''\n\t{test_addition.__name__} with different matrix dims'''       )
			matop.add(__lowerCamelCase       ,						__lowerCamelCase       )

@pytest.mark.mat_ops
@pytest.mark.parametrize(
    ("""mat1""", """mat2""")       ,						[(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]       )
def    _UpperCamelCase      (				SCREAMING_SNAKE_CASE__			:      Tuple       ,						SCREAMING_SNAKE_CASE__			:      Union[str, Any]       ):
	'''simple docstring'''





	if (np.array(__lowerCamelCase       )).shape < (2, 2) or (np.array(__lowerCamelCase       )).shape < (2, 2):
		with pytest.raises(__lowerCamelCase       ):
			logger.info(F'''\n\t{test_subtraction.__name__} returned integer'''       )
			matop.subtract(__lowerCamelCase       ,						__lowerCamelCase       )
	elif (np.array(__lowerCamelCase       )).shape == (np.array(__lowerCamelCase       )).shape:
		logger.info(F'''\n\t{test_subtraction.__name__} with same matrix dims'''       )
		UpperCAmelCase__										=    (np.array(__lowerCamelCase       ) - np.array(__lowerCamelCase       )).tolist()
		UpperCAmelCase__										=    matop.subtract(__lowerCamelCase       ,						__lowerCamelCase       )
		assert theo == act
	else:
		with pytest.raises(__lowerCamelCase       ):
			logger.info(F'''\n\t{test_subtraction.__name__} with different matrix dims'''       )
			assert matop.subtract(__lowerCamelCase       ,						__lowerCamelCase       )

@pytest.mark.mat_ops
@pytest.mark.parametrize(
    ("""mat1""", """mat2""")       ,						[(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]       )
def    _UpperCamelCase      (				SCREAMING_SNAKE_CASE__			:      Tuple       ,						SCREAMING_SNAKE_CASE__			:      List[str]       ):
	'''simple docstring'''





	if (np.array(__lowerCamelCase       )).shape < (2, 2) or (np.array(__lowerCamelCase       )).shape < (2, 2):
		logger.info(F'''\n\t{test_multiplication.__name__} returned integer'''       )
		with pytest.raises(__lowerCamelCase       ):
			matop.add(__lowerCamelCase       ,						__lowerCamelCase       )
	elif (np.array(__lowerCamelCase       )).shape == (np.array(__lowerCamelCase       )).shape:
		logger.info(F'''\n\t{test_multiplication.__name__} meets dim requirements'''       )
		UpperCAmelCase__										=    (np.matmul(__lowerCamelCase       ,						__lowerCamelCase       )).tolist()
		UpperCAmelCase__										=    matop.multiply(__lowerCamelCase       ,						__lowerCamelCase       )
		assert theo == act
	else:
		with pytest.raises(__lowerCamelCase       ):
			logger.info(
			    F'''\n\t{test_multiplication.__name__} does not meet dim requirements'''       )
			assert matop.subtract(__lowerCamelCase       ,						__lowerCamelCase       )

@pytest.mark.mat_ops
def    _UpperCamelCase      (				):
	'''simple docstring'''





	UpperCAmelCase__										=    (3.5 * np.array(__lowerCamelCase       )).tolist()
	UpperCAmelCase__										=    matop.scalar_multiply(__lowerCamelCase       ,						3.5       )
	assert theo == act

@pytest.mark.mat_ops
def    _UpperCamelCase      (				):
	'''simple docstring'''





	UpperCAmelCase__										=    (np.identity(5       )).tolist()
	UpperCAmelCase__										=    matop.identity(5       )
	assert theo == act







@pytest.mark.mat_ops
@pytest.mark.parametrize("""mat"""       ,						[mat_a, mat_b, mat_c, mat_d, mat_e, mat_f]       )
def    _UpperCamelCase      (				SCREAMING_SNAKE_CASE__			:      Tuple       ):
	'''simple docstring'''





	if (np.array(__lowerCamelCase       )).shape < (2, 2):
		with pytest.raises(__lowerCamelCase       ):
			logger.info(F'''\n\t{test_transpose.__name__} returned integer'''       )
			matop.transpose(__lowerCamelCase       )
	else:
		UpperCAmelCase__										=    (np.transpose(__lowerCamelCase       )).tolist()
		UpperCAmelCase__										=    matop.transpose(__lowerCamelCase       ,						return_map=__lowerCamelCase       )
		assert theo == act






'''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 						lowerCAmelCase_   ( lowerCamelCase_			,  lowerCamelCase_			,  unittest.TestCase   ):







  '''simple docstring'''







  lowerCAmelCase_				:					Any				     =						IFImgaImgPipeline
  lowerCAmelCase_				:					Dict				     =						TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
  lowerCAmelCase_				:					Union[str, Any]				     =						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
  lowerCAmelCase_				:					Dict				     =						PipelineTesterMixin.required_optional_params - {"""latents"""}


  def 							SCREAMING_SNAKE_CASE__			(						self    :	Optional[int] ):






   """simple docstring"""






   return self._get_dummy_components()


  def 							SCREAMING_SNAKE_CASE__			(						self    :	Tuple						,		_UpperCAmelCase    :	Any						,		_UpperCAmelCase    :	Any=0 ):






   """simple docstring"""






   if str(_UpperCAmelCase ).startswith("""mps""" ):
    UpperCAmelCase__										=    torch.manual_seed(_UpperCAmelCase )
   else:
    UpperCAmelCase__										=    torch.Generator(device=_UpperCAmelCase ).manual_seed(_UpperCAmelCase )

   UpperCAmelCase__										=    floats_tensor((1, 3, 32, 32)						,		rng=random.Random(_UpperCAmelCase ) ).to(_UpperCAmelCase )

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

   return inputs


  def 							SCREAMING_SNAKE_CASE__			(						self    :	List[Any] ):






   """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 							SCREAMING_SNAKE_CASE__			(						self    :	int ):






   """simple docstring"""






   self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3 )


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






   """simple docstring"""






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


  @unittest.skipIf(torch_device != """cuda"""						,		reason="""float16 requires CUDA""" )
  def 							SCREAMING_SNAKE_CASE__			(						self    :	Optional[int] ):






   """simple docstring"""






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


  def 							SCREAMING_SNAKE_CASE__			(						self    :	List[str] ):






   """simple docstring"""






   self._test_attention_slicing_forward_pass(expected_max_diff=1E-2 )


  def 							SCREAMING_SNAKE_CASE__			(						self    :	int ):






   """simple docstring"""






   self._test_save_load_local()



  def 							SCREAMING_SNAKE_CASE__			(						self    :	Any ):






   """simple docstring"""






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