





'''simple docstring'''






from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


__lowerCamelCase						: List[Any]		=   logging.get_logger(__name__)

# General docstring
__lowerCamelCase						: str		=   'RegNetConfig'

# Base docstring
__lowerCamelCase						: Any		=   'facebook/regnet-y-040'
__lowerCamelCase						: Union[str, Any]		=   [1, 1088, 7, 7]

# Image classification docstring
__lowerCamelCase						: Union[str, Any]		=   'facebook/regnet-y-040'
__lowerCamelCase						: List[str]		=   'tabby, tabby cat'

__lowerCamelCase						: int		=   [
    'facebook/regnet-y-040',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]







class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  def __init__(				self    :					List[Any]							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int = 3							,	UpperCamelCase__    :					int = 1							,	UpperCamelCase__    :					int = 1							,	UpperCamelCase__    :					Optional[str] = "relu"							,	**UpperCamelCase__    :					Any							,	)     ->						Dict:
    super().__init__(**UpperCamelCase__  )
    # The padding and conv has been verified in
    # https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
    _UpperCamelCase       			=tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2  )
    _UpperCamelCase       			=tf.keras.layers.ConvaD(
        filters=UpperCamelCase__							,	kernel_size=UpperCamelCase__							,	strides=UpperCamelCase__							,	padding='''VALID'''							,	groups=UpperCamelCase__							,	use_bias=UpperCamelCase__							,	name='''convolution'''							,	)
    _UpperCamelCase       			=tf.keras.layers.BatchNormalization(epsilon=1E-5							,	momentum=0.9							,	name='''normalization'''  )
    _UpperCamelCase       			=ACTaFN[activation] if activation is not None else tf.identity




  def   UpperCamelCase__      (				self    :					Union[str, Any]							,	UpperCamelCase__    :					int  )     ->						Union[str, Any]:
    _UpperCamelCase       			=self.convolution(self.padding(UpperCamelCase__  )  )
    _UpperCamelCase       			=self.normalization(UpperCamelCase__  )
    _UpperCamelCase       			=self.activation(UpperCamelCase__  )
    return hidden_state







class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  def __init__(				self    :					Optional[Any]							,	UpperCamelCase__    :					RegNetConfig							,	**UpperCamelCase__    :					int  )     ->						Optional[Any]:
    super().__init__(**UpperCamelCase__  )
    _UpperCamelCase       			=config.num_channels
    _UpperCamelCase       			=TFRegNetConvLayer(
        out_channels=config.embedding_size							,	kernel_size=3							,	stride=2							,	activation=config.hidden_act							,	name='''embedder'''							,	)




  def   UpperCamelCase__      (				self    :					Dict							,	UpperCamelCase__    :					List[Any]  )     ->						Any:
    _UpperCamelCase       			=shape_list(UpperCamelCase__  )[1]
    if tf.executing_eagerly() and num_channels != self.num_channels:
      raise ValueError(
          '''Make sure that the channel dimension of the pixel values match with the one set in the configuration.'''  )

    # When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
    # So change the input format from `NCHW` to `NHWC`.
    # shape = (batch_size, in_height, in_width, in_channels=num_channels)
    _UpperCamelCase       			=tf.transpose(UpperCamelCase__							,	perm=(0, 2, 3, 1)  )
    _UpperCamelCase       			=self.embedder(UpperCamelCase__  )
    return hidden_state







class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  def __init__(				self    :					Union[str, Any]							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int = 2							,	**UpperCamelCase__    :					Tuple  )     ->						Optional[int]:
    super().__init__(**UpperCamelCase__  )
    _UpperCamelCase       			=tf.keras.layers.ConvaD(
        filters=UpperCamelCase__							,	kernel_size=1							,	strides=UpperCamelCase__							,	use_bias=UpperCamelCase__							,	name='''convolution'''  )
    _UpperCamelCase       			=tf.keras.layers.BatchNormalization(epsilon=1E-5							,	momentum=0.9							,	name='''normalization'''  )




  def   UpperCamelCase__      (				self    :					Optional[Any]							,	UpperCamelCase__    :					tf.Tensor							,	UpperCamelCase__    :					bool = False  )     ->						tf.Tensor:
    return self.normalization(self.convolution(UpperCamelCase__  )							,	training=UpperCamelCase__  )







