code: def _reshape_weights(X, sample_weight, device="cpu"):
      """Handle a sample weight tensor by creating and reshaping it.
  
      This function will take any weight input, including None, 1D weights, and
      2D weights, and shape it into a 2D matrix with the same shape as the data
      X also passed in.
  
      Both elements must be PyTorch tensors.
  
  
      Parameters
      ----------
      X: torch.tensor, ndims=2
              The data being weighted. The contents of this tensor are not used, only
              the shape is.
  
      sample_weight: torch.tensor or None
              The weight for each element in the data or None.
  
  
      Returns
      -------
      sample_weight: torch.tensor, shape=X.shape
              A tensor with the same dimensions as X with elements repeated as
              necessary.
      """
  
      if sample_weight is None:
          if torch.is_floating_point(X):
              sample_weight = torch.ones(
                  1, device=device, dtype=X.dtype
              ).expand(*X.shape)
          else:
              sample_weight = torch.ones(
                  1, device=device, dtype=torch.float32
              ).expand(*X.shape)
      else:
          if not torch.is_floating_point(sample_weight):
              sample_weight = sample_weight.type(torch.float32)
  
      if len(sample_weight.shape) == 1:
          sample_weight = sample_weight.reshape(-1, 1).expand(
              -1, X.shape[1]
          )
          _check_parameter(sample_weight, "sample_weight", min_value=0)
  
      elif sample_weight.shape[1] == 1:
          sample_weight = sample_weight.expand(-1, X.shape[1])
          _check_parameter(sample_weight, "sample_weight", min_value=0)
  
      if isinstance(X, torch.masked.MaskedTensor):
          if not isinstance(sample_weight, torch.masked.MaskedTensor):
              sample_weight = torch.masked.MaskedTensor(
                  sample_weight, mask=X._masked_mask
              )
  
      _check_parameter(
          sample_weight, "sample_weight", shape=X.shape, ndim=X.ndim
      )
      return sample_weight
  
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 7 for calling a global function with example usage: _reshape_weights(X, sample_weight, device) and returns: sample_weight