Esempio n. 1
0
    def testCompress(self):
        a = np.array([[1, 2], [3, 4], [5, 6]])

        with self.assertRaises(TypeError):
            compress([0, 1], a, axis=0, out=1)

        with self.assertRaises(TypeError):
            compress([0, 1], array([[1, 2], [3, 4], [5, 6]], dtype='i8'),
                     axis=0, out=empty((1, 2), dtype='f8'))
Esempio n. 2
0
def test_compress():
    a = np.array([[1, 2], [3, 4], [5, 6]])

    with pytest.raises(TypeError):
        compress([0, 1], a, axis=0, out=1)

    with pytest.raises(TypeError):
        compress([0, 1], array([[1, 2], [3, 4], [5, 6]], dtype='i8'),
                 axis=0, out=empty((1, 2), dtype='f8'))
Esempio n. 3
0
def test_compress_execution(setup):
    data = np.array([[1, 2], [3, 4], [5, 6]])
    a = tensor(data, chunk_size=1)

    t = compress([0, 1], a, axis=0)

    res = t.execute().fetch()
    expected = np.compress([0, 1], data, axis=0)
    np.testing.assert_array_equal(res, expected)

    t = compress([0, 1], a, axis=1)

    res = t.execute().fetch()
    expected = np.compress([0, 1], data, axis=1)
    np.testing.assert_array_equal(res, expected)

    t = a.compress([0, 1, 1])

    res = t.execute().fetch()
    expected = np.compress([0, 1, 1], data)
    np.testing.assert_array_equal(res, expected)

    t = compress([False, True, True], a, axis=0)

    res = t.execute().fetch()
    expected = np.compress([False, True, True], data, axis=0)
    np.testing.assert_array_equal(res, expected)

    t = compress([False, True], a, axis=1)

    res = t.execute().fetch()
    expected = np.compress([False, True], data, axis=1)
    np.testing.assert_array_equal(res, expected)

    with pytest.raises(np.AxisError):
        compress([0, 1, 1], a, axis=1)

    # test order
    data = np.asfortranarray([[1, 2], [3, 4], [5, 6]])
    a = tensor(data, chunk_size=1)

    t = compress([0, 1, 1], a, axis=0)

    res = t.execute().fetch()
    expected = np.compress([0, 1, 1], data, axis=0)
    np.testing.assert_array_equal(res, expected)
    assert res.flags['C_CONTIGUOUS'] == expected.flags['C_CONTIGUOUS']
    assert res.flags['F_CONTIGUOUS'] == expected.flags['F_CONTIGUOUS']

    t = compress([0, 1, 1], a, axis=0, out=tensor(np.empty((2, 2), order='F', dtype=int)))

    res = t.execute().fetch()
    expected = np.compress([0, 1, 1], data, axis=0, out=np.empty((2, 2), order='F', dtype=int))
    np.testing.assert_array_equal(res, expected)
    assert res.flags['C_CONTIGUOUS'] == expected.flags['C_CONTIGUOUS']
    assert res.flags['F_CONTIGUOUS'] == expected.flags['F_CONTIGUOUS']
Esempio n. 4
0
    def testCompressExecution(self):
        data = np.array([[1, 2], [3, 4], [5, 6]])
        a = tensor(data, chunk_size=1)

        t = compress([0, 1], a, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([0, 1], data, axis=0)
        np.testing.assert_array_equal(res, expected)

        t = compress([0, 1], a, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([0, 1], data, axis=1)
        np.testing.assert_array_equal(res, expected)

        t = a.compress([0, 1, 1])

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([0, 1, 1], data)
        np.testing.assert_array_equal(res, expected)

        t = compress([False, True, True], a, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([False, True, True], data, axis=0)
        np.testing.assert_array_equal(res, expected)

        t = compress([False, True], a, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([False, True], data, axis=1)
        np.testing.assert_array_equal(res, expected)

        with self.assertRaises(np.AxisError):
            compress([0, 1, 1], a, axis=1)

        # test order
        data = np.asfortranarray([[1, 2], [3, 4], [5, 6]])
        a = tensor(data, chunk_size=1)

        t = compress([0, 1, 1], a, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([0, 1, 1], data, axis=0)
        np.testing.assert_array_equal(res, expected)
        self.assertEqual(res.flags['C_CONTIGUOUS'], expected.flags['C_CONTIGUOUS'])
        self.assertEqual(res.flags['F_CONTIGUOUS'], expected.flags['F_CONTIGUOUS'])

        t = compress([0, 1, 1], a, axis=0, out=tensor(np.empty((2, 2), order='F', dtype=int)))

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([0, 1, 1], data, axis=0, out=np.empty((2, 2), order='F', dtype=int))
        np.testing.assert_array_equal(res, expected)
        self.assertEqual(res.flags['C_CONTIGUOUS'], expected.flags['C_CONTIGUOUS'])
        self.assertEqual(res.flags['F_CONTIGUOUS'], expected.flags['F_CONTIGUOUS'])
Esempio n. 5
0
    def testCompressExecution(self):
        data = np.array([[1, 2], [3, 4], [5, 6]])
        a = tensor(data, chunk_size=1)

        t = compress([0, 1], a, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([0, 1], data, axis=0)
        np.testing.assert_array_equal(res, expected)

        t = compress([0, 1], a, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([0, 1], data, axis=1)
        np.testing.assert_array_equal(res, expected)

        t = a.compress([0, 1, 1])

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([0, 1, 1], data)
        np.testing.assert_array_equal(res, expected)

        t = compress([False, True, True], a, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([False, True, True], data, axis=0)
        np.testing.assert_array_equal(res, expected)

        t = compress([False, True], a, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.compress([False, True], data, axis=1)
        np.testing.assert_array_equal(res, expected)

        with self.assertRaises(np.AxisError):
            compress([0, 1, 1], a, axis=1)