Merge branch 'pybind:master' into master

This commit is contained in:
Steve R. Sun 2022-08-25 09:56:31 +08:00 committed by GitHub
commit a8a90fc7f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 36 deletions

View File

@ -1518,7 +1518,7 @@ PYBIND11_NOINLINE void register_structured_dtype(any_container<field_descriptor>
oss << '}'; oss << '}';
auto format_str = oss.str(); auto format_str = oss.str();
// Sanity check: verify that NumPy properly parses our buffer format string // Smoke test: verify that NumPy properly parses our buffer format string
auto &api = npy_api::get(); auto &api = npy_api::get();
auto arr = array(buffer_info(nullptr, itemsize, format_str, 1)); auto arr = array(buffer_info(nullptr, itemsize, format_str, 1));
if (!api.PyArray_EquivTypes_(dtype_ptr, arr.dtype().ptr())) { if (!api.PyArray_EquivTypes_(dtype_ptr, arr.dtype().ptr())) {

View File

@ -473,7 +473,7 @@ struct error_fetch_and_normalize {
+ " failed to obtain the name " + " failed to obtain the name "
"of the normalized active exception type."); "of the normalized active exception type.");
} }
#if defined(PYPY_VERSION) #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x07030a00
// This behavior runs the risk of masking errors in the error handling, but avoids a // This behavior runs the risk of masking errors in the error handling, but avoids a
// conflict with PyPy, which relies on the normalization here to change OSError to // conflict with PyPy, which relies on the normalization here to change OSError to
// FileNotFoundError (https://github.com/pybind/pybind11/issues/4075). // FileNotFoundError (https://github.com/pybind/pybind11/issues/4075).

View File

