Skip to content

Use pybind11 in image module #26275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,17 +1468,26 @@ def test_str_norms(fig_test, fig_ref):

def test__resample_valid_output():
resample = functools.partial(mpl._image.resample, transform=Affine2D())
with pytest.raises(ValueError, match="must be a NumPy array"):
with pytest.raises(TypeError, match="incompatible function arguments"):
resample(np.zeros((9, 9)), None)
with pytest.raises(ValueError, match="different dimensionalities"):
resample(np.zeros((9, 9)), np.zeros((9, 9, 4)))
with pytest.raises(ValueError, match="must be RGBA"):
with pytest.raises(ValueError, match="different dimensionalities"):
resample(np.zeros((9, 9, 4)), np.zeros((9, 9)))
with pytest.raises(ValueError, match="3D input array must be RGBA"):
resample(np.zeros((9, 9, 3)), np.zeros((9, 9, 4)))
with pytest.raises(ValueError, match="3D output array must be RGBA"):
resample(np.zeros((9, 9, 4)), np.zeros((9, 9, 3)))
with pytest.raises(ValueError, match="Mismatched types"):
with pytest.raises(ValueError, match="mismatched types"):
resample(np.zeros((9, 9), np.uint8), np.zeros((9, 9)))
with pytest.raises(ValueError, match="must be C-contiguous"):
resample(np.zeros((9, 9)), np.zeros((9, 9)).T)

out = np.zeros((9, 9))
out.flags.writeable = False
with pytest.raises(ValueError, match="Output array must be writeable"):
resample(np.zeros((9, 9)), out)


def test_axesimage_get_shape():
# generate dummy image to test get_shape method
Expand Down
9 changes: 5 additions & 4 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,13 @@ def get_extensions(self):
add_libagg_flags(ext)
yield ext
# image
ext = Extension(
ext = Pybind11Extension(
"matplotlib._image", [
"src/_image_wrapper.cpp",
"src/py_converters.cpp",
])
add_numpy_flags(ext)
"src/py_converters_11.cpp",
],
cxx_std=11)
# Only need source code files agg_image_filters.cpp and agg_trans_affine.cpp
add_libagg_flags_and_sources(ext)
yield ext
# path
Expand Down
2 changes: 0 additions & 2 deletions src/_image_resample.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ typedef enum {
SINC,
LANCZOS,
BLACKMAN,
_n_interpolation
} interpolation_e;


Expand Down Expand Up @@ -629,7 +628,6 @@ static void get_filter(const resample_params_t &params,
{
switch (params.interpolation) {
case NEAREST:
case _n_interpolation:
// Never should get here. Here to silence compiler warnings.
break;

Expand Down
Loading