コード例 #1
0
def test_wrap():
    from pybind11_tests.array import wrap

    def assert_references(a, b, base=None):
        if base is None:
            base = a
        assert a is not b
        assert a.__array_interface__['data'][0] == b.__array_interface__[
            'data'][0]
        assert a.shape == b.shape
        assert a.strides == b.strides
        assert a.flags.c_contiguous == b.flags.c_contiguous
        assert a.flags.f_contiguous == b.flags.f_contiguous
        assert a.flags.writeable == b.flags.writeable
        assert a.flags.aligned == b.flags.aligned
        assert a.flags.updateifcopy == b.flags.updateifcopy
        assert np.all(a == b)
        assert not b.flags.owndata
        assert b.base is base
        if a.flags.writeable and a.ndim == 2:
            a[0, 0] = 1234
            assert b[0, 0] == 1234

    a1 = np.array([1, 2], dtype=np.int16)
    assert a1.flags.owndata and a1.base is None
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order='F')
    assert a1.flags.owndata and a1.base is None
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order='C')
    a1.flags.writeable = False
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.random.random((4, 4, 4))
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1t = a1.transpose()
    a2 = wrap(a1t)
    assert_references(a1t, a2, a1)

    a1d = a1.diagonal()
    a2 = wrap(a1d)
    assert_references(a1d, a2, a1)

    a1m = a1[::-1, ::-1, ::-1]
    a2 = wrap(a1m)
    assert_references(a1m, a2, a1)
コード例 #2
0
def test_wrap():
    from pybind11_tests.array import wrap

    def assert_references(a, b, base=None):
        if base is None:
            base = a
        assert a is not b
        assert a.__array_interface__['data'][0] == b.__array_interface__['data'][0]
        assert a.shape == b.shape
        assert a.strides == b.strides
        assert a.flags.c_contiguous == b.flags.c_contiguous
        assert a.flags.f_contiguous == b.flags.f_contiguous
        assert a.flags.writeable == b.flags.writeable
        assert a.flags.aligned == b.flags.aligned
        assert a.flags.updateifcopy == b.flags.updateifcopy
        assert np.all(a == b)
        assert not b.flags.owndata
        assert b.base is base
        if a.flags.writeable and a.ndim == 2:
            a[0, 0] = 1234
            assert b[0, 0] == 1234

    a1 = np.array([1, 2], dtype=np.int16)
    assert a1.flags.owndata and a1.base is None
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order='F')
    assert a1.flags.owndata and a1.base is None
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order='C')
    a1.flags.writeable = False
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.random.random((4, 4, 4))
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1t = a1.transpose()
    a2 = wrap(a1t)
    assert_references(a1t, a2, a1)

    a1d = a1.diagonal()
    a2 = wrap(a1d)
    assert_references(a1d, a2, a1)

    a1m = a1[::-1, ::-1, ::-1]
    a2 = wrap(a1m)
    assert_references(a1m, a2, a1)
コード例 #3
0
ファイル: test_numpy_array.py プロジェクト: tingelst/game
def test_wrap():
    from pybind11_tests.array import wrap

    def assert_references(A, B):
        assert A is not B
        assert A.__array_interface__['data'][0] == \
               B.__array_interface__['data'][0]
        assert A.shape == B.shape
        assert A.strides == B.strides
        assert A.flags.c_contiguous == B.flags.c_contiguous
        assert A.flags.f_contiguous == B.flags.f_contiguous
        assert A.flags.writeable == B.flags.writeable
        assert A.flags.aligned == B.flags.aligned
        assert A.flags.updateifcopy == B.flags.updateifcopy
        assert np.all(A == B)
        assert not B.flags.owndata
        assert B.base is A
        if A.flags.writeable and A.ndim == 2:
            A[0, 0] = 1234
            assert B[0, 0] == 1234

    A1 = np.array([1, 2], dtype=np.int16)
    assert A1.flags.owndata and A1.base is None
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order='F')
    assert A1.flags.owndata and A1.base is None
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order='C')
    A1.flags.writeable = False
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = np.random.random((4, 4, 4))
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = A1.transpose()
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = A1.diagonal()
    A2 = wrap(A1)
    assert_references(A1, A2)
