code: import logging
  
  # standard libraries
  import sys
  
  import numpy as np
  import pytest  # type: ignore
  
  # Custom/local libraries
  from matrix import matrix_operation as matop
  
  A_:      List[Any]        =			[[12, 10], [3, 9]]
  A_:      Any        =			[[3, 4], [7, 4]]
  A_:      List[Any]        =			[[3, 0, 2], [2, 0, -2], [0, 1, 1]]
  A_:      int        =			[[3, 0, -2], [2, 0, 2], [0, 1, 1]]
  A_:      List[str]        =			[[3, 0, 2], [2, 0, -2], [0, 1, 1], [2, 0, -2]]
  A_:      List[str]        =			[1]
  A_:      Dict        =			[2]
  
  A_:      Optional[Any]        =			logging.getLogger()
  A_:      str        =			logging.DEBUG
  A_:      Union[str, Any]        =			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 					__lowerCAmelCase			(  _A ,_A					):
  
  
  
  							"""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'''					)
  														_lowercase				=	(np.array(__lowerCamelCase					) + np.array(__lowerCamelCase					)).tolist()
  														_lowercase				=	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 					__lowerCAmelCase			(  _A ,_A					):
  
  
  
  							"""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'''					)
  														_lowercase				=	(np.array(__lowerCamelCase					) - np.array(__lowerCamelCase					)).tolist()
  														_lowercase				=	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 					__lowerCAmelCase			(  _A ,_A					):
  
  
  
  							"""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'''					)
  														_lowercase				=	(np.matmul(__lowerCamelCase ,__lowerCamelCase					)).tolist()
  														_lowercase				=	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 					__lowerCAmelCase			(  ):
  
  
  
  							"""simple docstring"""
  
  
  							_lowercase				=	(3.5 * np.array(__lowerCamelCase					)).tolist()
  							_lowercase				=	matop.scalar_multiply(__lowerCamelCase ,3.5					)
  							assert theo == act
  
  
  @pytest.mark.mat_ops
  def 					__lowerCAmelCase			(  ):
  
  
  
  							"""simple docstring"""
  
  
  							_lowercase				=	(np.identity(5					)).tolist()
  							_lowercase				=	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 					__lowerCAmelCase			(  _A					):
  
  
  
  							"""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:
  														_lowercase				=	(np.transpose(__lowerCamelCase					)).tolist()
  														_lowercase				=	matop.transpose(__lowerCamelCase ,return_map=__lowerCamelCase					)
  														assert theo == act
  
  
  
style_context: import shutil
  import tempfile
  import unittest
  
  import numpy as np
  import pytest
  
  from transformers.testing_utils import require_vision
  from transformers.utils import is_vision_available
  
  
  if is_vision_available():
  				from PIL import Image
  
  				from transformers import AutoProcessor, BertTokenizer, CLIPImageProcessor, GitProcessor, PreTrainedTokenizerFast
  
  
  @require_vision
  class _lowercase					(       unittest.TestCase						):
  
  
  
  
  
  							"""simple docstring"""
  
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														_lowercase				=	tempfile.mkdtemp()
  
  														_lowercase				=	CLIPImageProcessor()
  														_lowercase				=	BertTokenizer.from_pretrained(
  														    """hf-internal-testing/tiny-random-BertModel"""     ,   model_input_names=["""input_ids""", """attention_mask"""]  )
  
  														_lowercase				=	GitProcessor(UpperCAmelCase     ,   UpperCAmelCase  )
  
  														processor.save_pretrained(self.tmpdirname  )
  
  
  
  							def     _UpperCAmelCase       (    self     ,   **UpperCAmelCase  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														return AutoProcessor.from_pretrained(self.tmpdirname     ,   **UpperCAmelCase  ).tokenizer
  
  
  
  							def     _UpperCAmelCase       (    self     ,   **UpperCAmelCase  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														return AutoProcessor.from_pretrained(self.tmpdirname     ,   **UpperCAmelCase  ).image_processor
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														shutil.rmtree(self.tmpdirname  )
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														_lowercase				=	[np.random.randint(255     ,   size=(3, 30, 400)     ,   dtype=np.uinta  )]
  
  														_lowercase				=	[Image.fromarray(np.moveaxis(UpperCAmelCase     ,   0     ,   -1  )  ) for x in image_inputs]
  
  														return image_inputs
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														_lowercase				=	GitProcessor(tokenizer=self.get_tokenizer()     ,   image_processor=self.get_image_processor()  )
  														processor.save_pretrained(self.tmpdirname  )
  
  														_lowercase				=	self.get_tokenizer(bos_token="""(BOS)"""     ,   eos_token="""(EOS)"""  )
  														_lowercase				=	self.get_image_processor(do_normalize=UpperCAmelCase     ,   padding_value=1.0  )
  
  														_lowercase				=	GitProcessor.from_pretrained(
  														    self.tmpdirname     ,   bos_token="""(BOS)"""     ,   eos_token="""(EOS)"""     ,   do_normalize=UpperCAmelCase     ,   padding_value=1.0  )
  
  														self.assertEqual(processor.tokenizer.get_vocab()     ,   tokenizer_add_kwargs.get_vocab()  )
  														self.assertIsInstance(processor.tokenizer     ,   UpperCAmelCase  )
  
  														self.assertEqual(processor.image_processor.to_json_string()     ,   image_processor_add_kwargs.to_json_string()  )
  														self.assertIsInstance(processor.image_processor     ,   UpperCAmelCase  )
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														_lowercase				=	self.get_image_processor()
  														_lowercase				=	self.get_tokenizer()
  
  														_lowercase				=	GitProcessor(tokenizer=UpperCAmelCase     ,   image_processor=UpperCAmelCase  )
  
  														_lowercase				=	self.prepare_image_inputs()
  
  														_lowercase				=	image_processor(UpperCAmelCase     ,   return_tensors="""np"""  )
  														_lowercase				=	processor(images=UpperCAmelCase     ,   return_tensors="""np"""  )
  
  														for key in input_feat_extract.keys():
  																					self.assertAlmostEqual(input_feat_extract[key].sum()     ,   input_processor[key].sum()     ,   delta=1e-2  )
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														_lowercase				=	self.get_image_processor()
  														_lowercase				=	self.get_tokenizer()
  
  														_lowercase				=	GitProcessor(tokenizer=UpperCAmelCase     ,   image_processor=UpperCAmelCase  )
  
  														_lowercase				=	"""lower newer"""
  
  														_lowercase				=	processor(text=UpperCAmelCase  )
  
  														_lowercase				=	tokenizer(UpperCAmelCase     ,   return_token_type_ids=UpperCAmelCase  )
  
  														for key in encoded_tok.keys():
  																					self.assertListEqual(encoded_tok[key]     ,   encoded_processor[key]  )
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														_lowercase				=	self.get_image_processor()
  														_lowercase				=	self.get_tokenizer()
  
  														_lowercase				=	GitProcessor(tokenizer=UpperCAmelCase     ,   image_processor=UpperCAmelCase  )
  
  														_lowercase				=	"""lower newer"""
  														_lowercase				=	self.prepare_image_inputs()
  
  														_lowercase				=	processor(text=UpperCAmelCase     ,   images=UpperCAmelCase  )
  
  														self.assertListEqual(list(inputs.keys()  )     ,   ["""input_ids""", """attention_mask""", """pixel_values"""]  )
  
  														# test if it raises when no input is passed
  														with pytest.raises(UpperCAmelCase  ):
  																					processor()
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														_lowercase				=	self.get_image_processor()
  														_lowercase				=	self.get_tokenizer()
  
  														_lowercase				=	GitProcessor(tokenizer=UpperCAmelCase     ,   image_processor=UpperCAmelCase  )
  
  														_lowercase				=	[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
  														_lowercase				=	processor.batch_decode(UpperCAmelCase  )
  														_lowercase				=	tokenizer.batch_decode(UpperCAmelCase  )
  
  														self.assertListEqual(UpperCAmelCase     ,   UpperCAmelCase  )
  
  
  
  							def     _UpperCAmelCase       (    self  ):
  
  
  
  
  
  
  
  														'''simple docstring'''
  
  
  
  
  
  
  														_lowercase				=	self.get_image_processor()
  														_lowercase				=	self.get_tokenizer()
  
  														_lowercase				=	GitProcessor(tokenizer=UpperCAmelCase     ,   image_processor=UpperCAmelCase  )
  
  														_lowercase				=	"""lower newer"""
  														_lowercase				=	self.prepare_image_inputs()
  
  														_lowercase				=	processor(text=UpperCAmelCase     ,   images=UpperCAmelCase  )
  
  														# For now the processor supports only ['input_ids', 'attention_mask', 'pixel_values']
  														self.assertListEqual(list(inputs.keys()  )     ,   ["""input_ids""", """attention_mask""", """pixel_values"""]  )
  
  
  