Example #1
0
    def testAllcloseExecution(self):
        a = tensor([1e10, 1e-7], chunk_size=1)
        b = tensor([1.00001e10, 1e-8], chunk_size=1)

        t = allclose(a, b)

        res = self.executor.execute_tensor(t)[0]
        self.assertFalse(res)

        a = tensor([1e10, 1e-8], chunk_size=1)
        b = tensor([1.00001e10, 1e-9], chunk_size=1)

        t = allclose(a, b)

        res = self.executor.execute_tensor(t)[0]
        self.assertTrue(res)

        a = tensor([1.0, np.nan], chunk_size=1)
        b = tensor([1.0, np.nan], chunk_size=1)

        t = allclose(a, b, equal_nan=True)

        res = self.executor.execute_tensor(t)[0]
        self.assertTrue(res)

        a = tensor(sps.csr_matrix([[1e10, 1e-7], [0, 0]]), chunk_size=1)
        b = tensor(sps.csr_matrix([[1.00001e10, 1e-8], [0, 0]]), chunk_size=1)

        t = allclose(a, b)

        res = self.executor.execute_tensor(t)[0]
        self.assertFalse(res)
Example #2
0
    def testAllcloseExecution(self):
        a = tensor([1e10, 1e-7], chunk_size=1)
        b = tensor([1.00001e10, 1e-8], chunk_size=1)

        t = allclose(a, b)

        res = self.executor.execute_tensor(t)[0]
        self.assertFalse(res)

        a = tensor([1e10, 1e-8], chunk_size=1)
        b = tensor([1.00001e10, 1e-9], chunk_size=1)

        t = allclose(a, b)

        res = self.executor.execute_tensor(t)[0]
        self.assertTrue(res)

        a = tensor([1.0, np.nan], chunk_size=1)
        b = tensor([1.0, np.nan], chunk_size=1)

        t = allclose(a, b, equal_nan=True)

        res = self.executor.execute_tensor(t)[0]
        self.assertTrue(res)

        a = tensor(sps.csr_matrix([[1e10, 1e-7], [0, 0]]), chunk_size=1)
        b = tensor(sps.csr_matrix([[1.00001e10, 1e-8], [0, 0]]), chunk_size=1)

        t = allclose(a, b)

        res = self.executor.execute_tensor(t)[0]
        self.assertFalse(res)

        # test string dtype
        with self.assertRaises(TypeError):
            a = tensor(list('abcdefghi'), dtype=object)
            self.executor.execute_tensor(allclose(a, a))
Example #3
0
def test_allclose_execution(setup):
    a = tensor([1e10, 1e-7], chunk_size=1)
    b = tensor([1.00001e10, 1e-8], chunk_size=1)

    t = allclose(a, b)

    res = t.execute().fetch()
    assert res is False

    a = tensor([1e10, 1e-8], chunk_size=1)
    b = tensor([1.00001e10, 1e-9], chunk_size=1)

    t = allclose(a, b)

    res = t.execute().fetch()
    assert res is True

    a = tensor([1.0, np.nan], chunk_size=1)
    b = tensor([1.0, np.nan], chunk_size=1)

    t = allclose(a, b, equal_nan=True)

    res = t.execute().fetch()
    assert res is True

    a = tensor(sps.csr_matrix([[1e10, 1e-7], [0, 0]]), chunk_size=1)
    b = tensor(sps.csr_matrix([[1.00001e10, 1e-8], [0, 0]]), chunk_size=1)

    t = allclose(a, b)

    res = t.execute().fetch()
    assert res is False

    # test string dtype
    with pytest.raises(TypeError):
        a = tensor(list('abcdefghi'), dtype=object)
        allclose(a, a).execute()