示例#1
0
def test_entropy_execution(setup):
    rs = np.random.RandomState(0)
    a = rs.rand(10)

    t1 = tensor(a, chunk_size=4)
    r = entropy(t1)

    result = r.execute().fetch()
    expected = sp_entropy(a)
    np.testing.assert_array_almost_equal(result, expected)

    b = rs.rand(10)
    base = 3.1

    t2 = tensor(b, chunk_size=4)
    r = entropy(t1, t2, base)

    result = r.execute().fetch()
    expected = sp_entropy(a, b, base)
    np.testing.assert_array_almost_equal(result, expected)

    b = rs.rand(10)
    base = 3.1

    t2 = tensor(b, chunk_size=4)
    r = entropy(t1, t2, base)

    result = r.execute().fetch()
    expected = sp_entropy(a, b, base)
    np.testing.assert_array_almost_equal(result, expected)

    r = entropy(t1, t2, t1.sum())

    result = r.execute().fetch()
    expected = sp_entropy(a, b, a.sum())
    np.testing.assert_array_almost_equal(result, expected)

    with pytest.raises(ValueError):
        entropy(t1, t2[:7])
示例#2
0
    def testEntropyExecution(self):
        rs = np.random.RandomState(0)
        a = rs.rand(10)

        t1 = tensor(a, chunk_size=4)
        r = entropy(t1)

        result = self.executor.execute_tensor(r, concat=True)[0]
        expected = sp_entropy(a)
        np.testing.assert_array_almost_equal(result, expected)

        b = rs.rand(10)
        base = 3.1

        t2 = tensor(b, chunk_size=4)
        r = entropy(t1, t2, base)

        result = self.executor.execute_tensor(r, concat=True)[0]
        expected = sp_entropy(a, b, base)
        np.testing.assert_array_almost_equal(result, expected)

        b = rs.rand(10)
        base = 3.1

        t2 = tensor(b, chunk_size=4)
        r = entropy(t1, t2, base)

        result = self.executor.execute_tensor(r, concat=True)[0]
        expected = sp_entropy(a, b, base)
        np.testing.assert_array_almost_equal(result, expected)

        r = entropy(t1, t2, t1.sum())

        result = self.executor.execute_tensor(r, concat=True)[0]
        expected = sp_entropy(a, b, a.sum())
        np.testing.assert_array_almost_equal(result, expected)

        with self.assertRaises(ValueError):
            entropy(t1, t2[:7])