class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  def __init__(				self    :					List[str]							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int							,	**UpperCamelCase__    :					int  )     ->						List[str]:
    super().__init__(**UpperCamelCase__  )
    _UpperCamelCase       			=tf.keras.layers.GlobalAveragePoolingaD(keepdims=UpperCamelCase__							,	name='''pooler'''  )
    _UpperCamelCase       			=[
        tf.keras.layers.ConvaD(filters=UpperCamelCase__							,	kernel_size=1							,	activation='''relu'''							,	name='''attention.0'''  ),
        tf.keras.layers.ConvaD(filters=UpperCamelCase__							,	kernel_size=1							,	activation='''sigmoid'''							,	name='''attention.2'''  ),
    ]




  def   UpperCamelCase__      (				self    :					List[Any]							,	UpperCamelCase__    :					Tuple  )     ->						int:
    # [batch_size, h, w, num_channels] -> [batch_size, 1, 1, num_channels]
    _UpperCamelCase       			=self.pooler(UpperCamelCase__  )
    for layer_module in self.attention:
      _UpperCamelCase       			=layer_module(UpperCamelCase__  )
    _UpperCamelCase       			=hidden_state * pooled
    return hidden_state







class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  def __init__(				self    :					Any							,	UpperCamelCase__    :					RegNetConfig							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int = 1							,	**UpperCamelCase__    :					Tuple  )     ->						Union[str, Any]:
    super().__init__(**UpperCamelCase__  )
    _UpperCamelCase       			=in_channels != out_channels or stride != 1
    _UpperCamelCase       			=max(1							,	out_channels // config.groups_width  )
    _UpperCamelCase       			=(
        TFRegNetShortCut(UpperCamelCase__							,	stride=UpperCamelCase__							,	name='''shortcut'''  )
        if should_apply_shortcut
        else tf.keras.layers.Activation('''linear'''							,	name='''shortcut'''  )
    )
    # `self.layers` instead of `self.layer` because that is a reserved argument.
    _UpperCamelCase       			=[
        TFRegNetConvLayer(UpperCamelCase__							,	kernel_size=1							,	activation=config.hidden_act							,	name='''layer.0'''  ),
        TFRegNetConvLayer(
            UpperCamelCase__							,	stride=UpperCamelCase__							,	groups=UpperCamelCase__							,	activation=config.hidden_act							,	name='''layer.1'''  ),
        TFRegNetConvLayer(UpperCamelCase__							,	kernel_size=1							,	activation=UpperCamelCase__							,	name='''layer.2'''  ),
    ]
    _UpperCamelCase       			=ACTaFN[config.hidden_act]




  def   UpperCamelCase__      (				self    :					Any							,	UpperCamelCase__    :					Any  )     ->						Optional[int]:
    _UpperCamelCase       			=hidden_state
    for layer_module in self.layers:
      _UpperCamelCase       			=layer_module(UpperCamelCase__  )
    _UpperCamelCase       			=self.shortcut(UpperCamelCase__  )
    hidden_state += residual
    _UpperCamelCase       			=self.activation(UpperCamelCase__  )
    return hidden_state







class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  def __init__(				self    :					Tuple							,	UpperCamelCase__    :					RegNetConfig							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int = 1							,	**UpperCamelCase__    :					str  )     ->						Any:
    super().__init__(**UpperCamelCase__  )
    _UpperCamelCase       			=in_channels != out_channels or stride != 1
    _UpperCamelCase       			=max(1							,	out_channels // config.groups_width  )
    _UpperCamelCase       			=(
        TFRegNetShortCut(UpperCamelCase__							,	stride=UpperCamelCase__							,	name='''shortcut'''  )
        if should_apply_shortcut
        else tf.keras.layers.Activation('''linear'''							,	name='''shortcut'''  )
    )
    _UpperCamelCase       			=[
        TFRegNetConvLayer(UpperCamelCase__							,	kernel_size=1							,	activation=config.hidden_act							,	name='''layer.0'''  ),
        TFRegNetConvLayer(
            UpperCamelCase__							,	stride=UpperCamelCase__							,	groups=UpperCamelCase__							,	activation=config.hidden_act							,	name='''layer.1'''  ),
        TFRegNetSELayer(UpperCamelCase__							,	reduced_channels=int(round(in_channels / 4  )  )							,	name='''layer.2'''  ),
        TFRegNetConvLayer(UpperCamelCase__							,	kernel_size=1							,	activation=UpperCamelCase__							,	name='''layer.3'''  ),
    ]
    _UpperCamelCase       			=ACTaFN[config.hidden_act]




  def   UpperCamelCase__      (				self    :					Union[str, Any]							,	UpperCamelCase__    :					Union[str, Any]  )     ->						Union[str, Any]:
    _UpperCamelCase       			=hidden_state
    for layer_module in self.layers:
      _UpperCamelCase       			=layer_module(UpperCamelCase__  )
    _UpperCamelCase       			=self.shortcut(UpperCamelCase__  )
    hidden_state += residual
    _UpperCamelCase       			=self.activation(UpperCamelCase__  )
    return hidden_state







class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  def __init__(				self    :					Dict							,	UpperCamelCase__    :					RegNetConfig							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					int = 2							,	UpperCamelCase__    :					int = 2							,	**UpperCamelCase__    :					Union[str, Any]  )     ->						Any:
    super().__init__(**UpperCamelCase__  )

    _UpperCamelCase       			=TFRegNetXLayer if config.layer_type == '''x''' else TFRegNetYLayer
    _UpperCamelCase       			=[
        # downsampling is done in the first layer with stride of 2
        layer(UpperCamelCase__							,	UpperCamelCase__							,	UpperCamelCase__							,	stride=UpperCamelCase__							,	name='''layers.0'''  ),
        *[layer(UpperCamelCase__							,	UpperCamelCase__							,	UpperCamelCase__							,	name=F'''layers.{i+1}'''  ) for i in range(depth - 1  )],
    ]




  def   UpperCamelCase__      (				self    :					List[str]							,	UpperCamelCase__    :					List[str]  )     ->						Tuple:
    for layer_module in self.layers:
      _UpperCamelCase       			=layer_module(UpperCamelCase__  )
    return hidden_state







class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  def __init__(				self    :					Optional[Any]							,	UpperCamelCase__    :					RegNetConfig							,	**UpperCamelCase__    :					List[str]  )     ->						Any:
    super().__init__(**UpperCamelCase__  )
    _UpperCamelCase       			=[]
    # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
    self.stages.append(
        TFRegNetStage(
            UpperCamelCase__							,	config.embedding_size							,	config.hidden_sizes[0]							,	stride=2 if config.downsample_in_first_stage else 1							,	depth=config.depths[0]							,	name='''stages.0'''							,	)  )
    _UpperCamelCase       			=zip(config.hidden_sizes							,	config.hidden_sizes[1:]  )
    for i, ((in_channels, out_channels), depth) in enumerate(zip(UpperCamelCase__							,	config.depths[1:]  )  ):
      self.stages.append(TFRegNetStage(UpperCamelCase__							,	UpperCamelCase__							,	UpperCamelCase__							,	depth=UpperCamelCase__							,	name=F'''stages.{i+1}'''  )  )




  def   UpperCamelCase__      (				self    :					Any							,	UpperCamelCase__    :					tf.Tensor							,	UpperCamelCase__    :					bool = False							,	UpperCamelCase__    :					bool = True  )     ->						TFBaseModelOutputWithNoAttention:
    _UpperCamelCase       			=() if output_hidden_states else None

    for stage_module in self.stages:
      if output_hidden_states:
        _UpperCamelCase       			=hidden_states + (hidden_state,)

      _UpperCamelCase       			=stage_module(UpperCamelCase__  )

    if output_hidden_states:
      _UpperCamelCase       			=hidden_states + (hidden_state,)

    if not return_dict:
      return tuple(v for v in [hidden_state, hidden_states] if v is not None  )

    return TFBaseModelOutputWithNoAttention(last_hidden_state=UpperCamelCase__							,	hidden_states=UpperCamelCase__  )







@keras_serializable
class 		UpperCAmelCase   (				tf.keras.layers.Layer):


  """simple docstring"""







  lowerCAmelCase_					=				RegNetConfig


  def __init__(				self    :					Tuple							,	UpperCamelCase__    :					Optional[int]							,	**UpperCamelCase__    :					Optional[int]  )     ->						List[Any]:
    super().__init__(**UpperCamelCase__  )
    _UpperCamelCase       			=config
    _UpperCamelCase       			=TFRegNetEmbeddings(UpperCamelCase__							,	name='''embedder'''  )
    _UpperCamelCase       			=TFRegNetEncoder(UpperCamelCase__							,	name='''encoder'''  )
    _UpperCamelCase       			=tf.keras.layers.GlobalAveragePoolingaD(keepdims=UpperCamelCase__							,	name='''pooler'''  )




  @unpack_inputs
  def   UpperCamelCase__      (				self    :					int							,	UpperCamelCase__    :					tf.Tensor							,	UpperCamelCase__    :					Optional[bool] = None							,	UpperCamelCase__    :					Optional[bool] = None							,	UpperCamelCase__    :					bool = False							,	)     ->						TFBaseModelOutputWithPoolingAndNoAttention:
    _UpperCamelCase       			=(
        output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    )
    _UpperCamelCase       			=return_dict if return_dict is not None else self.config.use_return_dict

    _UpperCamelCase       			=self.embedder(UpperCamelCase__							,	training=UpperCamelCase__  )

    _UpperCamelCase       			=self.encoder(
        UpperCamelCase__							,	output_hidden_states=UpperCamelCase__							,	return_dict=UpperCamelCase__							,	training=UpperCamelCase__  )

    _UpperCamelCase       			=encoder_outputs[0]
    _UpperCamelCase       			=self.pooler(UpperCamelCase__  )

    # Change to NCHW output format have uniformity in the modules
    _UpperCamelCase       			=tf.transpose(UpperCamelCase__							,	perm=(0, 3, 1, 2)  )
    _UpperCamelCase       			=tf.transpose(UpperCamelCase__							,	perm=(0, 3, 1, 2)  )

    # Change the other hidden state outputs to NCHW as well
    if output_hidden_states:
      _UpperCamelCase       			=tuple([tf.transpose(UpperCamelCase__							,	perm=(0, 3, 1, 2)  ) for h in encoder_outputs[1]]  )

    if not return_dict:
      return (last_hidden_state, pooled_output) + encoder_outputs[1:]

    return TFBaseModelOutputWithPoolingAndNoAttention(
        last_hidden_state=UpperCamelCase__							,	pooler_output=UpperCamelCase__							,	hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states							,	)







class 		UpperCAmelCase   (				lowercase_):


  """simple docstring"""







  lowerCAmelCase_					=				RegNetConfig
  lowerCAmelCase_					=				"""regnet"""
  lowerCAmelCase_					=				"""pixel_values"""


  @property
  def   UpperCamelCase__      (				self    :					List[Any]  )     ->						int:
    return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)							,	dtype=tf.floataa  )}




