





import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VideoMAEConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import (
          MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
          VideoMAEForPreTraining,
          VideoMAEForVideoClassification,
          VideoMAEModel,
      )
      from transformers.models.videomae.modeling_videomae import VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from transformers import VideoMAEImageProcessor







class 		UpperCAmelCase   :


  """simple docstring"""







  def __init__(				self    :					Dict							,	UpperCamelCase__    :					str							,	UpperCamelCase__    :					Optional[Any]=13							,	UpperCamelCase__    :					int=10							,	UpperCamelCase__    :					int=3							,	UpperCamelCase__    :					Any=2							,	UpperCamelCase__    :					List[Any]=2							,	UpperCamelCase__    :					Optional[int]=2							,	UpperCamelCase__    :					Dict=True							,	UpperCamelCase__    :					Optional[int]=True							,	UpperCamelCase__    :					Dict=32							,	UpperCamelCase__    :					str=5							,	UpperCamelCase__    :					Union[str, Any]=4							,	UpperCamelCase__    :					Union[str, Any]=37							,	UpperCamelCase__    :					int="gelu"							,	UpperCamelCase__    :					int=0.1							,	UpperCamelCase__    :					List[str]=0.1							,	UpperCamelCase__    :					Optional[int]=10							,	UpperCamelCase__    :					Union[str, Any]=0.02							,	UpperCamelCase__    :					str=0.9							,	UpperCamelCase__    :					Optional[Any]=None							,	)     ->						int:
    _UpperCamelCase       			=parent
    _UpperCamelCase       			=batch_size
    _UpperCamelCase       			=image_size
    _UpperCamelCase       			=num_channels
    _UpperCamelCase       			=patch_size
    _UpperCamelCase       			=tubelet_size
    _UpperCamelCase       			=num_frames
    _UpperCamelCase       			=is_training
    _UpperCamelCase       			=use_labels
    _UpperCamelCase       			=hidden_size
    _UpperCamelCase       			=num_hidden_layers
    _UpperCamelCase       			=num_attention_heads
    _UpperCamelCase       			=intermediate_size
    _UpperCamelCase       			=hidden_act
    _UpperCamelCase       			=hidden_dropout_prob
    _UpperCamelCase       			=attention_probs_dropout_prob
    _UpperCamelCase       			=type_sequence_label_size
    _UpperCamelCase       			=initializer_range
    _UpperCamelCase       			=mask_ratio
    _UpperCamelCase       			=scope

    # in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
    _UpperCamelCase       			=(image_size // patch_size) ** 2
    _UpperCamelCase       			=(num_frames // tubelet_size) * self.num_patches_per_frame

    # use this variable to define bool_masked_pos
    _UpperCamelCase       			=int(mask_ratio * self.seq_length  )


  def   UpperCamelCase__      (				self    :					Any  )     ->						Tuple:
    _UpperCamelCase       			=floats_tensor(
        [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]  )

    _UpperCamelCase       			=None
    if self.use_labels:
      _UpperCamelCase       			=ids_tensor([self.batch_size]							,	self.type_sequence_label_size  )

    _UpperCamelCase       			=self.get_config()

    return config, pixel_values, labels


  def   UpperCamelCase__      (				self    :					List[str]  )     ->						str:
    return VideoMAEConfig(
        image_size=self.image_size							,	patch_size=self.patch_size							,	num_channels=self.num_channels							,	num_frames=self.num_frames							,	tubelet_size=self.tubelet_size							,	hidden_size=self.hidden_size							,	num_hidden_layers=self.num_hidden_layers							,	num_attention_heads=self.num_attention_heads							,	intermediate_size=self.intermediate_size							,	hidden_act=self.hidden_act							,	hidden_dropout_prob=self.hidden_dropout_prob							,	attention_probs_dropout_prob=self.attention_probs_dropout_prob							,	is_decoder=__lowerCAmelCase							,	initializer_range=self.initializer_range							,	)


  def   UpperCamelCase__      (				self    :					Union[str, Any]							,	UpperCamelCase__    :					Union[str, Any]							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					List[Any]  )     ->						Dict:
    _UpperCamelCase       			=VideoMAEModel(config=__lowerCAmelCase  )
    model.to(__lowerCAmelCase  )
    model.eval()
    _UpperCamelCase       			=model(__lowerCAmelCase  )
    self.parent.assertEqual(result.last_hidden_state.shape							,	(self.batch_size, self.seq_length, self.hidden_size)  )


  def   UpperCamelCase__      (				self    :					Any							,	UpperCamelCase__    :					Any							,	UpperCamelCase__    :					List[Any]							,	UpperCamelCase__    :					Any  )     ->						int:
    _UpperCamelCase       			=VideoMAEForPreTraining(__lowerCAmelCase  )
    model.to(__lowerCAmelCase  )
    model.eval()
    # important: each video needs to have the same number of masked patches
    # hence we define a single mask, which we then repeat for each example in the batch
    _UpperCamelCase       			=torch.ones((self.num_masks,)  )
    _UpperCamelCase       			=torch.cat([mask, torch.zeros(self.seq_length - mask.size(0  )  )]  )
    _UpperCamelCase       			=mask.expand(self.batch_size							,	-1  ).bool()

    _UpperCamelCase       			=model(__lowerCAmelCase							,	__lowerCAmelCase  )
    # model only returns predictions for masked patches
    _UpperCamelCase       			=mask.sum().item()
    _UpperCamelCase       			=3 * self.tubelet_size * self.patch_size**2
    self.parent.assertEqual(result.logits.shape							,	(self.batch_size, num_masked_patches, decoder_num_labels)  )




  def   UpperCamelCase__      (				self    :					Optional[int]  )     ->						Union[str, Any]:
    _UpperCamelCase       			=self.prepare_config_and_inputs()
    _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase       			=config_and_inputs
    _UpperCamelCase       			={'''pixel_values''': pixel_values}
    return config, inputs_dict







@require_torch
class 		UpperCAmelCase   (				lowercase_   ,     lowercase_   ,     unittest.TestCase):


  """simple docstring"""







  lowerCAmelCase_					=				(
      (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
  )
  lowerCAmelCase_					=				(
      {"""feature-extraction""": VideoMAEModel, """video-classification""": VideoMAEForVideoClassification}
      if is_torch_available()
      else {}
  )

  lowerCAmelCase_					=				False
  lowerCAmelCase_					=				False
  lowerCAmelCase_					=				False
  lowerCAmelCase_					=				False


  def   UpperCamelCase__      (				self    :					List[Any]  )     ->						List[Any]:
    _UpperCamelCase       			=VideoMAEModelTester(self  )
    _UpperCamelCase       			=ConfigTester(self							,	config_class=__lowerCAmelCase							,	has_text_modality=__lowerCAmelCase							,	hidden_size=37  )


  def   UpperCamelCase__      (				self    :					Optional[int]							,	UpperCamelCase__    :					Optional[int]							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					Tuple=False  )     ->						Tuple:
    _UpperCamelCase       			=copy.deepcopy(__lowerCAmelCase  )

    if model_class == VideoMAEForPreTraining:
      # important: each video needs to have the same number of masked patches
      # hence we define a single mask, which we then repeat for each example in the batch
      _UpperCamelCase       			=torch.ones((self.model_tester.num_masks,)  )
      _UpperCamelCase       			=torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0  )  )]  )
      _UpperCamelCase       			=mask.expand(self.model_tester.batch_size							,	-1  ).bool()
      _UpperCamelCase       			=bool_masked_pos.to(__lowerCAmelCase  )

    if return_labels:
      if model_class in [
          *get_values(__lowerCAmelCase  ),
      ]:
        _UpperCamelCase       			=torch.zeros(
            self.model_tester.batch_size							,	dtype=torch.long							,	device=__lowerCAmelCase  )

    return inputs_dict


  def   UpperCamelCase__      (				self    :					str  )     ->						List[Any]:
    self.config_tester.run_common_tests()


  @unittest.skip(reason='''VideoMAE does not use inputs_embeds'''  )
  def   UpperCamelCase__      (				self    :					List[Any]  )     ->						int:
    pass


  def   UpperCamelCase__      (				self    :					List[Any]  )     ->						Optional[Any]:
    _UpperCamelCase			,     _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
      _UpperCamelCase       			=model_class(__lowerCAmelCase  )
      self.assertIsInstance(model.get_input_embeddings()							,	(nn.Module)  )
      _UpperCamelCase       			=model.get_output_embeddings()
      self.assertTrue(x is None or isinstance(__lowerCAmelCase							,	nn.Linear  )  )


  def   UpperCamelCase__      (				self    :					Dict  )     ->						Optional[Any]:
    _UpperCamelCase			,     _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
      _UpperCamelCase       			=model_class(__lowerCAmelCase  )
      _UpperCamelCase       			=inspect.signature(model.forward  )
      # signature.parameters is an OrderedDict => so arg_names order is deterministic
      _UpperCamelCase       			=[*signature.parameters.keys()]

      _UpperCamelCase       			=['''pixel_values''']
      self.assertListEqual(arg_names[:1]							,	__lowerCAmelCase  )


  def   UpperCamelCase__      (				self    :					Optional[Any]  )     ->						Tuple:
    _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*__lowerCAmelCase  )


  def   UpperCamelCase__      (				self    :					List[str]  )     ->						int:
    _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_pretraining(*__lowerCAmelCase  )


  @slow
  def   UpperCamelCase__      (				self    :					Any  )     ->						Union[str, Any]:







    for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      _UpperCamelCase       			=VideoMAEModel.from_pretrained(__lowerCAmelCase  )
      self.assertIsNotNone(__lowerCAmelCase  )


  def   UpperCamelCase__      (				self    :					List[Any]  )     ->						Tuple:







    if not self.has_attentions:
      pass

    else:
      _UpperCamelCase			,     _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs_for_common()
      _UpperCamelCase       			=True

      for model_class in self.all_model_classes:
        _UpperCamelCase       			=self.model_tester.seq_length - self.model_tester.num_masks
        _UpperCamelCase       			=(
            num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
        )

        _UpperCamelCase       			=True
        _UpperCamelCase       			=False
        _UpperCamelCase       			=True
        _UpperCamelCase       			=model_class(__lowerCAmelCase  )
        model.to(__lowerCAmelCase  )
        model.eval()
        with torch.no_grad():
          _UpperCamelCase       			=model(**self._prepare_for_class(__lowerCAmelCase							,	__lowerCAmelCase  )  )
        _UpperCamelCase       			=outputs.attentions
        self.assertEqual(len(__lowerCAmelCase  )							,	self.model_tester.num_hidden_layers  )

        # check that output_attentions also work using config
        del inputs_dict["output_attentions"]
        _UpperCamelCase       			=True
        _UpperCamelCase       			=model_class(__lowerCAmelCase  )
        model.to(__lowerCAmelCase  )
        model.eval()
        with torch.no_grad():
          _UpperCamelCase       			=model(**self._prepare_for_class(__lowerCAmelCase							,	__lowerCAmelCase  )  )
        _UpperCamelCase       			=outputs.attentions
        self.assertEqual(len(__lowerCAmelCase  )							,	self.model_tester.num_hidden_layers  )

        self.assertListEqual(
            list(attentions[0].shape[-3:]  )							,	[self.model_tester.num_attention_heads, seq_len, seq_len]							,	)
        _UpperCamelCase       			=len(__lowerCAmelCase  )

        # Check attention is always last and order is fine
        _UpperCamelCase       			=True
        _UpperCamelCase       			=True
        _UpperCamelCase       			=model_class(__lowerCAmelCase  )
        model.to(__lowerCAmelCase  )
        model.eval()
        with torch.no_grad():
          _UpperCamelCase       			=model(**self._prepare_for_class(__lowerCAmelCase							,	__lowerCAmelCase  )  )

        self.assertEqual(out_len + 1							,	len(__lowerCAmelCase  )  )

        _UpperCamelCase       			=outputs.attentions

        self.assertEqual(len(__lowerCAmelCase  )							,	self.model_tester.num_hidden_layers  )
        self.assertListEqual(
            list(self_attentions[0].shape[-3:]  )							,	[self.model_tester.num_attention_heads, seq_len, seq_len]							,	)


  def   UpperCamelCase__      (				self    :					List[str]  )     ->						Tuple:







    def check_hidden_states_output(UpperCamelCase__    :					Dict							,	UpperCamelCase__    :					Union[str, Any]							,	UpperCamelCase__    :					List[str]  ):
      _UpperCamelCase       			=model_class(__lowerCAmelCase  )
      model.to(__lowerCAmelCase  )
      model.eval()

      with torch.no_grad():
        _UpperCamelCase       			=model(**self._prepare_for_class(__lowerCAmelCase							,	__lowerCAmelCase  )  )

      _UpperCamelCase       			=outputs.hidden_states
      _UpperCamelCase       			=self.model_tester.num_hidden_layers + 1
      self.assertEqual(len(__lowerCAmelCase  )							,	__lowerCAmelCase  )

      _UpperCamelCase       			=self.model_tester.seq_length - self.model_tester.num_masks
      _UpperCamelCase       			=num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length

      self.assertListEqual(
          list(hidden_states[0].shape[-2:]  )							,	[seq_length, self.model_tester.hidden_size]							,	)

    _UpperCamelCase			,     _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
      _UpperCamelCase       			=True
      check_hidden_states_output(__lowerCAmelCase							,	__lowerCAmelCase							,	__lowerCAmelCase  )

      # check that output_hidden_states also work using config
      del inputs_dict["output_hidden_states"]
      _UpperCamelCase       			=True

      check_hidden_states_output(__lowerCAmelCase							,	__lowerCAmelCase							,	__lowerCAmelCase  )




  @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''  )
  def   UpperCamelCase__      (				self    :					List[str]  )     ->						str:
    pass




