コード例 #1
0
    def testIsclose(self):
        t1 = ones((2, 3), dtype='f4', chunk_size=2)

        atol = 1e-4
        rtol = 1e-5
        equal_nan = True

        t = isclose(t1, 2, atol=atol, rtol=rtol, equal_nan=equal_nan)

        self.assertIsInstance(t.op, IscloseConstant)
        self.assertEqual(t.op.atol, atol)
        self.assertEqual(t.op.rtol, rtol)
        self.assertEqual(t.op.equal_nan, equal_nan)
        self.assertEqual(calc_shape(t), t.shape)

        t.tiles()

        self.assertIsInstance(t.chunks[0].op, IscloseConstant)
        self.assertEqual(t.chunks[0].op.atol, atol)
        self.assertEqual(t.chunks[0].op.rtol, rtol)
        self.assertEqual(t.chunks[0].op.equal_nan, equal_nan)
        self.assertEqual(calc_shape(t.chunks[0]), t.chunks[0].shape)

        t1 = ones((2, 3), dtype='f4', chunk_size=2)
        t2 = ones((2, 3), dtype='f4', chunk_size=2)

        atol = 1e-4
        rtol = 1e-5
        equal_nan = True

        t = isclose(t1, t2, atol=atol, rtol=rtol, equal_nan=equal_nan)

        self.assertIsInstance(t.op, Isclose)
        self.assertEqual(t.op.atol, atol)
        self.assertEqual(t.op.rtol, rtol)
        self.assertEqual(t.op.equal_nan, equal_nan)
        self.assertEqual(calc_shape(t), t.shape)

        t.tiles()

        self.assertIsInstance(t.chunks[0].op, Isclose)
        self.assertEqual(t.chunks[0].op.atol, atol)
        self.assertEqual(t.chunks[0].op.rtol, rtol)
        self.assertEqual(t.chunks[0].op.equal_nan, equal_nan)
        self.assertEqual(calc_shape(t.chunks[0]), t.chunks[0].shape)
コード例 #2
0
    def testIsCloseExecution(self):
        data = np.array([1.05, 1.0, 1.01, np.nan])
        data2 = np.array([1.04, 1.0, 1.03, np.nan])

        x = tensor(data, chunk_size=2)
        y = tensor(data2, chunk_size=3)

        z = isclose(x, y, atol=.01)

        res = self.executor.execute_tensor(z, concat=True)[0]
        expected = np.isclose(data, data2, atol=.01)

        np.testing.assert_equal(res, expected)

        z = isclose(x, y, atol=.01, equal_nan=True)

        res = self.executor.execute_tensor(z, concat=True)[0]
        expected = np.isclose(data, data2, atol=.01, equal_nan=True)

        np.testing.assert_equal(res, expected)

        # test sparse

        data = sps.csr_matrix(np.array([0, 1.0, 1.01, np.nan]))
        data2 = sps.csr_matrix(np.array([0, 1.0, 1.03, np.nan]))

        x = tensor(data, chunk_size=2)
        y = tensor(data2, chunk_size=3)

        z = isclose(x, y, atol=.01)

        res = self.executor.execute_tensor(z, concat=True)[0]
        expected = np.isclose(data.toarray(), data2.toarray(), atol=.01)

        np.testing.assert_equal(res, expected)

        z = isclose(x, y, atol=.01, equal_nan=True)

        res = self.executor.execute_tensor(z, concat=True)[0]
        expected = np.isclose(data.toarray(),
                              data2.toarray(),
                              atol=.01,
                              equal_nan=True)

        np.testing.assert_equal(res, expected)