@ -251,14 +251,14 @@ def array_copy_but_one(a, r, c, v):
def test_eigen_return_references(): def test_eigen_return_references():
"""Tests various ways of returning references and non-referencing copies""" """Tests various ways of returning references and non-referencing copies"""
master = np.ones((10, 10)) primary = np.ones((10, 10))
a = m.ReturnTester() a = m.ReturnTester()
a_get1 = a.get() a_get1 = a.get()
assert not a_get1.flags.owndata and a_get1.flags.writeable assert not a_get1.flags.owndata and a_get1.flags.writeable
assign_both(a_get1, master, 3, 3, 5) assign_both(a_get1, primary, 3, 3, 5)
a_get2 = a.get_ptr() a_get2 = a.get_ptr()
assert not a_get2.flags.owndata and a_get2.flags.writeable assert not a_get2.flags.owndata and a_get2.flags.writeable
assign_both(a_get1, master, 2, 3, 6) assign_both(a_get1, primary, 2, 3, 6)
a_view1 = a.view() a_view1 = a.view()
assert not a_view1.flags.owndata and not a_view1.flags.writeable assert not a_view1.flags.owndata and not a_view1.flags.writeable
@ -271,25 +271,25 @@ def test_eigen_return_references():
a_copy1 = a.copy_get() a_copy1 = a.copy_get()
assert a_copy1.flags.owndata and a_copy1.flags.writeable assert a_copy1.flags.owndata and a_copy1.flags.writeable
np.testing.assert_array_equal(a_copy1, master) np.testing.assert_array_equal(a_copy1, primary)
a_copy1[7, 7] = -44 # Shouldn't affect anything else a_copy1[7, 7] = -44 # Shouldn't affect anything else
c1want = array_copy_but_one(master, 7, 7, -44) c1want = array_copy_but_one(primary, 7, 7, -44)
a_copy2 = a.copy_view() a_copy2 = a.copy_view()
assert a_copy2.flags.owndata and a_copy2.flags.writeable assert a_copy2.flags.owndata and a_copy2.flags.writeable
np.testing.assert_array_equal(a_copy2, master) np.testing.assert_array_equal(a_copy2, primary)
a_copy2[4, 4] = -22 # Shouldn't affect anything else a_copy2[4, 4] = -22 # Shouldn't affect anything else
c2want = array_copy_but_one(master, 4, 4, -22) c2want = array_copy_but_one(primary, 4, 4, -22)
a_ref1 = a.ref() a_ref1 = a.ref()
assert not a_ref1.flags.owndata and a_ref1.flags.writeable assert not a_ref1.flags.owndata and a_ref1.flags.writeable
assign_both(a_ref1, master, 1, 1, 15) assign_both(a_ref1, primary, 1, 1, 15)
a_ref2 = a.ref_const() a_ref2 = a.ref_const()
assert not a_ref2.flags.owndata and not a_ref2.flags.writeable assert not a_ref2.flags.owndata and not a_ref2.flags.writeable
with pytest.raises(ValueError): with pytest.raises(ValueError):
a_ref2[5, 5] = 33 a_ref2[5, 5] = 33
a_ref3 = a.ref_safe() a_ref3 = a.ref_safe()
assert not a_ref3.flags.owndata and a_ref3.flags.writeable assert not a_ref3.flags.owndata and a_ref3.flags.writeable
assign_both(a_ref3, master, 0, 7, 99) assign_both(a_ref3, primary, 0, 7, 99)
a_ref4 = a.ref_const_safe() a_ref4 = a.ref_const_safe()
assert not a_ref4.flags.owndata and not a_ref4.flags.writeable assert not a_ref4.flags.owndata and not a_ref4.flags.writeable
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -297,23 +297,23 @@ def test_eigen_return_references():
a_copy3 = a.copy_ref() a_copy3 = a.copy_ref()
assert a_copy3.flags.owndata and a_copy3.flags.writeable assert a_copy3.flags.owndata and a_copy3.flags.writeable
np.testing.assert_array_equal(a_copy3, master) np.testing.assert_array_equal(a_copy3, primary)
a_copy3[8, 1] = 11 a_copy3[8, 1] = 11
c3want = array_copy_but_one(master, 8, 1, 11) c3want = array_copy_but_one(primary, 8, 1, 11)
a_copy4 = a.copy_ref_const() a_copy4 = a.copy_ref_const()
assert a_copy4.flags.owndata and a_copy4.flags.writeable assert a_copy4.flags.owndata and a_copy4.flags.writeable
np.testing.assert_array_equal(a_copy4, master) np.testing.assert_array_equal(a_copy4, primary)
a_copy4[8, 4] = 88 a_copy4[8, 4] = 88
c4want = array_copy_but_one(master, 8, 4, 88) c4want = array_copy_but_one(primary, 8, 4, 88)
a_block1 = a.block(3, 3, 2, 2) a_block1 = a.block(3, 3, 2, 2)
assert not a_block1.flags.owndata and a_block1.flags.writeable assert not a_block1.flags.owndata and a_block1.flags.writeable
a_block1[0, 0] = 55 a_block1[0, 0] = 55
master[3, 3] = 55 primary[3, 3] = 55
a_block2 = a.block_safe(2, 2, 3, 2) a_block2 = a.block_safe(2, 2, 3, 2)
assert not a_block2.flags.owndata and a_block2.flags.writeable assert not a_block2.flags.owndata and a_block2.flags.writeable
a_block2[2, 1] = -123 a_block2[2, 1] = -123
master[4, 3] = -123 primary[4, 3] = -123
a_block3 = a.block_const(6, 7, 4, 3) a_block3 = a.block_const(6, 7, 4, 3)
assert not a_block3.flags.owndata and not a_block3.flags.writeable assert not a_block3.flags.owndata and not a_block3.flags.writeable
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -321,18 +321,18 @@ def test_eigen_return_references():
a_copy5 = a.copy_block(2, 2, 2, 3) a_copy5 = a.copy_block(2, 2, 2, 3)
assert a_copy5.flags.owndata and a_copy5.flags.writeable assert a_copy5.flags.owndata and a_copy5.flags.writeable
np.testing.assert_array_equal(a_copy5, master[2:4, 2:5]) np.testing.assert_array_equal(a_copy5, primary[2:4, 2:5])
a_copy5[1, 1] = 777 a_copy5[1, 1] = 777
c5want = array_copy_but_one(master[2:4, 2:5], 1, 1, 777) c5want = array_copy_but_one(primary[2:4, 2:5], 1, 1, 777)
a_corn1 = a.corners() a_corn1 = a.corners()
assert not a_corn1.flags.owndata and a_corn1.flags.writeable assert not a_corn1.flags.owndata and a_corn1.flags.writeable
a_corn1 *= 50 a_corn1 *= 50
a_corn1[1, 1] = 999 a_corn1[1, 1] = 999
master[0, 0] = 50 primary[0, 0] = 50
master[0, 9] = 50 primary[0, 9] = 50
master[9, 0] = 50 primary[9, 0] = 50
master[9, 9] = 999 primary[9, 9] = 999
a_corn2 = a.corners_const() a_corn2 = a.corners_const()
assert not a_corn2.flags.owndata and not a_corn2.flags.writeable assert not a_corn2.flags.owndata and not a_corn2.flags.writeable
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -340,22 +340,22 @@ def test_eigen_return_references():
# All of the changes made all the way along should be visible everywhere # All of the changes made all the way along should be visible everywhere
# now (except for the copies, of course) # now (except for the copies, of course)
np.testing.assert_array_equal(a_get1, master) np.testing.assert_array_equal(a_get1, primary)
np.testing.assert_array_equal(a_get2, master) np.testing.assert_array_equal(a_get2, primary)
np.testing.assert_array_equal(a_view1, master) np.testing.assert_array_equal(a_view1, primary)
np.testing.assert_array_equal(a_view2, master) np.testing.assert_array_equal(a_view2, primary)
np.testing.assert_array_equal(a_ref1, master) np.testing.assert_array_equal(a_ref1, primary)
np.testing.assert_array_equal(a_ref2, master) np.testing.assert_array_equal(a_ref2, primary)
np.testing.assert_array_equal(a_ref3, master) np.testing.assert_array_equal(a_ref3, primary)
np.testing.assert_array_equal(a_ref4, master) np.testing.assert_array_equal(a_ref4, primary)
np.testing.assert_array_equal(a_block1, master[3:5, 3:5]) np.testing.assert_array_equal(a_block1, primary[3:5, 3:5])
np.testing.assert_array_equal(a_block2, master[2:5, 2:4]) np.testing.assert_array_equal(a_block2, primary[2:5, 2:4])
np.testing.assert_array_equal(a_block3, master[6:10, 7:10]) np.testing.assert_array_equal(a_block3, primary[6:10, 7:10])
np.testing.assert_array_equal( np.testing.assert_array_equal(
a_corn1, master[0 :: master.shape[0] - 1, 0 :: master.shape[1] - 1] a_corn1, primary[0 :: primary.shape[0] - 1, 0 :: primary.shape[1] - 1]
) )
np.testing.assert_array_equal( np.testing.assert_array_equal(
a_corn2, master[0 :: master.shape[0] - 1, 0 :: master.shape[1] - 1] a_corn2, primary[0 :: primary.shape[0] - 1, 0 :: primary.shape[1] - 1]
) )
np.testing.assert_array_equal(a_copy1, c1want) np.testing.assert_array_equal(a_copy1, c1want)