






'''simple docstring'''







import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_flax_cross_test,
    require_flax,
    require_torch,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import is_flax_available, is_torch_available, is_vision_available

from ...test_modeling_flax_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_flax_bert import FlaxBertModelTester
from ..clip.test_modeling_flax_clip import FlaxCLIPVisionModelTester
from ..vit.test_modeling_flax_vit import FlaxViTModelTester


if is_flax_available():
							from transformers import (
							    FlaxBertModel,
							    FlaxCLIPVisionModel,
							    FlaxVisionTextDualEncoderModel,
							    FlaxViTModel,
							    VisionTextDualEncoderConfig,
							    VisionTextDualEncoderProcessor,
							)
							from transformers.modeling_flax_pytorch_utils import (
							    convert_pytorch_state_dict_to_flax,
							    load_flax_weights_in_pytorch_model,
							)


if is_torch_available():
							import torch

							from transformers import VisionTextDualEncoderModel

if is_vision_available():
							from PIL import Image
def 						A__			(				__lowerCAmelCase		:			int						):
						if isinstance(snake_case_   ,    collections.abc.Iterable						):
												return x
						return (x, x)




@require_flax
class 		UpperCamelCase__    :




		'''simple docstring'''





		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase       ):

								'''simple docstring'''





								pass






		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								pass






		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								pass






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  np.abs((a - b)       ).max()
								self.assertLessEqual(_lowerCAmelCase   ,_lowerCAmelCase   ,F'''Difference between torch and flax is {diff} (>= {tol}).'''       )






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase=None   ,**_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  VisionTextDualEncoderConfig.from_vision_text_configs(_lowerCAmelCase   ,_lowerCAmelCase       )

								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel(_lowerCAmelCase       )

								lowerCamelCase__         =  model(input_ids=_lowerCAmelCase   ,pixel_values=_lowerCAmelCase   ,attention_mask=_lowerCAmelCase       )

								self.assertEqual(output["""text_embeds"""].shape   ,(input_ids.shape[0], config.projection_dim)       )
								self.assertEqual(output["""image_embeds"""].shape   ,(pixel_values.shape[0], config.projection_dim)       )






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase=None   ,**_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.get_vision_text_model(_lowerCAmelCase   ,_lowerCAmelCase       )
								lowerCamelCase__         =  {'''vision_model''': vision_model, '''text_model''': text_model}
								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_lowerCAmelCase       )

								lowerCamelCase__         =  model(input_ids=_lowerCAmelCase   ,pixel_values=_lowerCAmelCase   ,attention_mask=_lowerCAmelCase       )

								self.assertEqual(output["""text_embeds"""].shape   ,(input_ids.shape[0], model.config.projection_dim)       )
								self.assertEqual(output["""image_embeds"""].shape   ,(pixel_values.shape[0], model.config.projection_dim)       )






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase=None   ,**_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.get_vision_text_model(_lowerCAmelCase   ,_lowerCAmelCase       )
								lowerCamelCase__         =  {'''vision_model''': vision_model, '''text_model''': text_model}
								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_lowerCAmelCase       )

								lowerCamelCase__         =  model(input_ids=_lowerCAmelCase   ,pixel_values=_lowerCAmelCase   ,attention_mask=_lowerCAmelCase       )
								lowerCamelCase__         =  output[0]

								with tempfile.TemporaryDirectory() as tmpdirname:
														model.save_pretrained(_lowerCAmelCase       )
														lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase       )

														lowerCamelCase__         =  model(input_ids=_lowerCAmelCase   ,pixel_values=_lowerCAmelCase   ,attention_mask=_lowerCAmelCase       )
														lowerCamelCase__         =  after_output[0]
														lowerCamelCase__         =  np.amax(np.abs(out_a - out_a       )       )
														self.assertLessEqual(_lowerCAmelCase   ,1E-3       )






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase=None   ,**_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.get_vision_text_model(_lowerCAmelCase   ,_lowerCAmelCase       )
								lowerCamelCase__         =  {'''vision_model''': vision_model, '''text_model''': text_model}
								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_lowerCAmelCase       )

								lowerCamelCase__         =  model(
								    input_ids=_lowerCAmelCase   ,pixel_values=_lowerCAmelCase   ,attention_mask=_lowerCAmelCase   ,output_attentions=_lowerCAmelCase       )

								lowerCamelCase__         =  output.vision_model_output.attentions
								self.assertEqual(len(_lowerCAmelCase       )   ,vision_config.num_hidden_layers       )

								# in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
								lowerCamelCase__         =  to_atuple(vision_model.config.image_size       )
								lowerCamelCase__         =  to_atuple(vision_model.config.patch_size       )
								lowerCamelCase__         =  (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
								lowerCamelCase__         =  num_patches + 1
								self.assertEqual(vision_attentions[0].shape[-3:]   ,(vision_config.num_attention_heads, seq_len, seq_len)       )

								lowerCamelCase__         =  output.text_model_output.attentions
								self.assertEqual(len(_lowerCAmelCase       )   ,text_config.num_hidden_layers       )

								self.assertEqual(
								    text_attentions[0].shape[-3:]   ,(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])   ,)






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase       ):

								'''simple docstring'''





								pt_model.to(_lowerCAmelCase       )
								pt_model.eval()

								# prepare inputs
								lowerCamelCase__         =  inputs_dict
								lowerCamelCase__         =  {k: torch.tensor(v.tolist()       ) for k, v in flax_inputs.items()}

								with torch.no_grad():
														lowerCamelCase__         =  pt_model(**_lowerCAmelCase       ).to_tuple()

								lowerCamelCase__         =  fx_model(**_lowerCAmelCase       ).to_tuple()
								self.assertEqual(len(_lowerCAmelCase       )   ,len(_lowerCAmelCase       )   ,"""Output lengths differ between Flax and PyTorch"""       )
								for fx_output, pt_output in zip(fx_outputs[:4]   ,pt_outputs[:4]       ):
														self.assert_almost_equals(_lowerCAmelCase   ,pt_output.numpy()   ,4E-2       )

								# PT -> Flax
								with tempfile.TemporaryDirectory() as tmpdirname:
														pt_model.save_pretrained(_lowerCAmelCase       )
														lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase   ,from_pt=_lowerCAmelCase       )

								lowerCamelCase__         =  fx_model_loaded(**_lowerCAmelCase       ).to_tuple()
								self.assertEqual(len(_lowerCAmelCase       )   ,len(_lowerCAmelCase       )   ,"""Output lengths differ between Flax and PyTorch"""       )
								for fx_output_loaded, pt_output in zip(fx_outputs_loaded[:4]   ,pt_outputs[:4]       ):
														self.assert_almost_equals(_lowerCAmelCase   ,pt_output.numpy()   ,4E-2       )

								# Flax -> PT
								with tempfile.TemporaryDirectory() as tmpdirname:
														fx_model.save_pretrained(_lowerCAmelCase       )
														lowerCamelCase__         =  VisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase   ,from_flax=_lowerCAmelCase       )

								pt_model_loaded.to(_lowerCAmelCase       )
								pt_model_loaded.eval()

								with torch.no_grad():
														lowerCamelCase__         =  pt_model_loaded(**_lowerCAmelCase       ).to_tuple()

								self.assertEqual(len(_lowerCAmelCase       )   ,len(_lowerCAmelCase       )   ,"""Output lengths differ between Flax and PyTorch"""       )
								for fx_output, pt_output_loaded in zip(fx_outputs[:4]   ,pt_outputs_loaded[:4]       ):
														self.assert_almost_equals(_lowerCAmelCase   ,pt_output_loaded.numpy()   ,4E-2       )






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  VisionTextDualEncoderConfig.from_vision_text_configs(_lowerCAmelCase   ,_lowerCAmelCase       )

								lowerCamelCase__         =  VisionTextDualEncoderModel(_lowerCAmelCase       )
								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel(_lowerCAmelCase       )

								lowerCamelCase__         =  convert_pytorch_state_dict_to_flax(pt_model.state_dict()   ,_lowerCAmelCase       )
								lowerCamelCase__         =  fx_state

								self.check_pt_flax_equivalence(_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  VisionTextDualEncoderConfig.from_vision_text_configs(_lowerCAmelCase   ,_lowerCAmelCase       )

								lowerCamelCase__         =  VisionTextDualEncoderModel(_lowerCAmelCase       )
								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel(_lowerCAmelCase       )

								lowerCamelCase__         =  load_flax_weights_in_pytorch_model(_lowerCAmelCase   ,fx_model.params       )

								self.check_pt_flax_equivalence(_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.prepare_config_and_inputs()
								self.check_model_from_pretrained_configs(**_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.prepare_config_and_inputs()
								self.check_vision_text_dual_encoder_from_pretrained(**_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.prepare_config_and_inputs()
								self.check_save_load(**_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.prepare_config_and_inputs()
								self.check_vision_text_output_attention(**_lowerCAmelCase       )






		@is_pt_flax_cross_test
		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.prepare_config_and_inputs()
								lowerCamelCase__         =  config_inputs_dict.pop("""vision_config"""       )
								lowerCamelCase__         =  config_inputs_dict.pop("""text_config"""       )

								lowerCamelCase__         =  config_inputs_dict

								self.check_equivalence_pt_to_flax(_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase       )
								self.check_equivalence_flax_to_pt(_lowerCAmelCase   ,_lowerCAmelCase   ,_lowerCAmelCase       )






		@slow
		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  self.get_pretrained_model_and_inputs()

								lowerCamelCase__         =  model_a(**_lowerCAmelCase       )
								lowerCamelCase__         =  outputs[0]

								with tempfile.TemporaryDirectory() as tmp_dirname:
														model_a.save_pretrained(_lowerCAmelCase       )
														lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase       )

														lowerCamelCase__         =  model_a(**_lowerCAmelCase       )
														lowerCamelCase__         =  after_outputs[0]
														lowerCamelCase__         =  np.amax(np.abs(out_a - out_a       )       )
														self.assertLessEqual(_lowerCAmelCase   ,1E-5       )




@require_flax
class 		UpperCamelCase__    (UpperCamelCase_   ,unittest.TestCase			):




		'''simple docstring'''





		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(
								    """hf-internal-testing/tiny-random-vit"""   ,"""hf-internal-testing/tiny-bert"""   ,vision_from_pt=_lowerCAmelCase   ,text_from_pt=_lowerCAmelCase   ,)
								lowerCamelCase__         =  13
								lowerCamelCase__         =  floats_tensor(
								    [
								        batch_size,
								        model.config.vision_config.num_channels,
								        model.config.vision_config.image_size,
								        model.config.vision_config.image_size,
								    ]       )
								lowerCamelCase__         =  ids_tensor([batch_size, 4]   ,model.config.text_config.vocab_size       )
								lowerCamelCase__         =  random_attention_mask([batch_size, 4]       )
								lowerCamelCase__         =  {'''pixel_values''': pixel_values, '''input_ids''': input_ids, '''attention_mask''': attention_mask}

								return model, inputs






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  FlaxViTModel(_lowerCAmelCase       )
								lowerCamelCase__         =  FlaxBertModel(_lowerCAmelCase       )
								return vision_model, text_model






		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  FlaxViTModelTester(self       )
								lowerCamelCase__         =  FlaxBertModelTester(self       )
								lowerCamelCase__         =  vit_model_tester.prepare_config_and_inputs()
								lowerCamelCase__         =  bert_model_tester.prepare_config_and_inputs()

								lowerCamelCase__         =  vision_config_and_inputs

								lowerCamelCase__         =  text_config_and_inputs

								# make sure that cross attention layers are added
								return {
								    "text_config": text_config,
								    "vision_config": vision_config,
								    "pixel_values": pixel_values,
								    "attention_mask": attention_mask,
								    "input_ids": input_ids,
								    "token_type_ids": token_type_ids,
								}




@require_torch
class 		UpperCamelCase__    (UpperCamelCase_   ,unittest.TestCase			):




		'''simple docstring'''





		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(
								    """hf-internal-testing/tiny-random-clip"""   ,"""hf-internal-testing/tiny-bert"""   ,vision_from_pt=_lowerCAmelCase   ,text_from_pt=_lowerCAmelCase   ,)
								lowerCamelCase__         =  13
								lowerCamelCase__         =  floats_tensor(
								    [
								        batch_size,
								        model.config.vision_config.num_channels,
								        model.config.vision_config.image_size,
								        model.config.vision_config.image_size,
								    ]       )
								lowerCamelCase__         =  ids_tensor([batch_size, 4]   ,model.config.text_config.vocab_size       )
								lowerCamelCase__         =  random_attention_mask([batch_size, 4]       )
								lowerCamelCase__         =  {'''pixel_values''': pixel_values, '''input_ids''': input_ids, '''attention_mask''': attention_mask}

								return model, inputs






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase       ):

								'''simple docstring'''





								lowerCamelCase__         =  FlaxCLIPVisionModel(_lowerCAmelCase       )
								lowerCamelCase__         =  FlaxBertModel(_lowerCAmelCase       )
								return vision_model, text_model






		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  FlaxCLIPVisionModelTester(self       )
								lowerCamelCase__         =  FlaxBertModelTester(self       )
								lowerCamelCase__         =  clip_model_tester.prepare_config_and_inputs()
								lowerCamelCase__         =  bert_model_tester.prepare_config_and_inputs()

								lowerCamelCase__         =  vision_config_and_inputs

								lowerCamelCase__         =  text_config_and_inputs

								# make sure that cross attention layers are added
								return {
								    "text_config": text_config,
								    "vision_config": vision_config,
								    "pixel_values": pixel_values,
								    "attention_mask": attention_mask,
								    "input_ids": input_ids,
								    "token_type_ids": token_type_ids,
								}




@require_flax
@require_vision
class 		UpperCamelCase__    (unittest.TestCase			):




		'''simple docstring'''





		@slow
		def 			UpperCamelCase_					(      self       ):

								'''simple docstring'''





								lowerCamelCase__         =  FlaxVisionTextDualEncoderModel.from_pretrained("""clip-italian/clip-italian"""   ,logit_scale_init_value=1.0       )
								lowerCamelCase__         =  VisionTextDualEncoderProcessor.from_pretrained("""clip-italian/clip-italian"""       )

								lowerCamelCase__         =  Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""       )
								lowerCamelCase__         =  processor(
								    text=["""una foto di un gatto""", """una foto di un cane"""]   ,images=_lowerCAmelCase   ,padding=_lowerCAmelCase   ,return_tensors="""np"""       )

								lowerCamelCase__         =  model(**_lowerCAmelCase       )

								# verify the logits
								self.assertEqual(outputs.logits_per_image.shape   ,(inputs.pixel_values.shape[0], inputs.input_ids.shape[0])       )
								self.assertEqual(
								    outputs.logits_per_text.shape   ,(inputs.input_ids.shape[0], inputs.pixel_values.shape[0])   ,)

								lowerCamelCase__         =  np.array([[1.228_4727, 0.310_4122]]       )

								self.assertTrue(np.allclose(outputs.logits_per_image   ,_lowerCAmelCase   ,atol=1E-3       )       )









'''simple docstring'''







import argparse
import struct
import unittest




class 		UpperCamelCase__    :




		'''simple docstring'''





		def __init__(      self   ,_lowerCAmelCase       ):
								lowerCamelCase__         =  data

								# Initialize hash values
								lowerCamelCase__         =  [
								    0x6a_09_e6_67,
								    0xbb_67_ae_85,
								    0x3c_6e_f3_72,
								    0xa5_4f_f5_3a,
								    0x51_0e_52_7f,
								    0x9b_05_68_8c,
								    0x1f_83_d9_ab,
								    0x5b_e0_cd_19,
								]

								# Initialize round constants
								lowerCamelCase__         =  [
								    0x42_8a_2f_98,
								    0x71_37_44_91,
								    0xb5_c0_fb_cf,
								    0xe9_b5_db_a5,
								    0x39_56_c2_5b,
								    0x59_f1_11_f1,
								    0x92_3f_82_a4,
								    0xab_1c_5e_d5,
								    0xd8_07_aa_98,
								    0x12_83_5b_01,
								    0x24_31_85_be,
								    0x55_0c_7d_c3,
								    0x72_be_5d_74,
								    0x80_de_b1_fe,
								    0x9b_dc_06_a7,
								    0xc1_9b_f1_74,
								    0xe4_9b_69_c1,
								    0xef_be_47_86,
								    0x0f_c1_9d_c6,
								    0x24_0c_a1_cc,
								    0x2d_e9_2c_6f,
								    0x4a_74_84_aa,
								    0x5c_b0_a9_dc,
								    0x76_f9_88_da,
								    0x98_3e_51_52,
								    0xa8_31_c6_6d,
								    0xb0_03_27_c8,
								    0xbf_59_7f_c7,
								    0xc6_e0_0b_f3,
								    0xd5_a7_91_47,
								    0x06_ca_63_51,
								    0x14_29_29_67,
								    0x27_b7_0a_85,
								    0x2e_1b_21_38,
								    0x4d_2c_6d_fc,
								    0x53_38_0d_13,
								    0x65_0a_73_54,
								    0x76_6a_0a_bb,
								    0x81_c2_c9_2e,
								    0x92_72_2c_85,
								    0xa2_bf_e8_a1,
								    0xa8_1a_66_4b,
								    0xc2_4b_8b_70,
								    0xc7_6c_51_a3,
								    0xd1_92_e8_19,
								    0xd6_99_06_24,
								    0xf4_0e_35_85,
								    0x10_6a_a0_70,
								    0x19_a4_c1_16,
								    0x1e_37_6c_08,
								    0x27_48_77_4c,
								    0x34_b0_bc_b5,
								    0x39_1c_0c_b3,
								    0x4e_d8_aa_4a,
								    0x5b_9c_ca_4f,
								    0x68_2e_6f_f3,
								    0x74_8f_82_ee,
								    0x78_a5_63_6f,
								    0x84_c8_78_14,
								    0x8c_c7_02_08,
								    0x90_be_ff_fa,
								    0xa4_50_6c_eb,
								    0xbe_f9_a3_f7,
								    0xc6_71_78_f2,
								]

								lowerCamelCase__         =  self.preprocessing(self.data       )
								self.final_hash()






		@staticmethod
		def 			UpperCamelCase_					(      _lowerCAmelCase       ):
								lowerCamelCase__         =  B"""\x80""" + (B"""\x00""" * (63 - (len(_lowerCAmelCase       ) + 8) % 64))
								lowerCamelCase__         =  struct.pack(""">Q"""   ,(len(_lowerCAmelCase       ) * 8)       )
								return data + padding + big_endian_integer






		def 			UpperCamelCase_					(      self       ):
								# Convert into blocks of 64 bytes
								lowerCamelCase__         =  [
								    self.preprocessed_data[x : x + 64]
								    for x in range(0   ,len(self.preprocessed_data       )   ,64       )
								]

								for block in self.blocks:
														# Convert the given block into a list of 4 byte integers
														lowerCamelCase__         =  list(struct.unpack(""">16L"""   ,_lowerCAmelCase       )       )
														# add 48 0-ed integers
														words += [0] * 48

														lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__         =  self.hashes

														for index in range(0   ,64       ):
																				if index > 15:
																										# modify the zero-ed indexes at the end of the array
																										lowerCamelCase__         =  (
																										    self.ror(words[index - 15]   ,7       )
																										    ^ self.ror(words[index - 15]   ,18       )
																										    ^ (words[index - 15] >> 3)
																										)
																										lowerCamelCase__         =  (
																										    self.ror(words[index - 2]   ,17       )
																										    ^ self.ror(words[index - 2]   ,19       )
																										    ^ (words[index - 2] >> 10)
																										)

																										lowerCamelCase__         =  (
																										    words[index - 16] + sa + words[index - 7] + sa
																										) % 0x1_00_00_00_00

																				# Compression
																				lowerCamelCase__         =  self.ror(_lowerCAmelCase   ,6       ) ^ self.ror(_lowerCAmelCase   ,11       ) ^ self.ror(_lowerCAmelCase   ,25       )
																				lowerCamelCase__         =  (e & f) ^ ((~e & 0xff_ff_ff_ff) & g)
																				lowerCamelCase__         =  (
																				    h + sa + ch + self.round_constants[index] + words[index]
																				) % 0x1_00_00_00_00
																				lowerCamelCase__         =  self.ror(_lowerCAmelCase   ,2       ) ^ self.ror(_lowerCAmelCase   ,13       ) ^ self.ror(_lowerCAmelCase   ,22       )
																				lowerCamelCase__         =  (a & b) ^ (a & c) ^ (b & c)
																				lowerCamelCase__         =  (sa + maj) % 0x1_00_00_00_00

																				lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__         =  (
																				    g,
																				    f,
																				    e,
																				    ((d + tempa) % 0x1_00_00_00_00),
																				    c,
																				    b,
																				    a,
																				    ((tempa + tempa) % 0x1_00_00_00_00),
																				)

														lowerCamelCase__         =  [a, b, c, d, e, f, g, h]

														# Modify final values
														lowerCamelCase__         =  [
														    ((element + mutated_hash_values[index]) % 0x1_00_00_00_00)
														    for index, element in enumerate(self.hashes       )
														]

								lowerCamelCase__         =  """""".join([hex(_lowerCAmelCase       )[2:].zfill(8       ) for value in self.hashes]       )






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase       ):
								return 0xff_ff_ff_ff & (value << (32 - rotations)) | (value >> rotations)




class 		UpperCamelCase__    (unittest.TestCase			):




		'''simple docstring'''





		def 			UpperCamelCase_					(      self       ):
								import hashlib

								lowerCamelCase__         =  bytes("""Test String"""   ,"""utf-8"""       )
								self.assertEqual(SHAaaa(_lowerCAmelCase       ).hash   ,hashlib.shaaaa(_lowerCAmelCase       ).hexdigest()       )



def 						A__			(				):
						import doctest

						doctest.testmod()

						lowerCamelCase__         =  argparse.ArgumentParser()
						parser.add_argument(
						    """-s"""   ,    """--string"""   ,    dest="""input_string"""   ,    default="""Hello World!! Welcome to Cryptography"""   ,    help="""Hash the string"""   ,    )
						parser.add_argument(
						    """-f"""   ,    """--file"""   ,    dest="""input_file"""   ,    help="""Hash contents of a file"""						)

						lowerCamelCase__         =  parser.parse_args()

						lowerCamelCase__         =  args.input_string

						# hash input should be a bytestring
						if args.input_file:
												with open(args.input_file   ,    """rb"""						) as f:
																		lowerCamelCase__         =  f.read()
						else:
												lowerCamelCase__         =  bytes(__lowerCAmelCase   ,    """utf-8"""						)

						print(SHAaaa(__lowerCAmelCase						).hash						)


if __name__ == "__main__":
							main()

