Skip to content

Commit

Permalink
Reduction append functions return index not boolean (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 authored Feb 13, 2023
1 parent d8167b4 commit 198c0b4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion datashader/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def make_append(bases, cols, calls, glyph, categorical, antialias):
if where_reduction:
# where reduction needs access to the return of the contained
# reduction, which is the preceding one here.
body[-2] = 'if ' + body[-2] + ':'
body[-2] = 'if ' + body[-2] + ' >= 0:'
body[-1] = ' ' + body[-1]

body = ['{0} = {1}[y, x]'.format(name, arg_lk[agg])
Expand Down
128 changes: 64 additions & 64 deletions datashader/reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ def _antialias_stage_2(self, self_intersect, array_module):
def _append(x, y, agg, field):
if not isnull(field):
agg[y, x] += 1
return True
return False
return 0
return -1

@staticmethod
@ngjit
Expand All @@ -449,23 +449,23 @@ def _append_antialias(x, y, agg, field, aa_factor):
agg[y, x] = aa_factor
else:
agg[y, x] += aa_factor
return True
return False
return 0
return -1

@staticmethod
@ngjit
def _append_antialias_not_self_intersect(x, y, agg, field, aa_factor):
if not isnull(field):
if isnull(agg[y, x]) or aa_factor > agg[y, x]:
agg[y, x] = aa_factor
return True
return False
return 0
return -1

@staticmethod
@ngjit
def _append_no_field(x, y, agg):
agg[y, x] += 1
return True
return 0

@staticmethod
@ngjit
Expand All @@ -474,46 +474,46 @@ def _append_no_field_antialias(x, y, agg, aa_factor):
agg[y, x] = aa_factor
else:
agg[y, x] += aa_factor
return True
return 0

@staticmethod
@ngjit
def _append_no_field_antialias_not_self_intersect(x, y, agg, aa_factor):
if isnull(agg[y, x]) or aa_factor > agg[y, x]:
agg[y, x] = aa_factor
return True
return False
return 0
return -1

# GPU append functions
@staticmethod
@nb_cuda.jit(device=True)
def _append_antialias_cuda(x, y, agg, field, aa_factor):
value = field*aa_factor
return cuda_atomic_nanmax(agg, (y, x), value) != value
return 0 if cuda_atomic_nanmax(agg, (y, x), value) != value else -1

@staticmethod
@nb_cuda.jit(device=True)
def _append_no_field_antialias_cuda_not_self_intersect(x, y, agg, aa_factor):
return cuda_atomic_nanmax(agg, (y, x), aa_factor) != aa_factor
return 0 if cuda_atomic_nanmax(agg, (y, x), aa_factor) != aa_factor else -1

@staticmethod
@nb_cuda.jit(device=True)
def _append_cuda(x, y, agg, field):
if not isnull(field):
nb_cuda.atomic.add(agg, (y, x), 1)
return True
return False
return 0
return -1

@staticmethod
@nb_cuda.jit(device=True)
def _append_no_field_antialias_cuda(x, y, agg, aa_factor):
return cuda_atomic_nanmax(agg, (y, x), aa_factor) != aa_factor
return 0 if cuda_atomic_nanmax(agg, (y, x), aa_factor) != aa_factor else -1

@staticmethod
@nb_cuda.jit(device=True)
def _append_no_field_cuda(x, y, agg):
nb_cuda.atomic.add(agg, (y, x), 1)
return True
return 0

def _build_combine(self, dshape, antialias):
if antialias:
Expand Down Expand Up @@ -646,31 +646,31 @@ def _antialias_stage_2(self, self_intersect, array_module):
def _append(x, y, agg, field):
if not isnull(field):
agg[y, x] = True
return True
return False
return 0
return -1

@staticmethod
@ngjit
def _append_antialias(x, y, agg, field, aa_factor):
if not isnull(field):
if isnull(agg[y, x]) or aa_factor > agg[y, x]:
agg[y, x] = aa_factor
return True
return False
return 0
return -1

@staticmethod
@ngjit
def _append_no_field(x, y, agg):
agg[y, x] = True
return True
return 0

@staticmethod
@ngjit
def _append_no_field_antialias(x, y, agg, aa_factor):
if isnull(agg[y, x]) or aa_factor > agg[y, x]:
agg[y, x] = aa_factor
return True
return False
return 0
return -1

# GPU append functions
_append_cuda =_append
Expand Down Expand Up @@ -763,8 +763,8 @@ def _append(x, y, agg, field):
if not isnull(field):
# agg[y, x] cannot be null as initialised to zero.
agg[y, x] += field
return True
return False
return 0
return -1

@staticmethod
@ngjit
Expand All @@ -773,8 +773,8 @@ def _append_antialias(x, y, agg, field, aa_factor):
if not isnull(value):
# agg[y, x] cannot be null as initialised to zero.
agg[y, x] += value
return True
return False
return 0
return -1

@staticmethod
@ngjit
Expand All @@ -783,17 +783,17 @@ def _append_antialias_not_self_intersect(x, y, agg, field, aa_factor):
if not isnull(value) and value > agg[y, x]:
# agg[y, x] cannot be null as initialised to zero.
agg[y, x] = value
return True
return False
return 0
return -1

# GPU append functions
@staticmethod
@nb_cuda.jit(device=True)
def _append_cuda(x, y, agg, field):
if not isnull(field):
nb_cuda.atomic.add(agg, (y, x), field)
return True
return False
return 0
return -1

@staticmethod
def _combine(aggs):
Expand Down Expand Up @@ -863,8 +863,8 @@ def _append(x, y, agg, field):
agg[y, x] = field
else:
agg[y, x] += field
return True
return False
return 0
return -1

@staticmethod
@ngjit
Expand All @@ -875,8 +875,8 @@ def _append_antialias(x, y, agg, field, aa_factor):
agg[y, x] = value
else:
agg[y, x] += value
return True
return False
return 0
return -1

@staticmethod
@ngjit
Expand All @@ -885,8 +885,8 @@ def _append_antialias_not_self_intersect(x, y, agg, field, aa_factor):
if not isnull(value):
if isnull(agg[y, x]) or value > agg[y, x]:
agg[y, x] = value
return True
return False
return 0
return -1

@staticmethod
def _combine(aggs):
Expand Down Expand Up @@ -936,8 +936,8 @@ def _append(x, y, m2, field, sum, count):
u1 = np.float64(sum) / count
u = np.float64(sum + field) / (count + 1)
m2[y, x] += (field - u1) * (field - u)
return True
return False
return 0
return -1

@staticmethod
def _combine(Ms, sums, ns):
Expand Down Expand Up @@ -967,23 +967,23 @@ def _antialias_stage_2(self, self_intersect, array_module):
def _append(x, y, agg, field):
if isnull(agg[y, x]) or agg[y, x] > field:
agg[y, x] = field
return True
return False
return 0
return -1

@staticmethod
@ngjit
def _append_antialias(x, y, agg, field, aa_factor):
value = field*aa_factor
if isnull(agg[y, x]) or value > agg[y, x]:
agg[y, x] = value
return True
return False
return 0
return -1

# GPU append functions
@staticmethod
@nb_cuda.jit(device=True)
def _append_cuda(x, y, agg, field):
return cuda_atomic_nanmin(agg, (y, x), field) != field
return 0 if cuda_atomic_nanmin(agg, (y, x), field) != field else -1

@staticmethod
def _combine(aggs):
Expand All @@ -1008,29 +1008,29 @@ def _antialias_stage_2(self, self_intersect, array_module):
def _append(x, y, agg, field):
if isnull(agg[y, x]) or agg[y, x] < field:
agg[y, x] = field
return True
return False
return 0
return -1

@staticmethod
@ngjit
def _append_antialias(x, y, agg, field, aa_factor):
value = field*aa_factor
if isnull(agg[y, x]) or value > agg[y, x]:
agg[y, x] = value
return True
return False
return 0
return -1

# GPU append functions
@staticmethod
@nb_cuda.jit(device=True)
def _append_antialias_cuda(x, y, agg, field, aa_factor):
value = field*aa_factor
return cuda_atomic_nanmax(agg, (y, x), value) != value
return 0 if cuda_atomic_nanmax(agg, (y, x), value) != value else -1

@staticmethod
@nb_cuda.jit(device=True)
def _append_cuda(x, y, agg, field):
return cuda_atomic_nanmax(agg, (y, x), field) != field
return 0 if cuda_atomic_nanmax(agg, (y, x), field) != field else -1

@staticmethod
def _combine(aggs):
Expand Down Expand Up @@ -1140,17 +1140,17 @@ def _antialias_stage_2(self, self_intersect, array_module):
def _append(x, y, agg, field):
if not isnull(field) and isnull(agg[y, x]):
agg[y, x] = field
return True
return False
return 0
return -1

@staticmethod
@ngjit
def _append_antialias(x, y, agg, field, aa_factor):
value = field*aa_factor
if isnull(agg[y, x]) or value > agg[y, x]:
agg[y, x] = value
return True
return False
return 0
return -1

@staticmethod
def _combine(aggs):
Expand Down Expand Up @@ -1190,17 +1190,17 @@ def _antialias_stage_2(self, self_intersect, array_module):
def _append(x, y, agg, field):
if not isnull(field):
agg[y, x] = field
return True
return False
return 0
return -1

@staticmethod
@ngjit
def _append_antialias(x, y, agg, field, aa_factor):
value = field*aa_factor
if isnull(agg[y, x]) or value > agg[y, x]:
agg[y, x] = value
return True
return False
return 0
return -1

@staticmethod
def _combine(aggs):
Expand Down Expand Up @@ -1306,25 +1306,25 @@ def _antialias_stage_2(self, self_intersect, array_module):
@ngjit
def _append(x, y, agg, field):
agg[y, x] = field
return True
return 0

@staticmethod
@ngjit
def _append_antialias(x, y, agg, field, aa_factor):
agg[y, x] = field
return True
return 0

@staticmethod
@nb_cuda.jit(device=True)
def _append_antialias_cuda(x, y, agg, field, aa_factor):
agg[y, x] = field
return True
return 0

@staticmethod
@nb_cuda.jit(device=True)
def _append_cuda(x, y, agg, field):
agg[y, x] = field
return True
return 0

def _build_append(self, dshape, schema, cuda, antialias, self_intersect):
# If self.column is None then append function still receives a 'field'
Expand Down Expand Up @@ -1355,7 +1355,7 @@ def combine_cpu(aggs, selector_aggs):
for y in range(ny):
for x in range(nx):
value = selector_aggs[1][y, x]
if not invalid(value) and append(x, y, selector_aggs[0], value):
if not invalid(value) and append(x, y, selector_aggs[0], value) >= 0:
aggs[0][y, x] = aggs[1][y, x]

@nb_cuda.jit
Expand All @@ -1364,7 +1364,7 @@ def combine_cuda(aggs, selector_aggs):
x, y = nb_cuda.grid(2)
if x < nx and y < ny:
value = selector_aggs[1][y, x]
if not invalid(value) and append(x, y, selector_aggs[0], value):
if not invalid(value) and append(x, y, selector_aggs[0], value) >= 0:
aggs[0][y, x] = aggs[1][y, x]

def wrapped_combine(aggs, selector_aggs):
Expand Down

0 comments on commit 198c0b4

Please sign in to comment.