code: def test_backprop(self):
      old_shape = (4, 2, 1)
      new_shape = (1, 8)
      X = np.random.rand(*old_shape).astype(np.float32)
      Y = np.random.rand(*new_shape).astype(np.float32)
  
      net = core.Net("net")
  
      net.GivenTensorFill([], "X", shape=old_shape, values=X.flatten())
      net.GivenTensorFill([], "Y", shape=new_shape, values=Y.flatten())
  
      net.Reshape(["X"], ["X_out", "old_shape"], shape=new_shape)
      net.DotProduct(["X_out", "Y"], "Z")
      net.AddGradientOperators(["Z"])
  
      workspace.RunNetOnce(net)
  
      Z = workspace.FetchBlob("Z")
      X_grad = workspace.FetchBlob("X_grad")
  
      # Check forward computation
      np.testing.assert_allclose(
          Z.squeeze(),
          X.reshape(new_shape).dot(Y.T).squeeze(),
          rtol=1e-5,
      )
  
      # Check the shape of the gradient
      np.testing.assert_array_equal(X_grad.shape, X.shape)
  
      # Check the gradient
      np.testing.assert_allclose(
          X_grad, Y.reshape(old_shape), rtol=1e-5
      )
  
imports: import numpy
  from numpy.testing import assert_array_equal
  from caffe2.python import core, workspace
  from caffe2.python.test_util import TestCase
  from caffe2.proto import caffe2_pb2
label_desc: Use image node_id 8 for calling the TestLengthsToShapeOps obj's underlying member method code with example usage: obj.test_backprop() without return types