code: def sparse_lengths_weighted_sum_ref(D, W, I, L):
      R = np.zeros(shape=(len(L),) + D.shape[1:], dtype=D.dtype)
      line = 0
      for g in range(len(L)):
          for _ in range(L[g]):
              if len(D.shape) > 1:
                  R[g, :] += W[line] * D[I[line], :]
              else:
                  R[g] += W[line] * D[I[line]]
              line += 1
      return [R]
  
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 11 for calling a global function with example usage: sparse_lengths_weighted_sum_ref(D, W, I, L) and returns: list