Skip to content

PRF: Speed up point_in_path and friends #6450

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 4 commits into from
May 19, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
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
  • Loading branch information
mdboom committed May 19, 2016
commit 7976970830a10e5572e114fb1da2d4458ebd01c9
26 changes: 13 additions & 13 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,13 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
typename PathGenerator::path_iterator path = path_generator(i);

if (Ntransforms) {
typename TransformArray::sub_t subtrans = transforms[i % Ntransforms];
trans = agg::trans_affine(subtrans(0, 0),
subtrans(1, 0),
subtrans(0, 1),
subtrans(1, 1),
subtrans(0, 2),
subtrans(1, 2));
int it = i % Ntransforms;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you are using int's, but elsewhere, you use size_t. Any particular reason for that?

trans = agg::trans_affine(transforms(it, 0, 0),
transforms(it, 1, 0),
transforms(it, 0, 1),
transforms(it, 1, 1),
transforms(it, 0, 2),
transforms(it, 1, 2));
trans *= master_transform;
} else {
trans = master_transform;
Expand All @@ -989,13 +989,13 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
trans *= agg::trans_affine_translation(0.0, (double)height);

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

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

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

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

_draw_gouraud_triangle(point, color, trans, has_clippath);
}
Expand Down
28 changes: 12 additions & 16 deletions src/_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,12 @@ Image *from_color_array(ArrayType &array, bool isoutput)

for (size_t rownum = 0; rownum < (size_t)array.dim(0); rownum++) {
for (size_t colnum = 0; colnum < (size_t)array.dim(1); colnum++) {
typename ArrayType::sub_t::sub_t color = array[rownum][colnum];

r = color(0);
g = color(1);
b = color(2);
r = array(rownum, colnum, 0);
g = array(rownum, colnum, 1);
b = array(rownum, colnum, 2);

if (rgba) {
alpha = color(3);
alpha = array(rownum, colnum, 3);
}

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

for (size_t rownum = 0; rownum < (size_t)array.dim(0); rownum++) {
for (size_t colnum = 0; colnum < (size_t)array.dim(1); colnum++) {
typename ArrayType::sub_t::sub_t color = array[rownum][colnum];
r = color(0);
g = color(1);
b = color(2);
r = array(rownum, colnum, 0);
g = array(rownum, colnum, 1);
b = array(rownum, colnum, 2);

if (rgba) {
alpha = color(3);
alpha = array(rownum, colnum, 3);
}

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

typename ColorArray::sub_t::sub_t start00 = d[rowstart[i]][colstart[j]];
typename ColorArray::sub_t::sub_t start01 = d[rowstart[i]][colstart[j] + 1];
typename ColorArray::sub_t::sub_t start10 = d[rowstart[i] + 1][colstart[j]];
typename ColorArray::sub_t::sub_t start11 = d[rowstart[i] + 1][colstart[j] + 1];
for (size_t k = 0; k < 4; ++k) {
position[k] =
start00(k) * a00 + start01(k) * a01 + start10(k) * a10 + start11(k) * a11;
d(rowstart[i], colstart[j], k) * a00 +
d(rowstart[i], colstart[j] + 1, k) * a01 +
d(rowstart[i] + 1, colstart[j], k) * a10 +
d(rowstart[i] + 1, colstart[j] + 1, k) * a11;
}
position += 4;
}
Expand Down
31 changes: 15 additions & 16 deletions src/_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ void get_path_collection_extents(agg::trans_affine &master_transform,
for (i = 0; i < N; ++i) {
typename PathGenerator::path_iterator path(paths(i % Npaths));
if (Ntransforms) {
typename TransformArray::sub_t subtrans = transforms[i % Ntransforms];
trans = agg::trans_affine(subtrans(0, 0),
subtrans(1, 0),
subtrans(0, 1),
subtrans(1, 1),
subtrans(0, 2),
subtrans(1, 2));
size_t ti = i % Ntransforms;
trans = agg::trans_affine(transforms(ti, 0, 0),
transforms(ti, 1, 0),
transforms(ti, 0, 1),
transforms(ti, 1, 1),
transforms(ti, 0, 2),
transforms(ti, 1, 2));
} else {
trans = master_transform;
}
Expand Down Expand Up @@ -436,13 +436,13 @@ void point_in_path_collection(double x,
typename PathGenerator::path_iterator path = paths(i % Npaths);

if (Ntransforms) {
typename TransformArray::sub_t subtrans = transforms[i % Ntransforms];
trans = agg::trans_affine(subtrans(0, 0),
subtrans(1, 0),
subtrans(0, 1),
subtrans(1, 1),
subtrans(0, 2),
subtrans(1, 2));
size_t ti = i % Ntransforms;
trans = agg::trans_affine(transforms(ti, 0, 0),
transforms(ti, 1, 0),
transforms(ti, 0, 1),
transforms(ti, 1, 1),
transforms(ti, 0, 2),
transforms(ti, 1, 2));
trans *= master_transform;
} else {
trans = master_transform;
Expand Down Expand Up @@ -770,8 +770,7 @@ int count_bboxes_overlapping_bbox(agg::rect_d &a, BBoxArray &bboxes)

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

if (b.x2 < b.x1) {
std::swap(b.x1, b.x2);
Expand Down
2 changes: 1 addition & 1 deletion src/_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static PyObject *Py_write_png(PyObject *self, PyObject *args, PyObject *kwds)
int channels = buffer.dim(2);
std::vector<png_bytep> row_pointers(height);
for (png_uint_32 row = 0; row < (png_uint_32)height; ++row) {
row_pointers[row] = (png_bytep)buffer[row].data();
row_pointers[row] = (png_bytep)&buffer(row, 0, 0);
}

FILE *fp = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/numpy_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class array_view_accessors<AV, T, 2>
self->m_strides[1] * j);
}

sub_t operator[](npy_intp i) const
sub_t subarray(npy_intp i) const
{
const AVC *self = static_cast<const AVC *>(this);

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

sub_t operator[](npy_intp i) const
sub_t subarray(npy_intp i) const
{
const AVC *self = static_cast<const AVC *>(this);

Expand Down