code: def test_sum_reduce(self, gc, dc):
      # Set broadcast and no axis, i.e. broadcasting last dimensions.
      X = np.random.rand(2, 3, 4, 5).astype(np.float32)
      Y = np.random.rand(4, 5).astype(np.float32)
      op = core.CreateOperator(
          "SumReduceLike", ["X", "Y"], "out", broadcast=1
      )
      workspace.FeedBlob("X", X)
      workspace.FeedBlob("Y", Y)
      workspace.RunOperatorOnce(op)
      out = workspace.FetchBlob("out")
      res = np.sum(X, axis=0)
      res = np.sum(res, axis=0)
      np.testing.assert_array_almost_equal(out, res)
      self.assertDeviceChecks(dc, op, [X, Y], [0])
  
      # Set broadcast and no axis, i.e. broadcasting last dimensions.
      X = np.random.rand(2, 3, 4, 5).astype(np.float32)
      Y = np.random.rand(2, 3).astype(np.float32)
      op = core.CreateOperator(
          "SumReduceLike", ["X", "Y"], "out", broadcast=1, axis=0
      )
      workspace.FeedBlob("X", X)
      workspace.FeedBlob("Y", Y)
      workspace.RunOperatorOnce(op)
      out = workspace.FetchBlob("out")
      res = np.sum(X, axis=3)
      res = np.sum(res, axis=2)
      np.testing.assert_array_almost_equal(out, res, decimal=3)
      self.assertDeviceChecks(dc, op, [X, Y], [0])
  
      # broadcasting intermediate dimensions
      X = np.random.rand(2, 3, 4, 5).astype(np.float32)
      Y = np.random.rand(3, 4).astype(np.float32)
      op = core.CreateOperator(
          "SumReduceLike", ["X", "Y"], "out", broadcast=1, axis=1
      )
      workspace.FeedBlob("X", X)
      workspace.FeedBlob("Y", Y)
      workspace.RunOperatorOnce(op)
      out = workspace.FetchBlob("out")
      res = np.sum(X, axis=0)
      res = np.sum(res, axis=2)
      np.testing.assert_array_almost_equal(out, res)
      self.assertDeviceChecks(dc, op, [X, Y], [0])
  
      # broadcasting intermediate dimensions
      X = np.random.rand(2, 3, 4, 500).astype(np.float64)
      Y = np.random.rand(1).astype(np.float64)
      op = core.CreateOperator(
          "SumReduceLike", ["X", "Y"], "out", broadcast=1
      )
      workspace.FeedBlob("X", X)
      workspace.FeedBlob("Y", Y)
      workspace.RunOperatorOnce(op)
      out = workspace.FetchBlob("out")
      res = np.array(np.sum(X))
      np.testing.assert_array_almost_equal(out, res, decimal=0)
  
      # broadcasting with single elem dimensions at both ends
      X = np.random.rand(2, 3, 4, 5).astype(np.float32)
      Y = np.random.rand(1, 3, 4, 1).astype(np.float32)
      op = core.CreateOperator(
          "SumReduceLike", ["X", "Y"], "out", broadcast=1
      )
      workspace.FeedBlob("X", X)
      workspace.FeedBlob("Y", Y)
      workspace.RunOperatorOnce(op)
      out = workspace.FetchBlob("out")
      res = np.sum(X, axis=0)
      res = np.sum(res, axis=2).reshape(Y.shape)
      np.testing.assert_array_almost_equal(out, res)
      self.assertDeviceChecks(dc, op, [X, Y], [0])
  
      # fp64 is not supported with the CUDA op
      dc_cpu_only = [d for d in dc if d.device_type != caffe2_pb2.CUDA]
      self.assertDeviceChecks(dc_cpu_only, op, [X, Y], [0])
  
imports: import unittest
  from hypothesis import given, assume, settings
  import hypothesis.strategies
  import numpy
  import operator
  from caffe2.proto import caffe2_pb2
  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 10 for calling the TestElementwiseBroadcast obj's underlying member method code with example usage: obj.test_sum_reduce(gc, dc) without return types