Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff4ab66

Browse files
committed
Make norm argument to _image.resample a bool.
It only accepts a boolean on the Python side, but this is not enforced on the C++ side. This causes many casting warnings since it's used multiple times calling various filters that only take a `bool`.
1 parent a57ba96 commit ff4ab66

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

lib/matplotlib/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
412412
t,
413413
_interpd_[self.get_interpolation()],
414414
self.get_resample(), 1.0,
415-
self.get_filternorm() or 0.0,
415+
self.get_filternorm(),
416416
self.get_filterrad() or 0.0)
417417

418418
# we are done with A_scaled now, remove from namespace
@@ -447,7 +447,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
447447
t,
448448
_interpd_[self.get_interpolation()],
449449
True, 1,
450-
self.get_filternorm() or 0.0,
450+
self.get_filternorm(),
451451
self.get_filterrad() or 0.0)
452452
# we are done with the mask, delete from namespace to be sure!
453453
del mask
@@ -481,7 +481,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
481481
_image.resample(
482482
A, output, t, _interpd_[self.get_interpolation()],
483483
self.get_resample(), alpha,
484-
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
484+
self.get_filternorm(), self.get_filterrad() or 0.0)
485485

486486
# at this point output is either a 2D array of normed data
487487
# (of int or float)

src/_image_resample.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ struct resample_params_t {
800800
agg::trans_affine affine;
801801
const double *transform_mesh;
802802
bool resample;
803-
double norm;
803+
bool norm;
804804
double radius;
805805
double alpha;
806806
};

src/_image_wrapper.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* */
1515

1616
const char* image_resample__doc__ =
17-
"resample(input_array, output_array, matrix, interpolation=NEAREST, alpha=1.0, norm=0, radius=1)\n\n"
17+
"resample(input_array, output_array, matrix, interpolation=NEAREST, alpha=1.0, norm=False, radius=1)\n\n"
1818

1919
"Resample input_array, blending it in-place into output_array, using an\n"
2020
"affine transformation.\n\n"
@@ -48,8 +48,8 @@ const char* image_resample__doc__ =
4848
" The level of transparency to apply. 1.0 is completely opaque.\n"
4949
" 0.0 is completely transparent.\n\n"
5050

51-
"norm : float, optional\n"
52-
" The norm for the interpolation function. Default is 0.\n\n"
51+
"norm : bool, optional\n"
52+
" Whether to norm the interpolation function. Default is `False`.\n\n"
5353

5454
"radius: float, optional\n"
5555
" The radius of the kernel, if method is SINC, LANCZOS or BLACKMAN.\n"
@@ -120,6 +120,7 @@ image_resample(PyObject *self, PyObject* args, PyObject *kwargs)
120120
PyObject *py_transform = NULL;
121121
resample_params_t params;
122122
int resample_;
123+
int norm_;
123124

124125
PyArrayObject *input_array = NULL;
125126
PyArrayObject *output_array = NULL;
@@ -132,9 +133,9 @@ image_resample(PyObject *self, PyObject* args, PyObject *kwargs)
132133
"resample", "alpha", "norm", "radius", NULL };
133134

134135
if (!PyArg_ParseTupleAndKeywords(
135-
args, kwargs, "OOO|iiddd:resample", (char **)kwlist,
136+
args, kwargs, "OOO|iidid:resample", (char **)kwlist,
136137
&py_input_array, &py_output_array, &py_transform,
137-
&params.interpolation, &resample_, &params.alpha, &params.norm,
138+
&params.interpolation, &resample_, &params.alpha, &norm_,
138139
&params.radius)) {
139140
return NULL;
140141
}
@@ -146,6 +147,7 @@ image_resample(PyObject *self, PyObject* args, PyObject *kwargs)
146147
}
147148

148149
params.resample = (resample_ != 0);
150+
params.norm = (norm_ != 0);
149151

150152
input_array = (PyArrayObject *)PyArray_FromAny(
151153
py_input_array, NULL, 2, 3, NPY_ARRAY_C_CONTIGUOUS, NULL);

0 commit comments

Comments
 (0)