コード例 #1
0
ファイル: test_api.py プロジェクト: zlheui/singa
        def _run_test(dev, singa_op, np_op, s1, s2):
            x_0 = np.random.random(s1).astype(np.float32)
            y_0 = np.random.random(s2).astype(np.float32)
            x0 = tensor.Tensor(device=dev, data=x_0)
            y0 = tensor.Tensor(device=dev, data=y_0)

            z0 = tensor._call_singa_func(singa_op, x0.data, y0.data)
            z0.to_host()
            np.testing.assert_array_almost_equal(tensor.to_numpy(z0),
                                                 np_op(x_0, y_0))
            return
コード例 #2
0
ファイル: test_api.py プロジェクト: zlheui/singa
    def _round_even(self, dev=gpu_dev):
        q=np.array([0.1, 0.5, 0.9, 1.2, 1.5,
                    1.8, 2.3, 2.5, 2.7, -1.1,
                    -1.5, -1.9, -2.2, -2.5, -2.8]).astype(np.float32)
        ans = np.array([0., 0., 1., 1., 2.,
                    2., 2., 2., 3., -1.,
                    -2., -2., -2., -2., -3.]).astype(np.float32)

        x = tensor.Tensor(shape=q.shape, device=dev)
        x.copy_from_numpy(q)
        y = tensor._call_singa_func(singa_api.RoundE, x.data)
        np.testing.assert_array_almost_equal(ans, tensor.to_numpy(y))
コード例 #3
0
        def _run_test(org_shape, axis, aft_shape):
            x_0 = np.random.random(org_shape).astype(np.float32)
            x_0 = x_0 + 1000
            x0 = tensor.Tensor(device=gpu_dev, data=x_0)

            # test with axis
            y0 = tensor._call_singa_func(singa_api.SoftMax, x0.data, axis)

            # test with numpy
            x_0 = x_0.reshape(aft_shape)
            x_0 = x_0 - np.max(x_0)
            y1 = np.divide(np.exp(x_0), np.sum(np.exp(x_0),axis=1).reshape(x_0.shape[0],1) ) # 2d softmax
            y1 = y1.reshape(org_shape)

            np.testing.assert_array_almost_equal(tensor.to_numpy(y0), y1)
コード例 #4
0
ファイル: test_api.py プロジェクト: zlheui/singa
        def _test(s1, s2, axis1, axis2, s3, s_op, n_op, dev):
            x_0 = np.random.random(s1).astype(np.float32)
            y_0 = np.random.random(s2).astype(np.float32)

            x0 = tensor.Tensor(device=dev, data=x_0)
            y0 = tensor.Tensor(device=dev, data=y_0)

            x1 = x0.transpose(axis1)
            y1 = y0.transpose(axis2)

            z0 = tensor._call_singa_func(s_op, x1.data, y1.data)
            z0.to_host()

            np.testing.assert_array_almost_equal(
                tensor.to_numpy(z0),
                n_op(x_0.transpose(axis1), y_0.transpose(axis2)))
            np.testing.assert_array_almost_equal(z0.shape, s3)
            return
コード例 #5
0
ファイル: test_api.py プロジェクト: zlheui/singa
 def _round(self, dev=gpu_dev):
     x = tensor.Tensor(shape=(3,4,5), device=dev).gaussian(0, 1)
     y = tensor._call_singa_func(singa_api.Round, x.data)
     np.testing.assert_array_almost_equal(np.round(tensor.to_numpy(x)),
                                          tensor.to_numpy(y))