mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
array: fix base handling
numpy arrays aren't currently properly setting base: by setting `->base` directly, the base doesn't follow what numpy expects and documents (that is, following chained array bases to the root array). This fixes the behaviour by using numpy's PyArray_SetBaseObject to set the base instead, and then updates the tests to reflect the fixed behaviour.
This commit is contained in:
committed by
Wenzel Jakob
parent
88fff9d189
commit
f86dddf7ba
@@ -165,7 +165,9 @@ def test_make_c_f_array():
|
||||
def test_wrap():
|
||||
from pybind11_tests.array import wrap
|
||||
|
||||
def assert_references(a, b):
|
||||
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
|
||||
@@ -177,7 +179,7 @@ def test_wrap():
|
||||
assert a.flags.updateifcopy == b.flags.updateifcopy
|
||||
assert np.all(a == b)
|
||||
assert not b.flags.owndata
|
||||
assert b.base is a
|
||||
assert b.base is base
|
||||
if a.flags.writeable and a.ndim == 2:
|
||||
a[0, 0] = 1234
|
||||
assert b[0, 0] == 1234
|
||||
@@ -201,13 +203,13 @@ def test_wrap():
|
||||
a2 = wrap(a1)
|
||||
assert_references(a1, a2)
|
||||
|
||||
a1 = a1.transpose()
|
||||
a2 = wrap(a1)
|
||||
assert_references(a1, a2)
|
||||
a1t = a1.transpose()
|
||||
a2 = wrap(a1t)
|
||||
assert_references(a1t, a2, a1)
|
||||
|
||||
a1 = a1.diagonal()
|
||||
a2 = wrap(a1)
|
||||
assert_references(a1, a2)
|
||||
a1d = a1.diagonal()
|
||||
a2 = wrap(a1d)
|
||||
assert_references(a1d, a2, a1)
|
||||
|
||||
|
||||
@pytest.requires_numpy
|
||||
|
||||
Reference in New Issue
Block a user