code: def test_conv2d(self):
      print("TEST CONV2D FORWARD")
      x_shape = [2, 1, 3, 3]
      x = singa_wrap.Tensor(x_shape)
      x.CopyFloatDataFromHostPtr(
          [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
      )
  
      W_shape = [1, 1, 3, 3]
      W = singa_wrap.Tensor(W_shape)
      W.CopyFloatDataFromHostPtr([1, 1, 0, 0, 0, -1, 0, 1, 0])
  
      b_shape = [1]
      b = singa_wrap.Tensor(b_shape)
      b.CopyFloatDataFromHostPtr([1])
  
      dy_shape = [2, 1, 2, 2]
      dy = singa_wrap.Tensor(dy_shape)
      dy.CopyFloatDataFromHostPtr(
          [0.1, 0.2, 0.3, 0.4, 0.1, 0.2, 0.3, 0.4]
      )
  
      handle = singa_wrap.ConvHandle(
          x, (3, 3), (2, 2), (1, 1), 1, 1, True, 1
      )
      y = singa_wrap.CpuConvForward(x, W, b, handle)
  
      self.assertListEqual([2, 1, 2, 2], list(y.shape()))
  
      _y = y.GetFloatValue(int(y.Size()))
      self.assertAlmostEqual(3.0, _y[0])
      self.assertAlmostEqual(7.0, _y[1])
      self.assertAlmostEqual(-3.0, _y[2])
      self.assertAlmostEqual(12.0, _y[3])
      self.assertAlmostEqual(3.0, _y[4])
      self.assertAlmostEqual(7.0, _y[5])
      self.assertAlmostEqual(-3.0, _y[6])
      self.assertAlmostEqual(12.0, _y[7])
  
      print("TEST CONV2D DATA BACKWARD")
  
      dx = singa_wrap.CpuConvBackwardx(dy, W, x, handle)
      self.assertListEqual([2, 1, 3, 3], list(dx.shape()))
  
      _dx = dx.GetFloatValue(int(dx.Size()))
      self.assertAlmostEqual(0.0, _dx[0])
      self.assertAlmostEqual(-0.1, _dx[1])
      self.assertAlmostEqual(0.0, _dx[2])
      self.assertAlmostEqual(0.4, _dx[3])
      self.assertAlmostEqual(0.4, _dx[4])
      self.assertAlmostEqual(0.6, _dx[5])
      self.assertAlmostEqual(0.0, _dx[6])
      self.assertAlmostEqual(-0.3, _dx[7])
  
      print("TEST CONV2D WEIGHT BACKWARD")
      dW = singa_wrap.CpuConvBackwardW(dy, x, W, handle)
      self.assertListEqual([1, 1, 3, 3], list(dW.shape()))
  
      _dW = dW.GetFloatValue(int(dW.Size()))
      self.assertAlmostEqual(4.0, _dW[0], places=5)
      self.assertAlmostEqual(7.2, _dW[1], places=5)
      self.assertAlmostEqual(3.0, _dW[2], places=5)
      self.assertAlmostEqual(7.2, _dW[3], places=5)
      self.assertAlmostEqual(12.8, _dW[4], places=5)
      self.assertAlmostEqual(5.2, _dW[5], places=5)
      self.assertAlmostEqual(2.0, _dW[6], places=5)
      self.assertAlmostEqual(3.2, _dW[7], places=5)
      self.assertAlmostEqual(1.0, _dW[8], places=5)
  
      print("TEST CONV2D DATA BACKWARD")
      db = singa_wrap.CpuConvBackwardb(dy, b, handle)
      self.assertEqual(1, dW.shape()[0])
  
      _db = db.GetFloatValue(int(db.Size()))
      print(_db)
      self.assertAlmostEqual(2.0, _db[0], places=5)
  
imports: import unittest
  from singa import singa_wrap
label_desc: Use image node_id 1 for calling the TestPythonOperation obj's underlying member method code with example usage: obj.test_conv2d() without return types