MCPcopy Index your code
hub / github.com/DeepGraphLearning/S3F / ranges_slices

Function ranges_slices

s3f/surface.py:13–27  ·  view source on GitHub ↗

Helper function for the diagonal ranges function.

(batch)

Source from the content-addressed store, hash-verified

11
12
13def ranges_slices(batch):
14 """Helper function for the diagonal ranges function."""
15 if 'mps' in str(batch.device):
16 Ns = batch.to('cpu').bincount()
17 else:
18 Ns = batch.bincount()
19
20 indices = Ns.cumsum(0)
21 ranges = torch.cat((0 * indices[:1], indices))
22 ranges = (
23 torch.stack((ranges[:-1], ranges[1:])).t().int().contiguous().to(batch.device)
24 )
25 slices = (1 + torch.arange(len(Ns))).int().to(batch.device)
26
27 return ranges, slices
28
29
30def diagonal_ranges(batch_x=None, batch_y=None):

Callers 1

diagonal_rangesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected