Пример #1
0
    def test_square(self):
        np_x = np.array([1, 2, 3])

        dtype = plaidml2.DType.FLOAT32
        x = edsl.Tensor(edsl.LogicalShape(dtype, np_x.shape))
        y = op.square(x)

        test_result = get_jacobian([x], [np_x], y, x)
        true_result = np.array([[2, 0, 0], [0, 4, 0], [0, 0, 6]])

        npt.assert_allclose(test_result, true_result)
Пример #2
0
    def test_assign(self):
        np_x = np.array([1, 2, 3])
        np_b = np.array([1, 1, 1])

        dtype = plaidml2.DType.FLOAT32
        x = edsl.Tensor(edsl.LogicalShape(dtype, np_x.shape))
        b = edsl.Tensor(edsl.LogicalShape(dtype, np_b.shape))
        y = op.square(dist(x, b))

        test_result = get_jacobian([x, b], [np_x, np_b], y, x)
        true_result = np.zeros((3, 3, 3))
        true_result[0, :, 0] = 0
        true_result[1, :, 1] = 2
        true_result[2, :, 2] = 4

        npt.assert_allclose(test_result, true_result)
Пример #3
0
def square(x):
    logger.debug('square(x: {})'.format(x))
    return _KerasNode('square', tensor=plaidml_op.square(x.tensor))
Пример #4
0
def square(x):
    return _KerasNode('square', tensor=plaidml_op.square(x.tensor))