def 					_a   ():


  """simple docstring"""

  _UpperCamelCase       			=hf_hub_download(
      repo_id='''hf-internal-testing/spaghetti-video'''  ,      filename='''eating_spaghetti.npy'''  ,      repo_type='''dataset'''   )
  _UpperCamelCase       			=np.load(__snake_case   )
  return list(__snake_case   )







@require_torch
@require_vision
class 		UpperCAmelCase   (				unittest.TestCase):


  """simple docstring"""







  @cached_property
  def   UpperCamelCase__      (				self    :					List[Any]  )     ->						List[str]:
    return (
        VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5]							,	image_std=[0.5, 0.5, 0.5]  )
        if is_vision_available()
        else None
    )


  @slow
  def   UpperCamelCase__      (				self    :					str  )     ->						Optional[int]:
    _UpperCamelCase       			=VideoMAEForVideoClassification.from_pretrained('''MCG-NJU/videomae-base-finetuned-kinetics'''  ).to(
        __lowerCAmelCase  )

    _UpperCamelCase       			=self.default_image_processor
    _UpperCamelCase       			=prepare_video()
    _UpperCamelCase       			=image_processor(__lowerCAmelCase							,	return_tensors='''pt'''  ).to(__lowerCAmelCase  )

    # forward pass
    with torch.no_grad():
      _UpperCamelCase       			=model(**__lowerCAmelCase  )

    # verify the logits
    _UpperCamelCase       			=torch.Size((1, 400)  )
    self.assertEqual(outputs.logits.shape							,	__lowerCAmelCase  )

    _UpperCamelCase       			=torch.tensor([0.3669, -0.0688, -0.2421]  ).to(__lowerCAmelCase  )

    self.assertTrue(torch.allclose(outputs.logits[0, :3]							,	__lowerCAmelCase							,	atol=1E-4  )  )




  @slow
  def   UpperCamelCase__      (				self    :					Union[str, Any]  )     ->						Dict:
    _UpperCamelCase       			=VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''  ).to(__lowerCAmelCase  )

    _UpperCamelCase       			=self.default_image_processor
    _UpperCamelCase       			=prepare_video()
    _UpperCamelCase       			=image_processor(__lowerCAmelCase							,	return_tensors='''pt'''  ).to(__lowerCAmelCase  )

    # add boolean mask, indicating which patches to mask
    _UpperCamelCase       			=hf_hub_download(repo_id='''hf-internal-testing/bool-masked-pos'''							,	filename='''bool_masked_pos.pt'''  )
    _UpperCamelCase       			=torch.load(__lowerCAmelCase  )

    # forward pass
    with torch.no_grad():
      _UpperCamelCase       			=model(**__lowerCAmelCase  )

    # verify the logits
    _UpperCamelCase       			=torch.Size([1, 1408, 1536]  )
    _UpperCamelCase       			=torch.tensor(
        [[0.7994, 0.9612, 0.8508], [0.7401, 0.8958, 0.8302], [0.5862, 0.7468, 0.7325]]							,	device=__lowerCAmelCase  )
    self.assertEqual(outputs.logits.shape							,	__lowerCAmelCase  )
    self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]							,	__lowerCAmelCase							,	atol=1E-4  )  )

    # verify the loss (`config.norm_pix_loss` = `True`)
    _UpperCamelCase       			=torch.tensor([0.5142]							,	device=__lowerCAmelCase  )
    self.assertTrue(torch.allclose(outputs.loss							,	__lowerCAmelCase							,	atol=1E-4  )  )

    # verify the loss (`config.norm_pix_loss` = `False`)
    _UpperCamelCase       			=VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''							,	norm_pix_loss=__lowerCAmelCase  ).to(
        __lowerCAmelCase  )

    with torch.no_grad():
      _UpperCamelCase       			=model(**__lowerCAmelCase  )

    _UpperCamelCase       			=torch.tensor(torch.tensor([0.6469]  )							,	device=__lowerCAmelCase  )
    self.assertTrue(torch.allclose(outputs.loss							,	__lowerCAmelCase							,	atol=1E-4  )  )