コード例 #4
0
ファイル: test_numpy_array.py プロジェクト: aldanor/pybind11
def test_wrap():
    from pybind11_tests.array import wrap

    def assert_references(A, B):
        assert A is not B
        assert A.__array_interface__["data"][0] == B.__array_interface__["data"][0]
        assert A.shape == B.shape
        assert A.strides == B.strides
        assert A.flags.c_contiguous == B.flags.c_contiguous
        assert A.flags.f_contiguous == B.flags.f_contiguous
        assert A.flags.writeable == B.flags.writeable
        assert A.flags.aligned == B.flags.aligned
        assert A.flags.updateifcopy == B.flags.updateifcopy
        assert np.all(A == B)
        assert not B.flags.owndata
        assert B.base is A
        if A.flags.writeable and A.ndim == 2:
            A[0, 0] = 1234
            assert B[0, 0] == 1234

    A1 = np.array([1, 2], dtype=np.int16)
    assert A1.flags.owndata and A1.base is None
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order="F")
    assert A1.flags.owndata and A1.base is None
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order="C")
    A1.flags.writeable = False
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = np.random.random((4, 4, 4))
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = A1.transpose()
    A2 = wrap(A1)
    assert_references(A1, A2)

    A1 = A1.diagonal()
    A2 = wrap(A1)
    assert_references(A1, A2)
コード例 #5
0
ファイル: test_numpy_array.py プロジェクト: pybind/pybind11
def test_wrap():
    from pybind11_tests.array import wrap

    def assert_references(a, b):
        assert a is not b
        assert a.__array_interface__["data"][0] == b.__array_interface__["data"][0]
        assert a.shape == b.shape
        assert a.strides == b.strides
        assert a.flags.c_contiguous == b.flags.c_contiguous
        assert a.flags.f_contiguous == b.flags.f_contiguous
        assert a.flags.writeable == b.flags.writeable
        assert a.flags.aligned == b.flags.aligned
        assert a.flags.updateifcopy == b.flags.updateifcopy
        assert np.all(a == b)
        assert not b.flags.owndata
        assert b.base is a
        if a.flags.writeable and a.ndim == 2:
            a[0, 0] = 1234
            assert b[0, 0] == 1234

    a1 = np.array([1, 2], dtype=np.int16)
    assert a1.flags.owndata and a1.base is None
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order="F")
    assert a1.flags.owndata and a1.base is None
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order="C")
    a1.flags.writeable = False
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.random.random((4, 4, 4))
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = a1.transpose()
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = a1.diagonal()
    a2 = wrap(a1)
    assert_references(a1, a2)
コード例 #6
0
def test_wrap():
    from pybind11_tests.array import wrap

    def assert_references(a, b):
        if a is b:
            raise AssertionError
        if a.__array_interface__['data'][0] != b.__array_interface__['data'][0]:
            raise AssertionError
        if a.shape != b.shape:
            raise AssertionError
        if a.strides != b.strides:
            raise AssertionError
        if a.flags.c_contiguous != b.flags.c_contiguous:
            raise AssertionError
        if a.flags.f_contiguous != b.flags.f_contiguous:
            raise AssertionError
        if a.flags.writeable != b.flags.writeable:
            raise AssertionError
        if a.flags.aligned != b.flags.aligned:
            raise AssertionError
        if a.flags.updateifcopy != b.flags.updateifcopy:
            raise AssertionError
        if not np.all(a == b):
            raise AssertionError
        if b.flags.owndata:
            raise AssertionError
        if b.base is not a:
            raise AssertionError
        if a.flags.writeable and a.ndim == 2:
            a[0, 0] = 1234
            if b[0, 0] != 1234:
                raise AssertionError

    a1 = np.array([1, 2], dtype=np.int16)
    if not (a1.flags.owndata and a1.base is None):
        raise AssertionError
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order='F')
    if not (a1.flags.owndata and a1.base is None):
        raise AssertionError
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order='C')
    a1.flags.writeable = False
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = np.random.random((4, 4, 4))
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = a1.transpose()
    a2 = wrap(a1)
    assert_references(a1, a2)

    a1 = a1.diagonal()
    a2 = wrap(a1)
    assert_references(a1, a2)