class_docstr: .. note::
      This class should not be instantiated directly; use :func:`Constant` function
      with appropriate arguments to create instances of this class.
  
  Wrapper for a constant value that can be used in DALI :ref:`mathematical expressions`
  and applied element-wise to the results of DALI Operators representing Tensors in
  :meth:`nvidia.dali.Pipeline.define_graph` step.
  
  ScalarConstant indicates what type should the value be treated as with respect
  to type promotions. The actual values passed to the backend from python
  would be `int32` for integer values and `float32` for floating point values.
  Python builtin types `bool`, `int` and `float` will be marked to indicate
  :const:`nvidia.dali.types.DALIDataType.BOOL`, :const:`nvidia.dali.types.DALIDataType.INT32`,
  and :const:`nvidia.dali.types.DALIDataType.FLOAT` respectively.
  
  Args
  ----
  value: bool or int or float
      The constant value to be passed to DALI expression.
  dtype: DALIDataType, optional
      Target type of the constant to be used in types promotions.
class_docstr_tok: ["..","note",":",":","This","class","should","not","be","instantiated","directly",";","use",":","func",":","`","Constant","`","function","with","appropriate","arguments","to","create","instances","of","this","class",".","Wrapper","for","a","constant","value","that","can","be","used","in","DALI",":","ref",":","`","mathematical","expressions","`","and","applied","element-wise","to","the","results","of","DALI","Operators","representing","Tensors","in",":","meth",":","`","nvidia.dali.Pipeline.define_graph","`","step",".","ScalarConstant","indicates","what","type","should","the","value","be","treated","as","with","respect","to","type","promotions",".","The","actual","values","passed","to","the","backend","from","python","would","be","`","int32","`","for","integer","values","and","`","float32","`","for","floating","point","values",".","Python","builtin","types","`","bool","`",",","`","int","`","and","`","float","`","will","be","marked","to","indicate",":","const",":","`","nvidia.dali.types.DALIDataType.BOOL","`",",",":","const",":","`","nvidia.dali.types.DALIDataType.INT32","`",",","and",":","const",":","`","nvidia.dali.types.DALIDataType.FLOAT","`","respectively",".","Args","--","--","value",":","bool","or","int","or","float","The","constant","value","to","be","passed","to","DALI","expression",".","dtype",":","DALIDataType",",","optional","Target","type","of","the","constant","to","be","used","in","types","promotions","."]
code: def __init__(self, value, dtype=None):
      self.shape = []
      value_dtype = getattr(
          value, "dtype", None
      )  # handle 0D tensors and numpy scalars
      if value_dtype is not None:
          dali_type = to_dali_type(value.dtype)
          if dali_type in _int_types:
              value = int(value)
          elif dali_type in _float_types:
              value = float(value)
          elif dali_type in _bool_types:
              value = bool(value)
          if dtype is None:
              dtype = dali_type
  
      if not isinstance(value, (bool, int, float)):
          raise TypeError(
              f"Expected scalar value of type 'bool', 'int' or 'float', got {type(value)}."
          )
  
      if dtype:
          self.dtype = dtype
          if self.dtype in _bool_types:
              self.value = bool(value)
          elif self.dtype in _int_types:
              self.value = int(value)
          elif self.dtype in _float_types:
              self.value = float(value)
          else:
              raise TypeError(
                  f"DALI ScalarConstant can only hold one of: {_all_types} types."
              )
      elif isinstance(value, bool):
          self.value = value
          self.dtype = DALIDataType.BOOL
      elif isinstance(value, int):
          self.value = value
          self.dtype = DALIDataType.INT32
      elif isinstance(value, float):
          self.value = value
          self.dtype = DALIDataType.FLOAT
  
imports: from enum import Enum, unique
  import re
  from nvidia.dali._backend_enums import DALIDataType, DALIImageType, DALIInterpType
  from nvidia.dali.backend_impl.types import *
label_desc: Use image node_id 1 to create a new ScalarConstant object from inherited base classes: object with example: obj = ScalarConstant(value, dtype)