__lowerCamelCase						: Union[str, Any]		=   R'\n    Parameters:\n    This model is a Tensorflow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular Tensorflow Module and refer to the Tensorflow documentation for all matter related to general usage and\n    behavior.\n        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n'

__lowerCamelCase						: Optional[int]		=   R'\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConveNextImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'







@add_start_docstrings(
    """The bare RegNet model outputting raw features without any specific head on top."""   ,     lowercase_   ,     )
class 		UpperCAmelCase   (				lowercase_):


  """simple docstring"""







  def __init__(				self    :					Dict							,	UpperCamelCase__    :					RegNetConfig							,	*UpperCamelCase__    :					Union[str, Any]							,	**UpperCamelCase__    :					Any  )     ->						str:
    super().__init__(UpperCamelCase__							,	*UpperCamelCase__							,	**UpperCamelCase__  )
    _UpperCamelCase       			=TFRegNetMainLayer(UpperCamelCase__							,	name='''regnet'''  )




  @unpack_inputs
  @add_start_docstrings_to_model_forward(UpperCamelCase__  )
  @add_code_sample_docstrings(
      checkpoint=_CHECKPOINT_FOR_DOC							,	output_type=UpperCamelCase__							,	config_class=_CONFIG_FOR_DOC							,	modality='''vision'''							,	expected_output=_EXPECTED_OUTPUT_SHAPE							,	)
  def   UpperCamelCase__      (				self    :					Optional[Any]							,	UpperCamelCase__    :					tf.Tensor							,	UpperCamelCase__    :					Optional[bool] = None							,	UpperCamelCase__    :					Optional[bool] = None							,	UpperCamelCase__    :					str=False							,	)     ->						Union[TFBaseModelOutputWithPoolingAndNoAttention, Tuple[tf.Tensor]]:
    _UpperCamelCase       			=(
        output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    )
    _UpperCamelCase       			=return_dict if return_dict is not None else self.config.use_return_dict

    _UpperCamelCase       			=self.regnet(
        pixel_values=UpperCamelCase__							,	output_hidden_states=UpperCamelCase__							,	return_dict=UpperCamelCase__							,	training=UpperCamelCase__							,	)
    if not return_dict:
      return (outputs[0],) + outputs[1:]

    return TFBaseModelOutputWithPoolingAndNoAttention(
        last_hidden_state=outputs.last_hidden_state							,	pooler_output=outputs.pooler_output							,	hidden_states=outputs.hidden_states							,	)







