8000 Rename operator[] to subarray... · matplotlib/matplotlib@7976970 · GitHub
[go: up one dir, main page]

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

Commit 7976970

Browse files
committed
Rename operator[] to subarray...
Since we now know the performance is so bad, this should discourage its use and flag it as something special. Also, use () in more places
1 parent 2c5d292 commit 7976970

File tree

5 files changed

+43
-48
lines changed

5 files changed

+43
-48
lines changed

src/_backend_agg.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,13 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
961961
typename PathGenerator::path_iterator path = path_generator(i);
962962

963963
if (Ntransforms) {
964-
typename TransformArray::sub_t subtrans = transforms[i % Ntransforms];
965-
trans = agg::trans_affine(subtrans(0, 0),
966-
subtrans(1, 0),
967-
subtrans(0, 1),
968-
subtrans(1, 1),
969-
subtrans(0, 2),
970-
subtrans(1, 2));
964+
int it = i % Ntransforms;
965+
trans = agg::trans_affine(transforms(it, 0, 0),
966+
transforms(it, 1, 0),
967+
transforms(it, 0, 1),
968+
transforms(it, 1, 1),
969+
transforms(it, 0, 2),
970+
transforms(it, 1, 2));
971971
trans *= master_transform;
972972
} else {
973973
trans = master_transform;
@@ -989,13 +989,13 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
989989
trans *= agg::trans_affine_translation(0.0, (double)height);
990990

991991
if (Nfacecolors) {
992-
typename ColorArray::sub_t facecolor = facecolors[i % Nfacecolors];
993-
face.second = agg::rgba(facecolor(0), facecolor(1), facecolor(2), facecolor(3));
992+
int ic = i % Nfacecolors;
993+
face.second = agg::rgba(facecolors(ic, 0), facecolors(ic, 1), facecolors(ic, 2), facecolors(ic, 3));
994994
}
995995

996996
if (Nedgecolors) {
997-
typename ColorArray::sub_t edgecolor = edgecolors[i % Nedgecolors];
998-
gc.color = agg::rgba(edgecolor(0), edgecolor(1), edgecolor(2), edgecolor(3));
997+
int ic = i % Nedgecolors;
998+
gc.color = agg::rgba(edgecolors(ic, 0), edgecolors(ic, 1), edgecolors(ic, 2), edgecolors(ic, 3));
999999

10001000
if (Nlinewidths) {
10011001
gc.linewidth = linewidths(i % Nlinewidths);
@@ -1274,8 +1274,8 @@ inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc,
12741274
bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans);
12751275

12761276
for (int i = 0; i < points.dim(0); ++i) {
1277-
typename PointArray::sub_t point = points[i];
1278-
typename ColorArray::sub_t color = colors[i];
1277+
typename PointArray::sub_t point = points.subarray(i);
1278+
typename ColorArray::sub_t color = colors.subarray(i);
12791279

12801280
_draw_gouraud_triangle(point, color, trans, has_clippath);
12811281
}

src/_image.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,12 @@ Image *from_color_array(ArrayType &array, bool isoutput)
126126

127127
for (size_t rownum = 0; rownum < (size_t)array.dim(0); rownum++) {
128128
for (size_t colnum = 0; colnum < (size_t)array.dim(1); colnum++) {
129-
typename ArrayType::sub_t::sub_t color = array[rownum][colnum];
130-
131-
r = col 8000 or(0);
132-
g = color(1);
133-
b = color(2);
129+
r = array(rownum, colnum, 0);
130+
g = array(rownum, colnum, 1);
131+
b = array(rownum, colnum, 2);
134132

135133
if (rgba) {
136-
alpha = color(3);
134+
alpha = array(rownum, colnum, 3);
137135
}
138136

139137
*buffer++ = int(255 * r); // red
@@ -164,13 +162,12 @@ Image *frombyte(ArrayType &array, bool isoutput)
164162

165163
for (size_t rownum = 0; rownum < (size_t)array.dim(0); rownum++) {
166164
for (size_t colnum = 0; colnum < (size_t)array.dim(1); colnum++) {
167-
typename ArrayType::sub_t::sub_t color = array[rownum][colnum];
168-
r = color(0);
169-
g = color(1);
170-
b = color(2);
165+
r = array(rownum, colnum, 0);
166+
g = array(rownum, colnum, 1);
167+
b = array(rownum, colnum, 2);
171168

172169
if (rgba) {
173-
alpha = color(3);
170+
alpha = array(rownum, colnum, 3);
174171
}
175172

176173
*buffer++ = r; // red
@@ -295,13 +292,12 @@ Image *pcolor(CoordinateArray &x,
295292
a10 = (1.0 - alpha) * beta;
296293
a11 = 1.0 - a00 - a01 - a10;
297294

298-
typename ColorArray::sub_t::sub_t start00 = d[rowstart[i]][colstart[j]];
299-
typename ColorArray::sub_t::sub_t start01 = d[rowstart[i]][colstart[j] + 1];
300-
typename ColorArray::sub_t::sub_t start10 = d[rowstart[i] + 1][colstart[j]];
301-
typename ColorArray::sub_t::sub_t start11 = d[rowstart[i] + 1][colstart[j] + 1];
302295
for (size_t k = 0; k < 4; ++k) {
303296
position[k] =
304-
start00(k) * a00 + start01(k) * a01 + start10(k) * a10 + start11(k) * a11;
297+
d(rowstart[i], colstart[j], k) * a00 +
298+
d(rowstart[i], colstart[j] + 1, k) * a01 +
299+
d(rowstart[i] + 1, colstart[j], k) * a10 +
300+
d(rowstart[i] + 1, colstart[j] + 1, k) * a11;
305301
}
306302
position += 4;
307303
}

src/_path.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,13 @@ void get_path_collection_extents(agg::trans_affine &master_transform,
384384
for (i = 0; i < N; ++i) {
385385
typename PathGenerator::path_iterator path(paths(i % Npaths));
386386
if (Ntransforms) {
387-
typename TransformArray::sub_t subtrans = transforms[i % Ntransforms];
388-
trans = agg::trans_affine(subtrans(0, 0),
389-
subtrans(1, 0),
390-
subtrans(0, 1),
391-
subtrans(1, 1),
392-
subtrans(0, 2),
393-
subtrans(1, 2));
387+
size_t ti = i % Ntransforms;
388+
trans = agg::trans_affine(transforms(ti, 0, 0),
389+
transforms(ti, 1, 0),
390+
transforms(ti, 0, 1),
391+
transforms(ti, 1, 1),
392+
transforms(ti, 0, 2),
393+
transforms(ti, 1, 2));
394394
} else {
395395
trans = master_transform;
396396
}
@@ -436,13 +436,13 @@ void point_in_path_collection(double x,
436436
typename PathGenerator::path_iterator path = paths(i % Npaths);
437437

438438
if (Ntransforms) {
439-
typename TransformArray::sub_t subtrans = transforms[i % Ntransforms];
440-
trans = agg::trans_affine(subtrans(0, 0),
441-
subtrans(1, 0),
442-
subtrans(0, 1),
443-
subtrans(1, 1),
444-
subtrans(0, 2),
445-
subtrans(1, 2));
439+
size_t ti = i % Ntransforms;
440+
trans = agg::trans_affine(transforms(ti, 0, 0),
441+
transforms(ti, 1, 0),
442+
transforms(ti, 0, 1),
443+
transforms(ti, 1, 1),
444+
transforms(ti, 0, 2),
445+
transforms(ti, 1, 2));
446446
trans *= master_transform;
447447
} else {
448448
trans = master_transform;
@@ -770,8 +770,7 @@ int count_bboxes_overlapping_bbox(agg::rect_d &a, BBoxArray &bboxes)
770770

771771
size_t num_bboxes = bboxes.size();
772772
for (size_t i = 0; i < num_bboxes; ++i) {
773-
typename BBoxArray::sub_t bbox_b = bboxes[i];
774-
b = agg::rect_d(bbox_b(0, 0), bbox_b(0, 1), bbox_b(1, 0), bbox_b(1, 1));
773+
b = agg::rect_d(bboxes(i, 0, 0), bboxes(i, 0, 1), bboxes(i, 1, 0), bboxes(i, 1, 1));
775774

776775
if (b.x2 < b.x1) {
777776
std::swap(b.x1, b.x2);

src/_png.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static PyObject *Py_write_png(PyObject *self, PyObject *args, PyObject *kwds)
9191
int channels = buffer.dim(2);
9292
std::vector<png_bytep> row_pointers(height);
9393
for (png_uint_32 row = 0; row < (png_uint_32)height; ++row) {
94-
row_pointers[row] = (png_bytep)buffer[row].data();
94+
row_pointers[row] = (png_bytep)&buffer(row, 0, 0);
9595
}
9696

9797
FILE *fp = NULL;

src/numpy_cpp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class array_view_accessors<AV, T, 2>
284284
self->m_strides[1] * j);
285285
}
286286

287-
sub_t operator[](npy_intp i) const
287+
sub_t subarray(npy_intp i) const
288288
{
289289
const AVC *self = static_cast<const AVC *>(this);
290290

@@ -318,7 +318,7 @@ class array_view_accessors<AV, T, 3>
318318
self->m_strides[1] * j + self->m_strides[2] * k);
319319
}
320320

321-
sub_t operator[](npy_intp i) const
321+
sub_t subarray(npy_intp i) const
322322
{
323323
const AVC *self = static_cast<const AVC *>(this);
324324

0 commit comments

Comments
 (0)
0