code: def test_sparse_lengths_weightedsum_cpu(
      self,
      batchsize,
      fptype,
      fp16asint,
      blocksize,
      empty_indices,
      gc,
      dc,
  ):
      if fptype != np.float32:
          assume(gc.device_type == caffe2_pb2.CPU)
          assume(not hiputl.run_in_hip(gc, dc))
          assume(caffe2_pb2.CUDA not in {d.device_type for d in dc})
  
      print("<test_sparse_lengths_weightedsum_cpu>")
  
      tblsize = 300
      if fptype == np.float32:
          Tbl = np.random.rand(tblsize, blocksize).astype(np.float32)
          atol = 1e-5
      else:
          if fp16asint:
              Tbl = (
                  (10.0 * np.random.rand(tblsize, blocksize))
                  .round()
                  .astype(np.float16)
              )
              atol = 1e-3
          else:
              Tbl = np.random.rand(tblsize, blocksize).astype(
                  np.float16
              )
              atol = 1e-1
  
      # array of each row length
      if empty_indices:
          Lengths = np.zeros(batchsize, dtype=np.int32)
      else:
          Lengths = np.random.randint(
              1, 30, size=batchsize, dtype=np.int32
          )
      # flat indices
      Indices = np.random.randint(
          0, tblsize, size=sum(Lengths), dtype=np.int64
      )
      Weights = np.random.rand(sum(Lengths)).astype(np.float32)
  
      op = core.CreateOperator(
          "SparseLengthsWeightedSum",
          ["Tbl", "Weights", "Indices", "Lengths"],
          "out",
      )
  
      def sparse_lengths_weightedsum_ref(
          Tbl, Weights, Indices, Lengths
      ):
          rptr = np.cumsum(np.insert(Lengths, [0], [0]))
          out = np.zeros((len(Lengths), blocksize))
          for i in range(0, len(rptr[0:-1])):
              w = Weights[rptr[i] : rptr[i + 1]]
              out[i] = (
                  Tbl[Indices[rptr[i] : rptr[i + 1]]] * w[:, np.newaxis]
              ).sum(axis=0)
          return [out.astype(np.float32)]
  
      self.assertReferenceChecks(
          gc,
          op,
          [Tbl, Weights, Indices, Lengths],
          sparse_lengths_weightedsum_ref,
          threshold=1e-3,
          atol=atol,
      )
  
file_path: pytorch/caffe2/python/operator_test/specialized_segment_ops_test.py
imports: import unittest
  from caffe2.proto import caffe2_pb2
  from caffe2.python import core
  import caffe2.python.hip_test_util
  import caffe2.python.hypothesis_test_util
  import hypothesis.strategies
  import numpy
  from hypothesis import given, assume, settings
label_desc: Use image node_id 2 for calling the TestSpecializedSegmentOps obj's underlying member method code with example usage: obj.test_sparse_lengths_weightedsum_cpu(batchsize, fptype, fp16asint, blocksize, empty_indices, gc, dc) and returns: list