Esempio n. 1
0
def test_symmetric(a, b):
    """
    Write a test that ensures that :func:`minitorch.operators.mul` is symmetric, i.e.
    gives the same value regardless of the order of its input.
    """
    # TODO: Implement for Task 0.2.
    assert operators.mul(a, b) == operators.mul(b, a)
Esempio n. 2
0
def test_symmetric(x, y):
    """
    Write a test that ensures that :func:`minitorch.operators.mul` is symmetric, i.e.
    gives the same value regardless of the order of its input.
    """
    #None
    assert_close(operators.mul(x, y), operators.mul(y, x))
Esempio n. 3
0
def test_distribute(a, b, c):
    r"""
    Write a test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """
    assert_close(operators.mul(a, b + c),
                 operators.mul(a, b) + operators.mul(a, c))
Esempio n. 4
0
def test_other(x, y):
    """
    Write a test that ensures some other property holds for your functions.
    """
    r1 = operators.mul(operators.neg(x), y)
    r2 = operators.mul(operators.mul(-1.0, y), operators.mul(1.0, x))
    assert_close(r1, r2)
Esempio n. 5
0
def test_distribute(x, y, z):
    r"""
    Write a test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """
    assert_close(operators.mul(z, operators.add(x, y)),
                 operators.add(operators.mul(x, z), operators.mul(y, z)))
Esempio n. 6
0
def test_other(x, y, z):
    """
    Write a test that ensures some other property holds for your functions.
    """
    None
    # TODO: Implement for Task 0.2.
    assert_close(operators.mul(x, (y * z)), operators.mul((x * y), z))
Esempio n. 7
0
def test_symmetric(x, y):
    """
    Write a test that ensures that :func:`minitorch.operators.mul` is symmetric, i.e.
    gives the same value regardless of the order of its input.
    """
    assert operators.mul(x, y) == operators.mul(y, x)
    assert operators.add(x, y) == operators.add(y, x)
Esempio n. 8
0
def test_distribute(x, y, z):
    r"""
    Write a test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """
    
    # TODO: Implement for Task 0.2.
    assert operators.mul(z, (x + y)) == operators.mul(z, x) + operators.mul(z, y)
Esempio n. 9
0
def test_other(x, y, z):
    """
    Write a test that ensures some other property holds for your functions.
    Associativity.
    """
    a = operators.mul(x, operators.mul(y, z))
    b = operators.mul(operators.mul(x, y), z)
    assert_close(a, b)
Esempio n. 10
0
def test_associate(x, y, z):
    """
    Write a test that ensures some other property holds for your functions.
    """
    assert_close(operators.mul(operators.mul(x, y), z),
                 operators.mul(x, operators.mul(y, z)))
    assert_close(operators.add(operators.add(x, y), z),
                 operators.add(x, operators.add(y, z)))
Esempio n. 11
0
def test_distribute(x, y, z):
    r"""
    Write a test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """
    r1 = operators.mul(z, operators.add(x, y))
    r2 = operators.add(operators.mul(z, x), operators.mul(z, y))
    assert_close(r1, r2)
Esempio n. 12
0
def test_distribute(x,y,z):
    r"""
    Write a test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """
    None
    # TODO: Implement for Task 0.2.
    assert_close(operators.mul(z, (x+y)), operators.add(operators.mul(z,x), operators.mul(z,y)))
Esempio n. 13
0
def test_symmetric():
    """
    A test that ensures that :func:`minitorch.operators.mul` is symmetric, i.e.
    gives the same value regardless of the order of its input.
    """
    a = list(range(-500, 501))
    b = list(range(-500, 501))

    for i, j in zip(a, b):
        assert operators.mul(i, j) == operators.mul(j, i)
Esempio n. 14
0
def test_distribute(x, y, z):
    """
    Write a test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """
    #None

    assert_close(operators.add((operators.mul(z, y)), operators.mul(z, x)),
                 (z * x) + (z * y))
    assert_close(operators.mul(z, operators.add(x, y)), z * (x + y))
Esempio n. 15
0
def test_distribute():
    r"""
    A test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """

    a = list(range(-500, 501))
    b = list(range(-500, 501))
    c = list(range(-500, 501))

    for i, j, z in zip(a, b, c):
        assert operators.mul(z, operators.add(i, j)) == operators.add(
            operators.mul(z, i), operators.mul(z, j))
Esempio n. 16
0
def test_inv(x):
    """
    Write a test that ensures some other property holds for your functions.
    """
    if x != 0:
        assert_close(operators.mul(x, operators.inv(x)), 1)
    assert_close(operators.add(x, operators.neg(x)), 0)
Esempio n. 17
0
def test_other():
    """
    Write a test that ensures some other property holds for your functions.
    """
    a = 10.0

    assert operators.neg(a) == -10.0
    assert operators.mul(a, -1) == -1 * a
def test_same_as_python(x, y):
    "Check that the main operators all return the same value of the python version"
    assert_close(mul(x, y), x * y)
    assert_close(add(x, y), x + y)
    assert_close(neg(x), -x)
    assert_close(max(x, y), x if x > y else y)
    if x != 0.0:
        assert_close(inv(x), 1.0 / x)
Esempio n. 19
0
def test_symmetric(x, y):
    assert_close(operators.mul(x, y), operators.mul(y, x))
Esempio n. 20
0
def test_add_and_mul(x, y):
    assert_close(operators.mul(x, y), x * y)
    assert_close(operators.add(x, y), x + y)
    assert_close(operators.neg(x), -x)
def test_distribute(x, y, z):
    assert_close(op.mul(z, op.add(x, y)), op.add(op.mul(z, x), op.mul(z, y)))
def test_symmetric(x, y):
    assert op.mul(x, y) == op.mul(y, x)
    assert op.add(x, y) == op.add(y, x)
    assert op.max(x, y) == op.max(y, x)
    assert op.eq(x, y) == op.eq(y, x)
Esempio n. 23
0
def test_other(x):
    """
    Write a test that ensures some other property holds for your functions.
    """
    assert_close(operators.mul(x, 1), x)
Esempio n. 24
0
def test_other(x):
    """
    Write a test that ensures some other property holds for your functions.
    """
    assert operators.neg(x) == operators.mul(-1, x)
Esempio n. 25
0
def test_distribute(a, b, c):
    r"""
    Write a test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """
    assert operators.mul(a, operators.add(b, c)) == operators.add(operators.mul(a, b), operators.mul(a, c))
Esempio n. 26
0
def test_distribute(x, y, z):
    assert_close(operators.mul(x, operators.add(y, z)),
                 operators.add(operators.mul(x, y), operators.mul(x, z)))
Esempio n. 27
0
def test_other(x, y, z):
    assert_close(operators.mul(x, operators.mul(y, z)),
                 operators.mul(operators.mul(x, y), z))
Esempio n. 28
0
def test_distribute(x, y, z):
    r"""
    Write a test that ensures that your operators distribute, i.e.
    :math:`z \times (x + y) = z \times x + z \times y`
    """
    assert operators.mul(z, x + y) == operators.mul(z, x) + operators.mul(z, y)