'''simple docstring'''






from collections.abc import Generator
from math import sin


def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  if len(__SCREAMING_SNAKE_CASE   ) != 32:
    raise ValueError('''Input must be of length 32'''   )

  _UpperCamelCase       			=b''''''
  for i in [3, 2, 1, 0]:
    little_endian += string_aa[8 * i : 8 * i + 8]
  return little_endian


def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  if i < 0:
    raise ValueError('''Input must be non-negative'''   )

  _UpperCamelCase       			=format(__SCREAMING_SNAKE_CASE  ,      '''08x'''   )[-8:]
  _UpperCamelCase       			=b''''''
  for i in [3, 2, 1, 0]:
    little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('''utf-8'''   )
  return little_endian_hex


def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  _UpperCamelCase       			=b''''''
  for char in message:
    bit_string += format(__SCREAMING_SNAKE_CASE  ,      '''08b'''   ).encode('''utf-8'''   )
  _UpperCamelCase       			=format(len(__SCREAMING_SNAKE_CASE   )  ,      '''064b'''   ).encode('''utf-8'''   )

  # Pad bit_string to a multiple of 512 chars
  bit_string += b"1"
  while len(__SCREAMING_SNAKE_CASE   ) % 512 != 448:
    bit_string += b"0"
  bit_string += to_little_endian(start_len[32:]   ) + to_little_endian(start_len[:32]   )

  return bit_string


