code: def test_backprop(self):
      device_opt = core.DeviceOption(caffe2_pb2.IDEEP, 0)
      with core.DeviceScope(device_opt):
          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.Mul(["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) * Y).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
          )
  
file_path: pytorch/caffe2/python/ideep/reshape_op_test.py
imports: from caffe2.python.test_util import TestCase
  from caffe2.proto import caffe2_pb2
  import unittest
  import numpy
  from caffe2.python import core, workspace
label_desc: Use image node_id 8 for calling the TestReShapeOps obj's underlying member method code with example usage: obj.test_backprop() without return types