



"""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      	=						logging.get_logger(__name__)

# General docstring
lowerCamelCase      	=						"""RegNetConfig"""

# Base docstring
lowerCamelCase      	=						"""facebook/regnet-y-040"""
lowerCamelCase      	=						[1, 1_088, 7, 7]

# Image classification docstring
lowerCamelCase      	=						"""facebook/regnet-y-040"""
lowerCamelCase      	=						"""tabby, tabby cat"""

lowerCamelCase      	=						[
    """facebook/regnet-y-040""",
    # See all regnet models at https://huggingface.co/models?filter=regnet
]
class 				lowercase__       (   tf.keras.layers.Layer				):







       '''simple docstring'''


       def __init__(							self      :  str		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int = 3		,    _UpperCAmelCase      :  int = 1		,    _UpperCAmelCase      :  int = 1		,    _UpperCAmelCase      :  Optional[str] = "relu"		,    **_UpperCAmelCase      :  Any		,    )			->						List[Any]:


             '''simple docstring'''




             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 					lowercase__    (							self      :  Optional[Any]		,    _UpperCAmelCase      :  int   )			->						Any:


             '''simple docstring'''




             UpperCAmelCase_      			=							self.convolution(self.padding(_UpperCAmelCase   )   )
             UpperCAmelCase_      			=							self.normalization(_UpperCAmelCase   )
             UpperCAmelCase_      			=							self.activation(_UpperCAmelCase   )
             return hidden_state



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







       '''simple docstring'''


       def __init__(							self      :  List[Any]		,    _UpperCAmelCase      :  RegNetConfig		,    **_UpperCAmelCase      :  Any   )			->						Optional[Any]:


             '''simple docstring'''




             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 					lowercase__    (							self      :  Optional[Any]		,    _UpperCAmelCase      :  str   )			->						List[Any]:


             '''simple docstring'''




             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 				lowercase__       (   tf.keras.layers.Layer				):







       '''simple docstring'''


       def __init__(							self      :  List[str]		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int = 2		,    **_UpperCAmelCase      :  Any   )			->						Optional[Any]:


             '''simple docstring'''




             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 					lowercase__    (							self      :  Union[str, Any]		,    _UpperCAmelCase      :  tf.Tensor		,    _UpperCAmelCase      :  bool = False   )			->						tf.Tensor:


             '''simple docstring'''




             return self.normalization(self.convolution(_UpperCAmelCase   )		,    training=_UpperCAmelCase   )



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







       '''simple docstring'''


       def __init__(							self      :  Optional[int]		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  int   )			->						str:


             '''simple docstring'''




             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 					lowercase__    (							self      :  Union[str, Any]		,    _UpperCAmelCase      :  List[Any]   )			->						Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_      			=							self.pooler(_UpperCAmelCase   )
             for layer_module in self.attention:
                   UpperCAmelCase_      			=							layer_module(_UpperCAmelCase   )
             UpperCAmelCase_      			=							hidden_state * pooled
             return hidden_state



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







       '''simple docstring'''


       def __init__(							self      :  Any		,    _UpperCAmelCase      :  RegNetConfig		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int = 1		,    **_UpperCAmelCase      :  Optional[Any]   )			->						Optional[int]:


             '''simple docstring'''




             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 					lowercase__    (							self      :  int		,    _UpperCAmelCase      :  Dict   )			->						List[str]:


             '''simple docstring'''




             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 				lowercase__       (   tf.keras.layers.Layer				):







       '''simple docstring'''


       def __init__(							self      :  Optional[Any]		,    _UpperCAmelCase      :  RegNetConfig		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int = 1		,    **_UpperCAmelCase      :  List[Any]   )			->						Dict:


             '''simple docstring'''




             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 					lowercase__    (							self      :  Dict		,    _UpperCAmelCase      :  str   )			->						Optional[int]:


             '''simple docstring'''




             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 				lowercase__       (   tf.keras.layers.Layer				):







       '''simple docstring'''


       def __init__(							self      :  Optional[Any]		,    _UpperCAmelCase      :  RegNetConfig		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int		,    _UpperCAmelCase      :  int = 2		,    _UpperCAmelCase      :  int = 2		,    **_UpperCAmelCase      :  Union[str, Any]   )			->						List[str]:


             '''simple docstring'''




             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 					lowercase__    (							self      :  Optional[int]		,    _UpperCAmelCase      :  int   )			->						str:


             '''simple docstring'''




             for layer_module in self.layers:
                   UpperCAmelCase_      			=							layer_module(_UpperCAmelCase   )
             return hidden_state



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







       '''simple docstring'''


       def __init__(							self      :  Optional[Any]		,    _UpperCAmelCase      :  RegNetConfig		,    **_UpperCAmelCase      :  List[Any]   )			->						Dict:


             '''simple docstring'''




             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 					lowercase__    (							self      :  List[str]		,    _UpperCAmelCase      :  tf.Tensor		,    _UpperCAmelCase      :  bool = False		,    _UpperCAmelCase      :  bool = True   )			->						TFBaseModelOutputWithNoAttention:


             '''simple docstring'''




             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 				lowercase__       (   tf.keras.layers.Layer				):







       '''simple docstring'''


       UpperCamelCase						=					RegNetConfig



       def __init__(							self      :  List[str]		,    _UpperCAmelCase      :  Optional[Any]		,    **_UpperCAmelCase      :  Union[str, Any]   )			->						Tuple:


             '''simple docstring'''




             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 					lowercase__    (							self      :  Optional[Any]		,    _UpperCAmelCase      :  tf.Tensor		,    _UpperCAmelCase      :  Optional[bool] = None		,    _UpperCAmelCase      :  Optional[bool] = None		,    _UpperCAmelCase      :  bool = False		,    )			->						TFBaseModelOutputWithPoolingAndNoAttention:


             '''simple docstring'''




             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 				lowercase__       (   SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					RegNetConfig
       UpperCamelCase						=					'''regnet'''
       UpperCamelCase						=					'''pixel_values'''



       @property
       def 					lowercase__    (							self      :  int   )			->						List[Any]:


             '''simple docstring'''




             return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)		,    dtype=tf.floataa   )}



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

lowerCamelCase      	=						r"""
    Args:
        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConveNextImageProcessor.__call__`] for details.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
"""
@add_start_docstrings(
    '''The bare RegNet model outputting raw features without any specific head on top.'''    , SCREAMING_SNAKE_CASE    , )
class 				lowercase__       (   SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       def __init__(							self      :  List[str]		,    _UpperCAmelCase      :  RegNetConfig		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  List[Any]   )			->						Any:


             '''simple docstring'''




             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 					lowercase__    (							self      :  List[str]		,    _UpperCAmelCase      :  tf.Tensor		,    _UpperCAmelCase      :  Optional[bool] = None		,    _UpperCAmelCase      :  Optional[bool] = None		,    _UpperCAmelCase      :  Optional[Any]=False		,    )			->						Union[TFBaseModelOutputWithPoolingAndNoAttention, Tuple[tf.Tensor]]:


             '''simple docstring'''




             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.
    '''    , SCREAMING_SNAKE_CASE    , )
class 				lowercase__       (   SCREAMING_SNAKE_CASE    , SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       def __init__(							self      :  List[Any]		,    _UpperCAmelCase      :  RegNetConfig		,    *_UpperCAmelCase      :  List[Any]		,    **_UpperCAmelCase      :  Tuple   )			->						str:


             '''simple docstring'''




             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 					lowercase__    (							self      :  str		,    _UpperCAmelCase      :  tf.Tensor = None		,    _UpperCAmelCase      :  tf.Tensor = None		,    _UpperCAmelCase      :  bool = None		,    _UpperCAmelCase      :  bool = None		,    _UpperCAmelCase      :  Tuple=False		,    )			->						Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]:


             '''simple docstring'''




             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 Iterable
from typing import Generic, TypeVar

lowerCamelCase       	=						TypeVar("""_T""")
class 				lowercase__       (   Generic[_T]				):







       '''simple docstring'''


       def __init__(							self      :  int		,    _UpperCAmelCase      :  Iterable[_T] | None = None   )			->						None:


             '''simple docstring'''




             UpperCAmelCase_      			=							list(iterable or []   )
             UpperCAmelCase_      			=							[]



       def __len__(							self      :  Optional[int]   )			->						int:


             '''simple docstring'''




             return len(self._stacka   ) + len(self._stacka   )



       def __repr__(							self      :  Optional[Any]   )			->						str:


             '''simple docstring'''




             return F"""Queue({tuple(self._stacka[::-1] + self._stacka   )})"""



       def 					lowercase__    (							self      :  Optional[Any]		,    _UpperCAmelCase      :  _T   )			->						None:


             '''simple docstring'''




             self._stacka.append(_UpperCAmelCase   )







       def 					lowercase__    (							self      :  Dict   )			->						_T:


             '''simple docstring'''




             UpperCAmelCase_      			=							self._stacka.pop
             UpperCAmelCase_      			=							self._stacka.append

             if not self._stacka:
                   while self._stacka:
                         stacka_append(stacka_pop()   )

             if not self._stacka:
                   raise IndexError("Queue is empty"   )
             return self._stacka.pop()


if __name__ == "__main__":
  from doctest import testmod

  testmod()




