code: def occnumber(
      a: ZType,
      n: Optional[int] = None,
      dtype: torch.dtype = torch.double,
      device: torch.device = torch.device("cpu"),
  ) -> torch.Tensor:
      """Occupation number (maxed at 1) where the total sum of the
      output equals to a with length of the output is n.
  
      Examples
      --------
      >>> import torch
      >>> occnumber(torch.tensor(2.5), 3, torch.double, torch.device('cpu'))
      tensor([1.0000, 1.0000, 0.5000], dtype=torch.float64)
      >>> occnumber(2.5)
      tensor([1.0000, 1.0000, 0.5000], dtype=torch.float64)
  
      Parameters
      ----------
      a: ZType
          Total sum of the output
      n: Optional[int] (default None)
          Length of the output
      dtype: torch.dtype (default torch.double)
          Data type of the output
      device: torch.device (default torch.device('cpu'))
          Device of the output
  
      Returns
      -------
      torch.Tensor
          The constructed occupation number
  
      """
  
      if isinstance(a, torch.Tensor):
          assert a.numel() == 1
          floor_a, ceil_a = get_floor_and_ceil(a.item())
      else:  # int or float
          floor_a, ceil_a = get_floor_and_ceil(a)
  
      # get the length of the tensor output
      if n is None:
          nlength = ceil_a
      else:
          nlength = n
          assert nlength >= ceil_a, (
              "The length of occupation number must be at least %d"
              % ceil_a
          )
  
      if isinstance(a, torch.Tensor):
          res = _OccNumber.apply(
              a, floor_a, ceil_a, nlength, dtype, device
          )
      else:
          res = _construct_occ_number(
              a, floor_a, ceil_a, nlength, dtype=dtype, device=device
          )
      return res
  
file_path: deepchem/deepchem/utils/safeops_utils.py
imports: import math
  import torch
  from typing import Union, Optional, Tuple
label_desc: Use image node_id 3 for calling a global function with example usage: occnumber(a, n, dtype, device) and returns: res