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

Skip to content

Commit 02fa8fc

Browse files
committed
Replace some calls to array_view.size with .shape(0)
The other dimensions have already been confirmed to be non-zero, so size() == shape(0) in these cases.
1 parent c1e6873 commit 02fa8fc

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

lib/matplotlib/tests/test_transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,9 @@ def test_invalid_arguments():
627627
t.transform([])
628628
with pytest.raises(RuntimeError):
629629
t.transform([1])
630-
with pytest.raises(RuntimeError):
630+
with pytest.raises(ValueError):
631631
t.transform([[1]])
632-
with pytest.raises(RuntimeError):
632+
with pytest.raises(ValueError):
633633
t.transform([[1, 2, 3]])
634634

635635

src/_backend_agg_wrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,13 @@ PyRendererAgg_draw_gouraud_triangles(PyRendererAgg *self, PyObject *args)
456456
&trans)) {
457457
return NULL;
458458
}
459-
if (points.size() && !check_trailing_shape(points, "points", 3, 2)) {
459+
if (points.shape(0) && !check_trailing_shape(points, "points", 3, 2)) {
460460
return NULL;
461461
}
462-
if (colors.size() && !check_trailing_shape(colors, "colors", 3, 4)) {
462+
if (colors.shape(0) && !check_trailing_shape(colors, "colors", 3, 4)) {
463463
return NULL;
464464
}
465-
if (points.size() != colors.size()) {
465+
if (points.shape(0) != colors.shape(0)) {
466466
PyErr_Format(PyExc_ValueError,
467467
"points and colors arrays must be the same length, got "
468468
"%" NPY_INTP_FMT " points and %" NPY_INTP_FMT "colors",

src/_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void affine_transform_2d(VerticesArray &vertices, agg::trans_affine &trans, Resu
713713
throw std::runtime_error("Invalid vertices array.");
714714
}
715715

716-
size_t n = vertices.size();
716+
size_t n = vertices.shape(0);
717717
double x;
718718
double y;
719719
double t0;

src/_path_wrapper.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ static PyObject *Py_points_in_path(PyObject *self, PyObject *args)
8383
return NULL;
8484
}
8585

86-
npy_intp dims[] = { (npy_intp)points.size() };
86+
if (!check_trailing_shape(points, "points", 2)) {
87+
return NULL;
88+
}
89+
90+
npy_intp dims[] = { (npy_intp)points.shape(0) };
8791
numpy::array_view<uint8_t, 1> results(dims);
8892

8993
CALL_CPP("points_in_path", (points_in_path(points, r, path, trans, results)));
@@ -361,15 +365,19 @@ static PyObject *Py_affine_transform(PyObject *self, PyObject *args)
361365
numpy::array_view<double, 2> vertices(vertices_arr);
362366
Py_DECREF(vertices_arr);
363367

364-
npy_intp dims[] = { (npy_intp)vertices.size(), 2 };
368+
if(!check_trailing_shape(vertices, "vertices", 2)) {
369+
return NULL;
370+
}
371+
372+
npy_intp dims[] = { (npy_intp)vertices.shape(0), 2 };
365373
numpy::array_view<double, 2> result(dims);
366374
CALL_CPP("affine_transform", (affine_transform_2d(vertices, trans, result)));
367375
return result.pyobj();
368376
} else { // PyArray_NDIM(vertices_arr) == 1
369377
numpy::array_view<double, 1> vertices(vertices_arr);
370378
Py_DECREF(vertices_arr);
371379

372-
npy_intp dims[] = { (npy_intp)vertices.size() };
380+
npy_intp dims[] = { (npy_intp)vertices.shape(0) };
373381
numpy::array_view<double, 1> result(dims);
374382
CALL_CPP("affine_transform", (affine_transform_1d(vertices, trans, result)));
375383
return result.pyobj();

0 commit comments

Comments
 (0)