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

Skip to content

Commit c1e6873

Browse files
committed
Rename array_view.dim to shape
This matches the name from pybind11, and will make it easier to reuse templated code with either.
1 parent 26f12fa commit c1e6873

File tree

8 files changed

+31
-31
lines changed

8 files changed

+31
-31
lines changed

src/_backend_agg.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -731,22 +731,22 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
731731
rendererBase.reset_clipping(true);
732732
if (angle != 0.0) {
733733
agg::rendering_buffer srcbuf(
734-
image.data(), (unsigned)image.dim(1),
735-
(unsigned)image.dim(0), (unsigned)image.dim(1));
734+
image.data(), (unsigned)image.shape(1),
735+
(unsigned)image.shape(0), (unsigned)image.shape(1));
736736
agg::pixfmt_gray8 pixf_img(srcbuf);
737737

738738
set_clipbox(gc.cliprect, theRasterizer);
739739

740740
agg::trans_affine mtx;
741-
mtx *= agg::trans_affine_translation(0, -image.dim(0));
741+
mtx *= agg::trans_affine_translation(0, -image.shape(0));
742742
mtx *= agg::trans_affine_rotation(-angle * (agg::pi / 180.0));
743743
mtx *= agg::trans_affine_translation(x, y);
744744

745745
agg::path_storage rect;
746746
rect.move_to(0, 0);
747-
rect.line_to(image.dim(1), 0);
748-
rect.line_to(image.dim(1), image.dim(0));
749-
rect.line_to(0, image.dim(0));
747+
rect.line_to(image.shape(1), 0);
748+
rect.line_to(image.shape(1), image.shape(0));
749+
rect.line_to(0, image.shape(0));
750750
rect.line_to(0, 0);
751751
agg::conv_transform<agg::path_storage> rect2(rect, mtx);
752752

@@ -767,10 +767,10 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
767767
} else {
768768
agg::rect_i fig, text;
769769

770-
int deltay = y - image.dim(0);
770+
int deltay = y - image.shape(0);
771771

772772
fig.init(0, 0, width, height);
773-
text.init(x, deltay, x + image.dim(1), y);
773+
text.init(x, deltay, x + image.shape(1), y);
774774
text.clip(fig);
775775

776776
if (gc.cliprect.x1 != 0.0 || gc.cliprect.y1 != 0.0 || gc.cliprect.x2 != 0.0 || gc.cliprect.y2 != 0.0) {
@@ -832,19 +832,19 @@ inline void RendererAgg::draw_image(GCAgg &gc,
832832

833833
agg::rendering_buffer buffer;
834834
buffer.attach(
835-
image.data(), (unsigned)image.dim(1), (unsigned)image.dim(0), -(int)image.dim(1) * 4);
835+
image.data(), (unsigned)image.shape(1), (unsigned)image.shape(0), -(int)image.shape(1) * 4);
836836
pixfmt pixf(buffer);
837837

838838
if (has_clippath) {
839839
agg::trans_affine mtx;
840840
agg::path_storage rect;
841841

842-
mtx *= agg::trans_affine_translation((int)x, (int)(height - (y + image.dim(0))));
842+
mtx *= agg::trans_affine_translation((int)x, (int)(height - (y + image.shape(0))));
843843

844844
rect.move_to(0, 0);
845-
rect.line_to(image.dim(1), 0);
846-
rect.line_to(image.dim(1), image.dim(0));
847-
rect.line_to(0, image.dim(0));
845+
rect.line_to(image.shape(1), 0);
846+
rect.line_to(image.shape(1), image.shape(0));
847+
rect.line_to(0, image.shape(0));
848848
rect.line_to(0, 0);
849849

850850
agg::conv_transform<agg::path_storage> rect2(rect, mtx);
@@ -880,7 +880,7 @@ inline void RendererAgg::draw_image(GCAgg &gc,
880880
} else {
881881
set_clipbox(gc.cliprect, rendererBase);
882882
rendererBase.blend_from(
883-
pixf, 0, (int)x, (int)(height - (y + image.dim(0))), (agg::int8u)(alpha * 255));
883+
pixf, 0, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255));
884884
}
885885

886886
rendererBase.reset_clipping(true);
@@ -1234,7 +1234,7 @@ inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc,
12341234
set_clipbox(gc.cliprect, theRasterizer);
12351235
bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans, gc.snap_mode);
12361236

1237-
for (int i = 0; i < points.dim(0); ++i) {
1237+
for (int i = 0; i < points.shape(0); ++i) {
12381238
typename PointArray::sub_t point = points.subarray(i);
12391239
typename ColorArray::sub_t color = colors.subarray(i);
12401240

src/_backend_agg_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ PyRendererAgg_draw_gouraud_triangles(PyRendererAgg *self, PyObject *args)
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",
469-
points.dim(0), colors.dim(0));
469+
points.shape(0), colors.shape(0));
470470
return NULL;
471471
}
472472

