Esempio n. 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)
Esempio n. 2
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)

        a = ones((2, 3), chunk_size=1)
        b = tensor(np.asfortranarray(np.random.rand(2, 3)), chunk_size=2)

        copyto(b, a)

        res = self.executor.execute_tensor(b, concat=True)[0]
        expected = np.asfortranarray(np.ones((2, 3)))

        np.testing.assert_array_equal(res, expected)
        self.assertTrue(res.flags['F_CONTIGUOUS'])
        self.assertFalse(res.flags['C_CONTIGUOUS'])
Esempio n. 3
0
def test_copyto():
    a = ones((10, 20), chunk_size=3)
    b = ones(10, chunk_size=4)

    with pytest.raises(ValueError):
        copyto(a, b)

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

    assert isinstance(a.op, TensorCopyTo)
    assert a.inputs[0] is b.data
    assert isinstance(a.inputs[1].op, tp)

    a = tile(a)

    assert isinstance(a.chunks[0].op, TensorCopyTo)
    assert len(a.chunks[0].inputs) == 2

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

    with pytest.raises(TypeError):
        copyto(a, b)

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

    assert a.op.where is not None

    a = tile(a)

    assert isinstance(a.chunks[0].op, TensorCopyTo)
    assert len(a.chunks[0].inputs) == 3

    with pytest.raises(ValueError):
        copyto(a, a, where=np.ones(30, dtype='?'))
Esempio n. 4
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, TensorCopyTo)
        self.assertIs(a.inputs[0], b.data)
        self.assertIsInstance(a.inputs[1].op, tp)

        a = a.tiles()

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

        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)

        a = a.tiles()

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

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