Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Rename py namespace to mpl in extension code #27086

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 2 commits into from
Oct 14, 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
4 changes: 2 additions & 2 deletions 4 src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ RendererAgg::restore_region(BufferRegion &region, int xx1, int yy1, int xx2, int
rendererBase.copy_from(rbuf, &rect, x, y);
}

bool RendererAgg::render_clippath(py::PathIterator &clippath,
bool RendererAgg::render_clippath(mpl::PathIterator &clippath,
const agg::trans_affine &clippath_trans,
e_snap_mode snap_mode)
{
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
typedef agg::conv_transform<mpl::PathIterator> transformed_path_t;
typedef PathNanRemover<transformed_path_t> nan_removed_t;
/* Unlike normal Paths, the clip path cannot be clipped to the Figure bbox,
* because it needs to remain a complete closed path, so there is no
Expand Down
10 changes: 5 additions & 5 deletions 10 src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class RendererAgg
template <class R>
void set_clipbox(const agg::rect_d &cliprect, R &rasterizer);

bool render_clippath(py::PathIterator &clippath, const agg::trans_affine &clippath_trans, e_snap_mode snap_mode);
bool render_clippath(mpl::PathIterator &clippath, const agg::trans_affine &clippath_trans, e_snap_mode snap_mode);

template <class PathIteratorType>
void _draw_path(PathIteratorType &path, bool has_clippath, const facepair_t &face, GCAgg &gc);
Expand Down Expand Up @@ -340,11 +340,11 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
rendererBase.reset_clipping(true);

// Create and transform the path
typedef agg::conv_transform<py::PathIterator> hatch_path_trans_t;
typedef agg::conv_transform<mpl::PathIterator> hatch_path_trans_t;
typedef agg::conv_curve<hatch_path_trans_t> hatch_path_curve_t;
typedef agg::conv_stroke<hatch_path_curve_t> hatch_path_stroke_t;

py::PathIterator hatch_path(gc.hatchpath);
mpl::PathIterator hatch_path(gc.hatchpath);
agg::trans_affine hatch_trans;
hatch_trans *= agg::trans_affine_scaling(1.0, -1.0);
hatch_trans *= agg::trans_affine_translation(0.0, 1.0);
Expand Down Expand Up @@ -447,7 +447,7 @@ template <class PathIterator>
inline void
RendererAgg::draw_path(GCAgg &gc, PathIterator &path, agg::trans_affine &trans, agg::rgba &color)
{
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
typedef agg::conv_transform<mpl::PathIterator> transformed_path_t;
typedef PathNanRemover<transformed_path_t> nan_removed_t;
typedef PathClipper<nan_removed_t> clipped_t;
typedef PathSnapper<clipped_t> snapped_t;
Expand Down Expand Up @@ -490,7 +490,7 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
agg::trans_affine &trans,
agg::rgba color)
{
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
typedef agg::conv_transform<mpl::PathIterator> transformed_path_t;
typedef PathNanRemover<transformed_path_t> nan_removed_t;
typedef PathSnapper<nan_removed_t> snap_t;
typedef agg::conv_curve<snap_t> curve_t;
Expand Down
4 changes: 2 additions & 2 deletions 4 src/_backend_agg_basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

struct ClipPath
{
py::PathIterator path;
mpl::PathIterator path;
agg::trans_affine trans;
};

Expand Down Expand Up @@ -103,7 +103,7 @@ class GCAgg

e_snap_mode snap_mode;

py::PathIterator hatchpath;
mpl::PathIterator hatchpath;
agg::rgba hatch_color;
double hatch_linewidth;

Expand Down
8 changes: 4 additions & 4 deletions 8 src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static void PyRendererAgg_dealloc(PyRendererAgg *self)
static PyObject *PyRendererAgg_draw_path(PyRendererAgg *self, PyObject *args)
{
GCAgg gc;
py::PathIterator path;
mpl::PathIterator path;
agg::trans_affine trans;
PyObject *faceobj = NULL;
agg::rgba face;
Expand Down Expand Up @@ -263,9 +263,9 @@ static PyObject *PyRendererAgg_draw_text_image(PyRendererAgg *self, PyObject *ar
PyObject *PyRendererAgg_draw_markers(PyRendererAgg *self, PyObject *args)
{
GCAgg gc;
py::PathIterator marker_path;
mpl::PathIterator marker_path;
agg::trans_affine marker_path_trans;
py::PathIterator path;
mpl::PathIterator path;
agg::trans_affine trans;
PyObject *faceobj = NULL;
agg::rgba face;
Expand Down Expand Up @@ -328,7 +328,7 @@ PyRendererAgg_draw_path_collection(PyRendererAgg *self, PyObject *args)
{
GCAgg gc;
agg::trans_affine master_transform;
py::PathGenerator paths;
mpl::PathGenerator paths;
numpy::array_view<const double, 3> transforms;
numpy::array_view<const double, 2> offsets;
agg::trans_affine offset_trans;
Expand Down
72 changes: 37 additions & 35 deletions 72 src/_image_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "_image_resample.h"
#include "py_converters_11.h"

namespace py = pybind11;
using namespace pybind11::literals;

/**********************************************************************
* Free functions
Expand Down Expand Up @@ -46,8 +48,8 @@ radius: float, default: 1
)""";


static pybind11::array_t<double>
_get_transform_mesh(const pybind11::object& transform, const pybind11::ssize_t *dims)
static py::array_t<double>
_get_transform_mesh(const py::object& transform, const py::ssize_t *dims)
{
/* TODO: Could we get away with float, rather than double, arrays here? */

Expand All @@ -58,8 +60,8 @@ _get_transform_mesh(const pybind11::object& transform, const pybind11::ssize_t *
// If attribute doesn't exist, raises Python AttributeError
auto inverse = transform.attr("inverted")();

pybind11::ssize_t mesh_dims[2] = {dims[0]*dims[1], 2};
pybind11::array_t<double> input_mesh(mesh_dims);
py::ssize_t mesh_dims[2] = {dims[0]*dims[1], 2};
py::array_t<double> input_mesh(mesh_dims);
auto p = input_mesh.mutable_data();

for (auto y = 0; y < dims[0]; ++y) {
Expand All @@ -72,7 +74,7 @@ _get_transform_mesh(const pybind11::object& transform, const pybind11::ssize_t *
auto output_mesh = inverse.attr("transform")(input_mesh);

auto output_mesh_array =
pybind11::array_t<double, pybind11::array::c_style | pybind11::array::forcecast>(output_mesh);
py::array_t<double, py::array::c_style | py::array::forcecast>(output_mesh);

if (output_mesh_array.ndim() != 2) {
throw std::runtime_error(
Expand All @@ -84,12 +86,12 @@ _get_transform_mesh(const pybind11::object& transform, const pybind11::ssize_t *
}


// Using generic pybind::array for input and output arrays rather than the more usual
// pybind::array_t<type> as function supports multiple array dtypes.
// Using generic py::array for input and output arrays rather than the more usual
// py::array_t<type> as this function supports multiple array dtypes.
static void
image_resample(pybind11::array input_array,
pybind11::array& output_array,
const pybind11::object& transform,
image_resample(py::array input_array,
py::array& output_array,
const py::object& transform,
interpolation_e interpolation,
bool resample_, // Avoid name clash with resample() function
float alpha,
Expand All @@ -111,7 +113,7 @@ image_resample(pybind11::array input_array,
}

// Ensure input array is contiguous, regardless of dtype
input_array = pybind11::array::ensure(input_array, pybind11::array::c_style);
input_array = py::array::ensure(input_array, py::array::c_style);

// Validate output array
auto out_ndim = output_array.ndim();
Expand All @@ -132,7 +134,7 @@ image_resample(pybind11::array input_array,
throw std::invalid_argument("Input and output arrays have mismatched types");
}

if ((output_array.flags() & pybind11::array::c_style) == 0) {
if ((output_array.flags() & py::array::c_style) == 0) {
throw std::invalid_argument("Output array must be C-contiguous");
}

Expand All @@ -150,14 +152,14 @@ image_resample(pybind11::array input_array,

// Only used if transform is not affine.
// Need to keep it in scope for the duration of this function.
pybind11::array_t<double> transform_mesh;
py::array_t<double> transform_mesh;

// Validate transform
if (transform.is_none()) {
params.is_affine = true;
} else {
// Raises Python AttributeError if no such attribute or TypeError if cast fails
bool is_affine = pybind11::cast<bool>(transform.attr("is_affine"));
bool is_affine = py::cast<bool>(transform.attr("is_affine"));

if (is_affine) {
convert_trans_affine(transform, params.affine);
Expand All @@ -171,20 +173,20 @@ image_resample(pybind11::array input_array,

if (auto resampler =
(ndim == 2) ? (
(dtype.is(pybind11::dtype::of<std::uint8_t>())) ? resample<agg::gray8> :
(dtype.is(pybind11::dtype::of<std::int8_t>())) ? resample<agg::gray8> :
(dtype.is(pybind11::dtype::of<std::uint16_t>())) ? resample<agg::gray16> :
(dtype.is(pybind11::dtype::of<std::int16_t>())) ? resample<agg::gray16> :
(dtype.is(pybind11::dtype::of<float>())) ? resample<agg::gray32> :
(dtype.is(pybind11::dtype::of<double>())) ? resample<agg::gray64> :
(dtype.is(py::dtype::of<std::uint8_t>())) ? resample<agg::gray8> :
(dtype.is(py::dtype::of<std::int8_t>())) ? resample<agg::gray8> :
(dtype.is(py::dtype::of<std::uint16_t>())) ? resample<agg::gray16> :
(dtype.is(py::dtype::of<std::int16_t>())) ? resample<agg::gray16> :
(dtype.is(py::dtype::of<float>())) ? resample<agg::gray32> :
(dtype.is(py::dtype::of<double>())) ? resample<agg::gray64> :
nullptr) : (
// ndim == 3
(dtype.is(pybind11::dtype::of<std::uint8_t>())) ? resample<agg::rgba8> :
(dtype.is(pybind11::dtype::of<std::int8_t>())) ? resample<agg::rgba8> :
(dtype.is(pybind11::dtype::of<std::uint16_t>())) ? resample<agg::rgba16> :
(dtype.is(pybind11::dtype::of<std::int16_t>())) ? resample<agg::rgba16> :
(dtype.is(pybind11::dtype::of<float>())) ? resample<agg::rgba32> :
(dtype.is(pybind11::dtype::of<double>())) ? resample<agg::rgba64> :
(dtype.is(py::dtype::of<std::uint8_t>())) ? resample<agg::rgba8> :
(dtype.is(py::dtype::of<std::int8_t>())) ? resample<agg::rgba8> :
(dtype.is(py::dtype::of<std::uint16_t>())) ? resample<agg::rgba16> :
(dtype.is(py::dtype::of<std::int16_t>())) ? resample<agg::rgba16> :
(dtype.is(py::dtype::of<float>())) ? resample<agg::rgba32> :
(dtype.is(py::dtype::of<double>())) ? resample<agg::rgba64> :
nullptr)) {
Py_BEGIN_ALLOW_THREADS
resampler(
Expand All @@ -199,7 +201,7 @@ image_resample(pybind11::array input_array,


PYBIND11_MODULE(_image, m) {
pybind11::enum_<interpolation_e>(m, "_InterpolationType")
py::enum_<interpolation_e>(m, "_InterpolationType")
.value("NEAREST", NEAREST)
.value("BILINEAR", BILINEAR)
.value("BICUBIC", BICUBIC)
Expand All @@ -220,13 +222,13 @@ PYBIND11_MODULE(_image, m) {
.export_values();

m.def("resample", &image_resample,
pybind11::arg("input_array"),
pybind11::arg("output_array"),
pybind11::arg("transform"),
pybind11::arg("interpolation") = interpolation_e::NEAREST,
pybind11::arg("resample") = false,
pybind11::arg("alpha") = 1,
pybind11::arg("norm") = false,
pybind11::arg("radius") = 1,
"input_array"_a,
"output_array"_a,
"transform"_a,
"interpolation"_a = interpolation_e::NEAREST,
"resample"_a = false,
"alpha"_a = 1,
"norm"_a = false,
"radius"_a = 1,
image_resample__doc__);
}
10 changes: 5 additions & 5 deletions 10 src/_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ inline bool segments_intersect(const double &x1,
template <class PathIterator1, class PathIterator2>
bool path_intersects_path(PathIterator1 &p1, PathIterator2 &p2)
{
typedef PathNanRemover<py::PathIterator> no_nans_t;
typedef PathNanRemover<mpl::PathIterator> no_nans_t;
typedef agg::conv_curve<no_nans_t> curve_t;

if (p1.total_vertices() < 2 || p2.total_vertices() < 2) {
Expand Down Expand Up @@ -920,7 +920,7 @@ bool path_intersects_rectangle(PathIterator &path,
double rect_x2, double rect_y2,
bool filled)
{
typedef PathNanRemover<py::PathIterator> no_nans_t;
typedef PathNanRemover<mpl::PathIterator> no_nans_t;
typedef agg::conv_curve<no_nans_t> curve_t;

if (path.total_vertices() == 0) {
Expand Down Expand Up @@ -966,7 +966,7 @@ void convert_path_to_polygons(PathIterator &path,
int closed_only,
std::vector<Polygon> &result)
{
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
typedef agg::conv_transform<mpl::PathIterator> transformed_path_t;
typedef PathNanRemover<transformed_path_t> nan_removal_t;
typedef PathClipper<nan_removal_t> clipped_t;
typedef PathSimplifier<clipped_t> simplify_t;
Expand Down Expand Up @@ -1032,7 +1032,7 @@ void cleanup_path(PathIterator &path,
std::vector<double> &vertices,
std::vector<unsigned char> &codes)
{
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
typedef agg::conv_transform<mpl::PathIterator> transformed_path_t;
typedef PathNanRemover<transformed_path_t> nan_removal_t;
typedef PathClipper<nan_removal_t> clipped_t;
typedef PathSnapper<clipped_t> snapped_t;
Expand Down Expand Up @@ -1189,7 +1189,7 @@ bool convert_to_string(PathIterator &path,
std::string& buffer)
{
size_t buffersize;
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
typedef agg::conv_transform<mpl::PathIterator> transformed_path_t;
typedef PathNanRemover<transformed_path_t> nan_removal_t;
typedef PathClipper<nan_removal_t> clipped_t;
typedef PathSimplifier<clipped_t> simplify_t;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.