src/_path.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void get_path_collection_extents(agg::trans_affine &master_transform,
379379
agg::trans_affine &offset_trans,
380380
extent_limits &extent)
381381
{
382-
if (offsets.size() != 0 && offsets.dim(1) != 2) {
382+
if (offsets.size() != 0 && offsets.shape(1) != 2) {
383383
throw std::runtime_error("Offsets array must have shape (N, 2)");
384384
}
385385

@@ -709,7 +709,7 @@ clip_path_to_rect(PathIterator &path, agg::rect_d &rect, bool inside, std::vecto
709709
template <class VerticesArray, class ResultArray>
710710
void affine_transform_2d(VerticesArray &vertices, agg::trans_affine &trans, ResultArray &result)
711711
{
712-
if (vertices.size() != 0 && vertices.dim(1) != 2) {
712+
if (vertices.size() != 0 && vertices.shape(1) != 2) {
713713
throw std::runtime_error("Invalid vertices array.");
714714
}
715715

@@ -739,7 +739,7 @@ void affine_transform_2d(VerticesArray &vertices, agg::trans_affine &trans, Resu
739739
template <class VerticesArray, class ResultArray>
740740
void affine_transform_1d(VerticesArray &vertices, agg::trans_affine &trans, ResultArray &result)
741741
{
742-
if (vertices.dim(0) != 2) {
742+
if (vertices.shape(0) != 2) {
743743
throw std::runtime_error("Invalid vertices array.");
744744
}
745745

src/_path_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ static PyObject *Py_update_path_extents(PyObject *self, PyObject *args)
118118
return NULL;
119119
}
120120

121-
if (minpos.dim(0) != 2) {
121+
if (minpos.shape(0) != 2) {
122122
PyErr_Format(PyExc_ValueError,
123123
"minpos must be of length 2, got %" NPY_INTP_FMT,
124-
minpos.dim(0));
124+
minpos.shape(0));
125125
return NULL;
126126
}
127127

src/_qhull_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ delaunay(PyObject *self, PyObject *args)
267267
return NULL;
268268
}
269269

270-
npoints = xarray.dim(0);
271-
if (npoints != yarray.dim(0)) {
270+
npoints = xarray.shape(0);
271+
if (npoints != yarray.shape(0)) {
272272
PyErr_SetString(PyExc_ValueError,
273273
"x and y must be 1D arrays of the same length");
274274
return NULL;

src/array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class scalar
2929
return m_value;
3030
}
3131

32-
int dim(size_t i)
32+
int shape(size_t i)
3333
{
3434
return 1;
3535
}
@@ -65,7 +65,7 @@ class empty
6565
return empty<T>();
6666
}
6767

68-
int dim(size_t i) const
68+
int shape(size_t i) const
6969
{
7070
return 0;
7171
}

src/mplutils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ inline int prepare_and_add_type(PyTypeObject *type, PyObject *module)
7272
template<typename T>
7373
inline bool check_trailing_shape(T array, char const* name, long d1)
7474
{
75-
if (array.dim(1) != d1) {
75+
if (array.shape(1) != d1) {
7676
PyErr_Format(PyExc_ValueError,
7777
"%s must have shape (N, %ld), got (%ld, %ld)",
78-
name, d1, array.dim(0), array.dim(1));
78+
name, d1, array.shape(0), array.shape(1));
7979
return false;
8080
}
8181
return true;
@@ -84,10 +84,10 @@ inline bool check_trailing_shape(T array, char const* name, long d1)
8484
template<typename T>
8585
inline bool check_trailing_shape(T array, char const* name, long d1, long d2)
8686
{
87-
if (array.dim(1) != d1 || array.dim(2) != d2) {
87+
if (array.shape(1) != d1 || array.shape(2) != d2) {
8888
PyErr_Format(PyExc_ValueError,
8989
"%s must have shape (N, %ld, %ld), got (%ld, %ld, %ld)",
90-
name, d1, d2, array.dim(0), array.dim(1), array.dim(2));
90+
name, d1, d2, array.shape(0), array.shape(1), array.shape(2));
9191
return false;
9292
}
9393
return true;

src/numpy_cpp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
492492
return true;
493493
}
494494

495-
npy_intp dim(size_t i) const
495+
npy_intp shape(size_t i) const
496496
{
497497
if (i >= ND) {
498498
return 0;
@@ -515,7 +515,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
515515
if (empty) {
516516
return 0;
517517
} else {
518-
return (size_t)dim(0);
518+
return (size_t)shape(0);
519519
}
520520
}
521521

0 commit comments

Comments
 (0)