Skip to content

Commit 0ad7981

Browse files
authored
Merge pull request #12 from denix56/triton
Fix flake8 errors
2 parents 56d33dd + 4106591 commit 0ad7981

3 files changed

Lines changed: 25 additions & 33 deletions

File tree

torch_cluster/fps.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,6 @@
55

66
import torch_cluster.typing
77

8-
@torch.library.register_fake("torch_cluster::fps")
9-
def _(src, ptr, ratio, random_start = True):
10-
torch._check(src.device == ptr.device)
11-
torch._check(ptr.ndim == 1)
12-
13-
ctx = torch.library.get_ctx()
14-
nnz = ctx.new_dynamic_size()
15-
return ptr.new_empty((nnz,))
16-
17-
@torch.library.register_fake("torch_cluster::fps")
18-
def _(src, ptr, ratio, random_start=True):
19-
torch._check(src.device == ptr.device)
20-
torch._check(ptr.ndim == 1)
21-
22-
ctx = torch.library.get_ctx()
23-
nnz = ctx.new_dynamic_size()
24-
return ptr.new_empty((nnz,))
25-
26-
@torch.library.register_fake("torch_cluster::fps")
27-
def _(src, ptr, ratio, random_start=True):
28-
torch._check(src.device == ptr.device)
29-
torch._check(ptr.ndim == 1)
30-
31-
ctx = torch.library.get_ctx()
32-
nnz = ctx.new_dynamic_size()
33-
return ptr.new_empty((nnz,))
348

359
@torch.library.register_fake("torch_cluster::fps")
3610
def _(src, ptr, ratio, random_start=True):

torch_cluster/triton/_kernels.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,21 @@ def _nearest_kernel(
106106
best_idx = tl.zeros((BLOCK_N,), dtype=tl.int32) # Best y index.
107107

108108
if USE_BATCH:
109-
batch_id = tl.load(batch_x_ptr + offs_n, mask=mask_x, other=0) # Batch id per x.
110-
left = tl.load(ptr_y_ptr + batch_id, mask=mask_x, other=0) # y range start.
111-
right = tl.load(ptr_y_ptr + batch_id + 1, mask=mask_x, other=0) # y range end.
109+
batch_id = tl.load(
110+
batch_x_ptr + offs_n,
111+
mask=mask_x,
112+
other=0,
113+
) # Batch id per x.
114+
left = tl.load(
115+
ptr_y_ptr + batch_id,
116+
mask=mask_x,
117+
other=0,
118+
) # y range start.
119+
right = tl.load(
120+
ptr_y_ptr + batch_id + 1,
121+
mask=mask_x,
122+
other=0,
123+
) # y range end.
112124
else:
113125
left = 0 # Full y range.
114126
right = M
@@ -194,7 +206,11 @@ def _nearest_kernel(
194206
inv_y = tl.rsqrt(y_sq + EPS) # 1/||y||.
195207
dist = 1.0 - acc * (inv_y[:, None] * inv_x[None, :])
196208
else:
197-
dist = tl.fma(-2.0, acc, y_sq[:, None] + x_sq[None, :]) # L2^2 distance.
209+
dist = tl.fma(
210+
-2.0,
211+
acc,
212+
y_sq[:, None] + x_sq[None, :],
213+
) # L2^2 distance.
198214

199215
if full_y:
200216
valid = tl.broadcast_to(mask_x[None, :], (BLOCK_M, BLOCK_N))
@@ -218,7 +234,11 @@ def _nearest_kernel(
218234
best_dist = tl.where(better, block_min, best_dist)
219235
best_idx = tl.where(better, block_idx, best_idx)
220236

221-
tl.store(out_ptr + offs_n, best_idx.to(tl.int64), mask=mask_x) # Write output.
237+
tl.store(
238+
out_ptr + offs_n,
239+
best_idx.to(tl.int64),
240+
mask=mask_x,
241+
) # Write output.
222242

223243

224244
@triton.autotune(

torch_cluster/triton/knn.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from __future__ import annotations
2-
import math
3-
import triton
42
from typing import Optional
53

64
import triton

0 commit comments

Comments
 (0)