Skip to content

Commit

Permalink
Replace accumulate with copy on first call to antialiased stage 2 com…
Browse files Browse the repository at this point in the history
…bine
  • Loading branch information
ianthomas23 committed Aug 7, 2023
1 parent f263c56 commit 23d49a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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

0 comments on commit 23d49a5

Please sign in to comment.