@add_start_docstrings(
    """
    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    """   ,     lowercase_   ,     )
class 		UpperCAmelCase   (				lowercase_   ,     lowercase_):


  """simple docstring"""







  def __init__(				self    :					Union[str, Any]							,	UpperCamelCase__    :					RegNetConfig							,	*UpperCamelCase__    :					int							,	**UpperCamelCase__    :					List[str]  )     ->						Union[str, Any]:
    super().__init__(UpperCamelCase__							,	*UpperCamelCase__							,	**UpperCamelCase__  )
    _UpperCamelCase       			=config.num_labels
    _UpperCamelCase       			=TFRegNetMainLayer(UpperCamelCase__							,	name='''regnet'''  )
    # classification head
    _UpperCamelCase       			=[
        tf.keras.layers.Flatten(),
        tf.keras.layers.Dense(config.num_labels							,	name='''classifier.1'''  ) if config.num_labels > 0 else tf.identity,
    ]




  @unpack_inputs
  @add_start_docstrings_to_model_forward(UpperCamelCase__  )
  @add_code_sample_docstrings(
      checkpoint=_IMAGE_CLASS_CHECKPOINT							,	output_type=UpperCamelCase__							,	config_class=_CONFIG_FOR_DOC							,	expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT							,	)
  def   UpperCamelCase__      (				self    :					int							,	UpperCamelCase__    :					tf.Tensor = None							,	UpperCamelCase__    :					tf.Tensor = None							,	UpperCamelCase__    :					bool = None							,	UpperCamelCase__    :					bool = None							,	UpperCamelCase__    :					Optional[int]=False							,	)     ->						Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]:
    _UpperCamelCase       			=(
        output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    )
    _UpperCamelCase       			=return_dict if return_dict is not None else self.config.use_return_dict

    _UpperCamelCase       			=self.regnet(
        UpperCamelCase__							,	output_hidden_states=UpperCamelCase__							,	return_dict=UpperCamelCase__							,	training=UpperCamelCase__  )

    _UpperCamelCase       			=outputs.pooler_output if return_dict else outputs[1]

    _UpperCamelCase       			=self.classifier[0](UpperCamelCase__  )
    _UpperCamelCase       			=self.classifier[1](UpperCamelCase__  )

    _UpperCamelCase       			=None if labels is None else self.hf_compute_loss(labels=UpperCamelCase__							,	logits=UpperCamelCase__  )

    if not return_dict:
      _UpperCamelCase       			=(logits,) + outputs[2:]
      return ((loss,) + output) if loss is not None else output

    return TFSequenceClassifierOutput(loss=UpperCamelCase__							,	logits=UpperCamelCase__							,	hidden_states=outputs.hidden_states  )













'''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()






