docstr: Specify a (dense) tensor input.
  
  Parameters
  ----------
  name: str
      Input name. Must match an input name in the model (usually the
      Placeholder name for TensorFlow or the input name for PyTorch).
  
      The ``name`` is required except for a TensorFlow model in which there is
      exactly one input Placeholder.
  
  shape: The shape of the input
      - List of positive int or :py:class:`RangeDim`, or
      - :py:class:`EnumeratedShapes`
  
      For TensorFlow:
         * The ``shape`` is optional. If omitted, the shape is inferred from
           TensorFlow graph's Placeholder shape.
  
      For PyTorch:
         * The ``shape`` is required.
  
  dtype: np.generic or mil.type type
      For example, ``np.int32`` or ``coremltools.converters.mil.mil.types.fp32``
  
  default_value: np.ndarray
      If provided, the input is considered optional. At runtime, if the
      input is not provided, ``default_value`` is used.
  
      Limitations:
        *  If ``default_value`` is ``np.ndarray``, all
           elements are required to have the same value.
  
        * The ``default_value`` may not be specified if ``shape`` is
          :py:class:`EnumeratedShapes`.
  
  Examples
  --------
  * ``ct.TensorType(name="input", shape=(1, 2, 3))` implies `dtype ==
    np.float32``
  
  * ``ct.TensorType(name="input", shape=(1, 2, 3), dtype=np.int32)``
  
  * ``ct.TensorType(name="input", shape=(1, 2, 3),
    dtype=ct.converters.mil.types.fp32)``
