예제 #1
0
def test_max_two_array():
    with goos.OptimizationPlan() as plan:
        x = goos.Variable([2, 1])
        y = goos.Variable([3, 0.5])
        z = goos.dot(goos.max(x, y), [1, -1])

        np.testing.assert_array_equal(z.get().array, 2)
        np.testing.assert_array_equal(z.get_grad([x])[0].array_grad, [0, -1])
        np.testing.assert_array_equal(z.get_grad([y])[0].array_grad, [1, 0])
예제 #2
0
def test_max_two_scalar():
    with goos.OptimizationPlan() as plan:
        x = goos.Variable(2)
        y = goos.Variable(3)
        z = goos.max(x, y)

        assert z.get() == 3
        assert z.get_grad([x])[0] == 0
        assert z.get_grad([y])[0] == 1
예제 #3
0
def test_max_two_array_2d():
    with goos.OptimizationPlan() as plan:
        x = goos.Variable([[1, 2], [3, 4]])
        y = goos.Variable([[3, 0.5], [4.5, 6]])
        z = goos.dot([[1, 2], [3, 4]], goos.max(x, y))

        np.testing.assert_array_equal(z.get().array, 44.5)
        np.testing.assert_array_equal(
            z.get_grad([x])[0].array_grad, [[0, 2], [0, 0]])
        np.testing.assert_array_equal(
            z.get_grad([y])[0].array_grad, [[1, 0], [3, 4]])
예제 #4
0
def test_max_three_scalars():
    with goos.OptimizationPlan() as plan:
        x = goos.Variable(2)
        y = goos.Variable(3)
        w = goos.Variable(1)
        z = goos.max(x, y, w)

        assert z.get() == 3
        assert z.get_grad([x])[0] == 0
        assert z.get_grad([y])[0] == 1
        assert z.get_grad([w])[0] == 0