code: def test_sparse_lengths_weighted_sum(
      self, grad_on_weights, inputs, seed, gc, dc
  ):
      D, I, L = inputs
  
      np.random.seed(int(seed))
  
      W = np.random.rand(I.size).astype(np.float32)
      op = core.CreateOperator(
          "SparseLengthsWeightedSum",
          ["D", "W", "I", "L"],
          "out",
          grad_on_weights=grad_on_weights,
      )
      self.assertDeviceChecks(dc, op, [D, W, I, L], [0])
      self.assertReferenceChecks(
          device_option=gc,
          op=op,
          inputs=[D, W, I, L],
          reference=sparse_lengths_weighted_sum_ref,
          threshold=1e-4,
          output_to_grad="out",
          grad_reference=partial(
              sparse_lengths_weighted_sum_grad_ref,
              grad_on_weights=grad_on_weights,
          ),
      )
      self.assertGradientChecks(gc, op, [D, W, I, L], 0, [0])
      if grad_on_weights:
          self.assertGradientChecks(gc, op, [D, W, I, L], 1, [0])
  
imports: from functools import partial
  from hypothesis import given, settings
  import numpy
  import unittest
  import hypothesis.strategies
  from caffe2.python import core, workspace
  import caffe2.python.hypothesis_test_util
  import caffe2.python.serialized_test.serialized_test_util
label_desc: Use image node_id 16 for calling the TestSegmentOps obj's underlying member method code with example usage: obj.test_sparse_lengths_weighted_sum(grad_on_weights, inputs, seed, gc, dc) without return types