コード例 #1
0
    def testCopytoExecution(self):
        a = ones((2, 3), chunk_size=1)
        b = tensor([3, -1, 3], chunk_size=2)

        copyto(a, b, where=b > 1)

        res = self.executor.execute_tensor(a, concat=True)[0]
        expected = np.array([[3, 1, 3], [3, 1, 3]])

        np.testing.assert_equal(res, expected)
コード例 #2
0
    def testCopyto(self):
        a = ones((10, 20), chunk_size=3)
        b = ones(10, chunk_size=4)

        with self.assertRaises(ValueError):
            copyto(a, b)

        tp = type(a.op)
        b = ones(20, chunk_size=4)
        copyto(a, b)

        self.assertIsInstance(a.op, CopyTo)
        self.assertIs(a.inputs[0], b.data)
        self.assertIsInstance(a.inputs[1].op, tp)
        self.assertEqual(calc_shape(a), a.shape)

        a.tiles()

        self.assertIsInstance(a.chunks[0].op, CopyTo)
        self.assertEqual(len(a.chunks[0].inputs), 2)
        self.assertEqual(calc_shape(a.chunks[0]), a.chunks[0].shape)

        a = ones((10, 20), chunk_size=3, dtype='i4')
        b = ones(20, chunk_size=4, dtype='f8')

        with self.assertRaises(TypeError):
            copyto(a, b)

        b = ones(20, chunk_size=4, dtype='i4')
        copyto(a, b, where=b > 0)

        self.assertIsNotNone(a.op.where)
        self.assertEqual(calc_shape(a), a.shape)

        a.tiles()

        self.assertIsInstance(a.chunks[0].op, CopyTo)
        self.assertEqual(len(a.chunks[0].inputs), 3)
        self.assertEqual(calc_shape(a.chunks[0]), a.chunks[0].shape)

        with self.assertRaises(ValueError):
            copyto(a, a, where=np.ones(30, dtype='?'))