(self)
| 603 | tensor.to_numpy(_cTensor_to_pyTensor(dx0_ct)), dx1) |
| 604 | |
| 605 | def test_dnnl_pooling_avg(self): |
| 606 | dev = cpu_dev |
| 607 | N = 1 |
| 608 | C = 3 |
| 609 | H = 2 |
| 610 | W = 2 |
| 611 | |
| 612 | data_shape = [N, C, H, W] |
| 613 | param_shape = [1, C, 1, 1] |
| 614 | data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] |
| 615 | |
| 616 | x0 = np.array(data, dtype=np.float32).reshape(data_shape) |
| 617 | x0_ct = tensor.Tensor(device=dev, data=x0).data |
| 618 | |
| 619 | dy0 = np.array([1, 2, 3], dtype=np.float32).reshape([1, 3, 1, 1]) |
| 620 | dy0_ct = tensor.Tensor(device=dev, data=dy0).data |
| 621 | |
| 622 | hndl = singa_api.PoolingHandle(x0_ct, [2, 2], [1, 1], [0, 0], False) |
| 623 | |
| 624 | y0_ct = singa_api.CpuPoolingForward(hndl, x0_ct) |
| 625 | |
| 626 | y1 = np.array([[[[2.5000]], [[6.5000]], [[10.5000]]]]) |
| 627 | np.testing.assert_array_almost_equal( |
| 628 | tensor.to_numpy(_cTensor_to_pyTensor(y0_ct)), y1) |
| 629 | dx0_ct = singa_api.CpuPoolingBackward(hndl, dy0_ct, x0_ct, y0_ct) |
| 630 | dx1 = np.array([[[[0.2500, 0.2500], [0.2500, 0.2500]], |
| 631 | [[0.5000, 0.5000], [0.5000, 0.5000]], |
| 632 | [[0.7500, 0.7500], [0.7500, 0.7500]]]]) |
| 633 | np.testing.assert_array_almost_equal( |
| 634 | tensor.to_numpy(_cTensor_to_pyTensor(dx0_ct)), dx1) |
| 635 | |
| 636 | def _concat_helper(self, dev): |
| 637 | np1 = np.random.random([5, 6, 7, 8]).astype(np.float32) |
nothing calls this directly
no test coverage detected