o
    Æ µi«  ã                   @   sD   d dl mZ d dlmZ d dlmZ d dlmZ G dd„ deƒZdS )é    )ÚAny)Ú_C)Údtype)ÚInputc                       sL   e Zd ZdZdededdf‡ fdd„Zdefdd	„Zdej	fd
d„Z
‡  ZS )ÚTorchScriptInputa   
    Defines an input to a module in terms of expected shape, data type and tensor format.

    Attributes:
        shape_mode (torch_tensorrt.Input._ShapeMode): Is input statically or dynamically shaped
        shape (Tuple or Dict): Either a single Tuple or a dict of tuples defining the input shape.
            Static shaped inputs will have a single tuple. Dynamic inputs will have a dict of the form
            ``{
                "min_shape": Tuple,
                "opt_shape": Tuple,
                "max_shape": Tuple
            }``
        dtype (torch_tensorrt.dtype): The expected data type of the input tensor (default: torch_tensorrt.dtype.float32)
        format (torch_tensorrt.TensorFormat): The expected format of the input tensor (default: torch_tensorrt.TensorFormat.NCHW)
    ÚargsÚkwargsÚreturnNc                    s   t ƒ j|i |¤Ž dS )a=  __init__ Method for torch_tensorrt.Input

        Input accepts one of a few construction patterns

        Args:
            shape (Tuple or List, optional): Static shape of input tensor

        Keyword Arguments:
            shape (Tuple or List, optional): Static shape of input tensor
            min_shape (Tuple or List, optional): Min size of input tensor's shape range
                Note: All three of min_shape, opt_shape, max_shape must be provided, there must be no positional arguments, shape must not be defined and implicitly this sets Input's shape_mode to DYNAMIC
            opt_shape (Tuple or List, optional): Opt size of input tensor's shape range
                Note: All three of min_shape, opt_shape, max_shape must be provided, there must be no positional arguments, shape must not be defined and implicitly this sets Input's shape_mode to DYNAMIC
            max_shape (Tuple or List, optional): Max size of input tensor's shape range
                Note: All three of min_shape, opt_shape, max_shape must be provided, there must be no positional arguments, shape must not be defined and implicitly this sets Input's shape_mode to DYNAMIC
            dtype (torch.dtype or torch_tensorrt.dtype): Expected data type for input tensor (default: torch_tensorrt.dtype.float32)
            format (torch.memory_format or torch_tensorrt.TensorFormat): The expected format of the input tensor (default: torch_tensorrt.TensorFormat.NCHW)
            tensor_domain (Tuple(float, float), optional): The domain of allowed values for the tensor, as interval notation: [tensor_domain[0], tensor_domain[1]).
                Note: Entering "None" (or not specifying) will set the bound to [0, 2)

        Examples:
            - Input([1,3,32,32], dtype=torch.float32, format=torch.channel_last)
            - Input(shape=(1,3,32,32), dtype=torch_tensorrt.dtype.int32, format=torch_tensorrt.TensorFormat.NCHW)
            - Input(min_shape=(1,3,32,32), opt_shape=[2,3,32,32], max_shape=(3,3,32,32)) #Implicitly dtype=torch_tensorrt.dtype.float32, format=torch_tensorrt.TensorFormat.NCHW
        N)ÚsuperÚ__init__)Úselfr   r   ©Ú	__class__© úL/home/ubuntu/.local/lib/python3.10/site-packages/torch_tensorrt/ts/_Input.pyr      s   zTorchScriptInput.__init__c                 C   s   t | jtjkƒS )N)Úboolr   Úlong)r   r   r   r   Úis_trt_dtype5   s   zTorchScriptInput.is_trt_dtypec                 C   sF  t  ¡ }| jtjjkrlt| jtƒrkt 	| jd ¡s(t
dtt| jd ƒƒ d ƒ‚| jd |_t 	| jd ¡sEt
dtt| jd ƒƒ d ƒ‚| jd |_t 	| jd ¡sbt
dtt| jd ƒƒ d ƒ‚| jd |_d|_nt 	| j¡st
dtt| jƒƒ d	 ƒ‚| j|_d
|_| j t j¡|_| j|_| j t j¡|_t | j¡|_|S )NÚ	min_shapezbInput shape specifications for inputs are required to be a List, tuple or torch.Size, found type: z for min_shapeÚ	opt_shapez for opt_shapeÚ	max_shapez for max_shapeTz
 for shapeF)r   r   Ú
shape_modeÚ
_ShapeModeÚDYNAMICÚ
isinstanceÚshapeÚdictr   Ú_supported_input_size_typeÚ	TypeErrorÚstrÚtypeÚminÚoptÚmaxÚinput_is_dynamicr   ÚtoÚ_explicit_set_dtypeÚformatÚTensorFormatÚ_parse_tensor_domainÚtensor_domain)r   Úinternal_inr   r   r   Ú_to_internal8   sn   ÿÿþÿÿÿþÿÿÿþÿ€ÿþÿÿzTorchScriptInput._to_internal)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r,   Ú__classcell__r   r   r   r   r      s
    r   N)	Útypingr   Útorch_tensorrtr   Útorch_tensorrt._enumsr   Útorch_tensorrt._Inputr   r   r   r   r   r   Ú<module>   s
    