code: def hardtanh(
      a: TensorLikeType,
      min_val: NumberType = -1,
      max_val: NumberType = 1,
      inplace: bool = False,
  ) -> TensorLikeType:
      """
      Reference implementation of torch.nn.functional.hardtanh
      """
      if inplace:
          raise NotImplementedError
      if utils.is_boolean_dtype(a.dtype):
          raise RuntimeError("Bool inputs not supported for hardtanh")
  
      # preserve legacy behavior of boundaries not causing type promotion
      if utils.is_integer_dtype(a.dtype):
          min_val = int(min_val)  # type: ignore[arg-type]
          max_val = int(max_val)  # type: ignore[arg-type]
          if not (
              a.dtype != torch.uint8 or (min_val >= 0 and max_val >= 0)
          ):
              raise RuntimeError(
                  "Cannot do hardtanh on an unsigned type with negative limits"
              )
      return torch.clamp(a, min_val, max_val)
  
imports: import math
  from functools import wraps
  from typing import Callable, Optional, Union
  import torch
  import torch._prims
  import torch._prims_common
  import torch._refs
  from torch._decomp import register_decomposition
  from torch._prims_common import ELEMENTWISE_TYPE_PROMOTION_KIND, NumberType, ShapeType, TensorLike, TensorLikeType
  from torch._prims_common.wrappers import elementwise_type_promotion_wrapper, elementwise_unary_scalar_wrapper, out_wrapper
  from torch._refs import _make_inplace
label_desc: Use image node_id 35 for calling a global function with example usage: hardtanh(a, min_val, max_val, inplace) and returns: torch