MCPcopy Create free account
hub / github.com/apache/singa / test_dnnl_pooling_max

Method test_dnnl_pooling_max

test/python/test_api.py:575–603  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

573 _run_test([2, 2, 2, 2], -4, [1, 16])
574
575 def test_dnnl_pooling_max(self):
576 dev = cpu_dev
577 N = 1
578 C = 3
579 H = 2
580 W = 2
581
582 data_shape = [N, C, H, W]
583 param_shape = [1, C, 1, 1]
584 data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
585
586 x0 = np.array(data, dtype=np.float32).reshape(data_shape)
587 x0_ct = tensor.Tensor(device=dev, data=x0).data
588
589 dy0 = np.array([1, 2, 3], dtype=np.float32).reshape([1, 3, 1, 1])
590 dy0_ct = tensor.Tensor(device=dev, data=dy0).data
591
592 hndl = singa_api.PoolingHandle(x0_ct, [2, 2], [1, 1], [0, 0], True)
593
594 y0_ct = singa_api.CpuPoolingForward(hndl, x0_ct)
595 y1 = np.array([[[[4.]], [[8.]], [[12.]]]])
596 np.testing.assert_array_almost_equal(
597 tensor.to_numpy(_cTensor_to_pyTensor(y0_ct)), y1)
598
599 dx0_ct = singa_api.CpuPoolingBackward(hndl, dy0_ct, x0_ct, y0_ct)
600 dx1 = np.array([[[[0., 0.], [0., 1.]], [[0., 0.], [0., 2.]],
601 [[0., 0.], [0., 3.]]]])
602 np.testing.assert_array_almost_equal(
603 tensor.to_numpy(_cTensor_to_pyTensor(dx0_ct)), dx1)
604
605 def test_dnnl_pooling_avg(self):
606 dev = cpu_dev

Callers

nothing calls this directly

Calls 4

_cTensor_to_pyTensorFunction · 0.85
TensorMethod · 0.80
PoolingHandleMethod · 0.80
reshapeMethod · 0.45

Tested by

no test coverage detected