code: def _cast_as_tensor(value, dtype=None):
      """Set the parameter."""
  
      if value is None:
          return None
  
      if isinstance(
          value,
          (torch.nn.Parameter, torch.Tensor, torch.masked.MaskedTensor),
      ):
          if dtype is None:
              return value
          elif value.dtype == dtype:
              return value
          else:
              return value.type(dtype)
  
      if isinstance(value, list) and all(
          isinstance(v, numpy.ndarray) for v in value
      ):
          value = numpy.array(value)
  
      if isinstance(value, (float, int, list, tuple, numpy.ndarray)):
          if dtype is None:
              return torch.tensor(value)
          else:
              return torch.tensor(value, dtype=dtype)
  
file_path: pomegranate/pomegranate/_utils.py
imports: import numpy
  import torch
  import collections
  from apricot import FacilityLocationSelection
  from apricot import FeatureBasedSelection
label_desc: Use image node_id 2 for calling a global function with example usage: _cast_as_tensor(value, dtype) and returns: None, value, torch, torch, value, value