def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  if len(__SCREAMING_SNAKE_CASE   ) % 512 != 0:
    raise ValueError('''Input must have length that\'s a multiple of 512'''   )

  for pos in range(0  ,      len(__SCREAMING_SNAKE_CASE   )  ,      512   ):
    _UpperCamelCase       			=bit_string[pos : pos + 512]
    _UpperCamelCase       			=[]
    for i in range(0  ,      512  ,      32   ):
      block_words.append(int(to_little_endian(block[i : i + 32]   )  ,      2   )   )
    yield block_words


def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  if i < 0:
    raise ValueError('''Input must be non-negative'''   )

  _UpperCamelCase       			=format(__SCREAMING_SNAKE_CASE  ,      '''032b'''   )
  _UpperCamelCase       			=''''''
  for c in i_str:
    new_str += "1" if c == "0" else "0"
  return int(__SCREAMING_SNAKE_CASE  ,      2   )


def 					_a   (__SCREAMING_SNAKE_CASE  ,      __SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  return (a + b) % 2**32


def 					_a   (__SCREAMING_SNAKE_CASE  ,      __SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  if i < 0:
    raise ValueError('''Input must be non-negative'''   )
  if shift < 0:
    raise ValueError('''Shift must be non-negative'''   )
  return ((i << shift) ^ (i >> (32 - shift))) % 2**32


def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  _UpperCamelCase       			=preprocess(__SCREAMING_SNAKE_CASE   )

  _UpperCamelCase       			=[int(2**32 * abs(sin(i + 1   )   )   ) for i in range(64   )]

  # Starting states
  _UpperCamelCase       			=0X6745_2301
  _UpperCamelCase       			=0Xefcd_ab89
  _UpperCamelCase       			=0X98ba_dcfe
  _UpperCamelCase       			=0X1032_5476

  _UpperCamelCase       			=[
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
  ]

  # Process bit string in chunks, each with 16 32-char words
  for block_words in get_block_words(__SCREAMING_SNAKE_CASE   ):
    _UpperCamelCase       			=aa
    _UpperCamelCase       			=ba
    _UpperCamelCase       			=ca
    _UpperCamelCase       			=da

    # Hash current chunk
    for i in range(64   ):
      if i <= 15:
        # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
        _UpperCamelCase       			=d ^ (b & (c ^ d))
        _UpperCamelCase       			=i
      elif i <= 31:
        # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
        _UpperCamelCase       			=c ^ (d & (b ^ c))
        _UpperCamelCase       			=(5 * i + 1) % 16
      elif i <= 47:
        _UpperCamelCase       			=b ^ c ^ d
        _UpperCamelCase       			=(3 * i + 5) % 16
      else:
        _UpperCamelCase       			=c ^ (b | not_aa(__SCREAMING_SNAKE_CASE   ))
        _UpperCamelCase       			=(7 * i) % 16
      _UpperCamelCase       			=(f + a + added_consts[i] + block_words[g]) % 2**32
      _UpperCamelCase       			=d
      _UpperCamelCase       			=c
      _UpperCamelCase       			=b
      _UpperCamelCase       			=sum_aa(__SCREAMING_SNAKE_CASE  ,      left_rotate_aa(__SCREAMING_SNAKE_CASE  ,      shift_amounts[i]   )   )

    # Add hashed chunk to running total
    _UpperCamelCase       			=sum_aa(__SCREAMING_SNAKE_CASE  ,      __SCREAMING_SNAKE_CASE   )
    _UpperCamelCase       			=sum_aa(__SCREAMING_SNAKE_CASE  ,      __SCREAMING_SNAKE_CASE   )
    _UpperCamelCase       			=sum_aa(__SCREAMING_SNAKE_CASE  ,      __SCREAMING_SNAKE_CASE   )
    _UpperCamelCase       			=sum_aa(__SCREAMING_SNAKE_CASE  ,      __SCREAMING_SNAKE_CASE   )

  _UpperCamelCase       			=reformat_hex(__SCREAMING_SNAKE_CASE   ) + reformat_hex(__SCREAMING_SNAKE_CASE   ) + reformat_hex(__SCREAMING_SNAKE_CASE   ) + reformat_hex(__SCREAMING_SNAKE_CASE   )
  return digest


if __name__ == "__main__":
      import doctest

      doctest.testmod()






