import torch


def heaviside(X):
  """
    A pytorch-differentiable version of the Heaviside function

    .. math::
      
      H\\left(x\\right) = \\frac{\\operatorname{sign}(x) + 1)}{2}

    Args:
      X:        tensor input
  """
  return (torch.sign(X) + 1.0) / 2.0