Skip to content
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

Replace accumulate with copy on first call to antialiased stage 2 combine #1264

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions datashader/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,16 @@ def make_antialias_stage_2_functions(antialias_stage_2):
for func in set(funcs):
namespace[func.__name__] = func

lines = ["def aa_stage_2_accumulate(aggs_and_copies):"]
lines = [
"def aa_stage_2_accumulate(aggs_and_copies, first_pass):",
# Don't need to accumulate if first_pass, just copy (opposite of aa_stage_2_copy_back)
" if first_pass:",
" for a in literal_unroll(aggs_and_copies):",
" a[1][:] = a[0][:]",
" else:",
]
for i, func in enumerate(funcs):
lines.append(f" {func.__name__}(aggs_and_copies[{i}][1], aggs_and_copies[{i}][0])")
lines.append(f" {func.__name__}(aggs_and_copies[{i}][1], aggs_and_copies[{i}][0])")

code = "\n".join(lines)
exec(code, namespace)
Expand Down
14 changes: 8 additions & 6 deletions datashader/glyphs/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ def cpu_antialias_2agg_impl(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys,
if ncols == 1:
return

aa_stage_2_accumulate(aggs_and_accums)
aa_stage_2_accumulate(aggs_and_accums, j==0)

if j < ncols - 1:
aa_stage_2_clear(aggs_and_accums)
Expand Down Expand Up @@ -1208,7 +1208,7 @@ def cpu_antialias_2agg_impl(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys,
if xs.shape[0] == 1:
return

aa_stage_2_accumulate(aggs_and_accums)
aa_stage_2_accumulate(aggs_and_accums, i==0)

if i < xs.shape[0] - 1:
aa_stage_2_clear(aggs_and_accums)
Expand Down Expand Up @@ -1302,7 +1302,7 @@ def cpu_antialias_2agg_impl(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys,
if ys.shape[0] == 1:
return

aa_stage_2_accumulate(aggs_and_accums)
aa_stage_2_accumulate(aggs_and_accums, i==0)

if i < ys.shape[0] - 1:
aa_stage_2_clear(aggs_and_accums)
Expand Down Expand Up @@ -1398,7 +1398,7 @@ def cpu_antialias_2agg_impl(sx, tx, sy, ty, xmin, xmax, ymin, ymax, xs, ys,
if xs.shape[0] == 1:
return

aa_stage_2_accumulate(aggs_and_accums)
aa_stage_2_accumulate(aggs_and_accums, i==0)

if i < xs.shape[0] - 1:
aa_stage_2_clear(aggs_and_accums)
Expand Down Expand Up @@ -1574,7 +1574,7 @@ def extend_cpu_numba_antialias_2agg(
if nrows == 1:
return

aa_stage_2_accumulate(aggs_and_accums)
aa_stage_2_accumulate(aggs_and_accums, i==0)

if i < nrows - 1:
aa_stage_2_clear(aggs_and_accums)
Expand Down Expand Up @@ -1728,6 +1728,7 @@ def extend_cpu_numba_antialias_2agg(
antialias = antialias_stage_2 is not None
buffer = np.empty(8) if antialias else None

first_pass = True
for i in eligible_inds:
if missing[i]:
continue
Expand Down Expand Up @@ -1772,7 +1773,8 @@ def extend_cpu_numba_antialias_2agg(
segment_start, segment_end, x0, x1, y0, y1,
0.0, 0.0, buffer, *aggs_and_cols)

aa_stage_2_accumulate(aggs_and_accums)
aa_stage_2_accumulate(aggs_and_accums, first_pass)
first_pass = False
aa_stage_2_clear(aggs_and_accums)

aa_stage_2_copy_back(aggs_and_accums)
Expand Down