docstr_tok: ["Specify","a","(","dense",")","tensor","input",".","Parameters","--","--","--","--","--","name",":","str","Input","name",".","Must","match","an","input","name","in","the","model","(","usually","the","Placeholder","name","for","TensorFlow","or","the","input","name","for","PyTorch",")",".","The","``","name","``","is","required","except","for","a","TensorFlow","model","in","which","there","is","exactly","one","input","Placeholder",".","shape",":","The","shape","of","the","input","-","List","of","positive","int","or",":","py",":","class",":","`","RangeDim","`",",","or","-",":","py",":","class",":","`","EnumeratedShapes","`","For","TensorFlow",":","*","The","``","shape","``","is","optional",".","If","omitted",",","the","shape","is","inferred","from","TensorFlow","graph","'s","Placeholder","shape",".","For","PyTorch",":","*","The","``","shape","``","is","required",".","dtype",":","np.generic","or","mil.type","type","For","example",",","``","np.int32","``","or","``","coremltools.converters.mil.mil.types.fp32","``","default_value",":","np.ndarray","If","provided",",","the","input","is","considered","optional",".","At","runtime",",","if","the","input","is","not","provided",",","``","default_value","``","is","used",".","Limitations",":","*","If","``","default_value","``","is","``","np.ndarray","``",",","all","elements","are","required","to","have","the","same","value",".","*","The","``","default_value","``","may","not","be","specified","if","``","shape","``","is",":","py",":","class",":","`","EnumeratedShapes","`",".","Examples","--","--","--","--","*","``","ct.TensorType","(","name=","''","input","''",",","shape=","(","1",",","2",",","3",")",")","`","implies","`","dtype","==","np.float32","``","*","``","ct.TensorType","(","name=","''","input","''",",","shape=","(","1",",","2",",","3",")",",","dtype=np.int32",")","``","*","``","ct.TensorType","(","name=","''","input","''",",","shape=","(","1",",","2",",","3",")",",","dtype=ct.converters.mil.types.fp32",")","``"]
code: def __init__(
      self, name=None, shape=None, dtype=None, default_value=None
  ):
      """
      Specify a (dense) tensor input.
  
      Parameters
      ----------
      name: str
          Input name. Must match an input name in the model (usually the
          Placeholder name for TensorFlow or the input name for PyTorch).
  
          The ``name`` is required except for a TensorFlow model in which there is
          exactly one input Placeholder.
  
      shape: The shape of the input
          - List of positive int or :py:class:`RangeDim`, or
          - :py:class:`EnumeratedShapes`
  
          For TensorFlow:
             * The ``shape`` is optional. If omitted, the shape is inferred from
               TensorFlow graph's Placeholder shape.
  
          For PyTorch:
             * The ``shape`` is required.
  
      dtype: np.generic or mil.type type
          For example, ``np.int32`` or ``coremltools.converters.mil.mil.types.fp32``
  
      default_value: np.ndarray
          If provided, the input is considered optional. At runtime, if the
          input is not provided, ``default_value`` is used.
  
          Limitations:
            *  If ``default_value`` is ``np.ndarray``, all
               elements are required to have the same value.
  
            * The ``default_value`` may not be specified if ``shape`` is
              :py:class:`EnumeratedShapes`.
  
      Examples
      --------
      * ``ct.TensorType(name="input", shape=(1, 2, 3))` implies `dtype ==
        np.float32``
  
      * ``ct.TensorType(name="input", shape=(1, 2, 3), dtype=np.int32)``
  
      * ``ct.TensorType(name="input", shape=(1, 2, 3),
        dtype=ct.converters.mil.types.fp32)``
      """
      super(TensorType, self).__init__(name, shape)
      if dtype is not None:
          if is_builtin(dtype):
              self.dtype = dtype
              if dtype not in (
                  types.int8,
                  types.uint8,
                  types.fp16,
                  types.fp32,
                  types.fp64,
                  types.int32,
                  types.int64,
                  types.bool,
              ):
                  raise TypeError(
                      "dtype={} is unsupported for inputs/outputs of the model".format(
                          dtype
                      )
                  )
          else:
              # Assume dtype is numpy type
              try:
                  self.dtype = numpy_type_to_builtin_type(dtype)
              except TypeError:
                  raise TypeError(
                      "dtype={} is unsupported".format(dtype)
                  )
              if dtype not in (
                  np.float16,
                  np.float32,
                  np.float64,
                  float,
                  np.int32,
                  np.int64,
                  int,
                  bool,
                  np.bool_,
              ):
                  raise TypeError(
                      "dtype={} is unsupported for inputs/outputs of the model".format(
                          dtype
                      )
                  )
  
      if default_value is not None:
          if isinstance(shape, EnumeratedShapes):
              msg = (
                  "TensorType input {} has EnumeratedShapes and "
                  + "may not be optional"
              )
              raise ValueError(msg.format(name))
          if not isinstance(default_value, np.ndarray):
              msg = "TensorType {} default_value is not np.ndarray"
              raise ValueError(msg.format(name))
          default_fill_val = default_value.flatten()[0]
          if not np.all(default_value == default_fill_val):
              msg = (
                  "TensorType {} default_value can only have "
                  + "same entries"
              )
              raise ValueError(msg.format(name))
          if not self.shape.has_symbolic and list(
              default_value.shape
          ) != list(self.shape.symbolic_shape):
              msg = (
                  "TensorType {} default_value shape {} != "
                  + "TensorType.shape {}"
              )
              raise ValueError(
                  msg.format(
                      name, default_value.shape, self.shape.to_list()
                  )
              )
          if (
              self.dtype is not None
              and numpy_type_to_builtin_type(default_value.dtype)
              != self.dtype
          ):
              msg = (
                  "TensorType {} default_value dtype {} != "
                  + "TensorType.dtype {}"
              )
              raise ValueError(
                  msg.format(
                      name,
                      default_value.dtype,
                      self.dtype.__type_info__(),
                  )
              )
          else:
              self.dtype = numpy_type_to_builtin_type(
                  default_value.dtype
              )
  
      self.default_value = default_value
  
imports: from enum import Enum
  from typing import Optional
  import numpy
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.mil.types.symbolic import is_symbolic
  from coremltools.converters.mil.mil.types.type_mapping import is_builtin, numpy_type_to_builtin_type
label_desc: Use image node_id 1 to create a new TensorType object from inherited base classes: InputType with example: obj = TensorType(name, shape, dtype, default_value)