Example #1
0
def test_ascontiguousarray():
    # dtype different
    raw_a = np.asfortranarray(np.random.rand(2, 4))
    raw_b = np.ascontiguousarray(raw_a, dtype='f4')

    a = tensor(raw_a, chunk_size=2)
    b = ascontiguousarray(a, dtype='f4')

    assert a.dtype == raw_a.dtype
    assert a.flags['C_CONTIGUOUS'] == raw_a.flags['C_CONTIGUOUS']
    assert a.flags['F_CONTIGUOUS'] == raw_a.flags['F_CONTIGUOUS']

    assert b.dtype == raw_b.dtype
    assert b.flags['C_CONTIGUOUS'] == raw_b.flags['C_CONTIGUOUS']
    assert b.flags['F_CONTIGUOUS'] == raw_b.flags['F_CONTIGUOUS']

    # no copy
    raw_a = np.random.rand(2, 4)
    raw_b = np.ascontiguousarray(raw_a)

    a = tensor(raw_a, chunk_size=2)
    b = ascontiguousarray(a)

    assert a.dtype == raw_a.dtype
    assert a.flags['C_CONTIGUOUS'] == raw_a.flags['C_CONTIGUOUS']
    assert a.flags['F_CONTIGUOUS'] == raw_a.flags['F_CONTIGUOUS']

    assert b.dtype == raw_b.dtype
    assert b.flags['C_CONTIGUOUS'] == raw_b.flags['C_CONTIGUOUS']
    assert b.flags['F_CONTIGUOUS'] == raw_b.flags['F_CONTIGUOUS']
Example #2
0
    def testAscontiguousarray(self):
        # dtype different
        raw_a = np.asfortranarray(np.random.rand(2, 4))
        raw_b = np.ascontiguousarray(raw_a, dtype='f4')

        a = tensor(raw_a, chunk_size=2)
        b = ascontiguousarray(a, dtype='f4')

        self.assertEqual(a.dtype, raw_a.dtype)
        self.assertEqual(a.flags['C_CONTIGUOUS'], raw_a.flags['C_CONTIGUOUS'])
        self.assertEqual(a.flags['F_CONTIGUOUS'], raw_a.flags['F_CONTIGUOUS'])

        self.assertEqual(b.dtype, raw_b.dtype)
        self.assertEqual(b.flags['C_CONTIGUOUS'], raw_b.flags['C_CONTIGUOUS'])
        self.assertEqual(b.flags['F_CONTIGUOUS'], raw_b.flags['F_CONTIGUOUS'])

        # no copy
        raw_a = np.random.rand(2, 4)
        raw_b = np.ascontiguousarray(raw_a)

        a = tensor(raw_a, chunk_size=2)
        b = ascontiguousarray(a)

        self.assertEqual(a.dtype, raw_a.dtype)
        self.assertEqual(a.flags['C_CONTIGUOUS'], raw_a.flags['C_CONTIGUOUS'])
        self.assertEqual(a.flags['F_CONTIGUOUS'], raw_a.flags['F_CONTIGUOUS'])

        self.assertEqual(b.dtype, raw_b.dtype)
        self.assertEqual(b.flags['C_CONTIGUOUS'], raw_b.flags['C_CONTIGUOUS'])
        self.assertEqual(b.flags['F_CONTIGUOUS'], raw_b.flags['F_CONTIGUOUS'])