MCPcopy Create free account
hub / github.com/QWTforGithub/T2LDM / forward

Method forward

pointops/functions/pointops.py:498–527  ·  view source on GitHub ↗

KNN Indexing input: nsample: int32, Number of neighbor xyz: (b, n, 3) coordinates of the features new_xyz: (b, m, 3) centriods output: new_features: (b, m, nsample)

(ctx, nsample: int, xyz: torch.Tensor, new_xyz: torch.Tensor = None)

Source from the content-addressed store, hash-verified

496class KNNQueryExclude(Function):
497 @staticmethod
498 def forward(ctx, nsample: int, xyz: torch.Tensor, new_xyz: torch.Tensor = None) -> Tuple[torch.Tensor]:
499 """
500 KNN Indexing
501 input: nsample: int32, Number of neighbor
502 xyz: (b, n, 3) coordinates of the features
503 new_xyz: (b, m, 3) centriods
504 output: new_features: (b, m, nsample)
505 """
506 if new_xyz is None:
507 new_xyz = xyz
508 b, m, _ = new_xyz.size()
509 n = xyz.size(1)
510
511 '''
512 idx = torch.zeros(b, m, nsample).int().cuda()
513 for i in range(b):
514 dist = pairwise_distances(new_xyz[i, :, :], xyz[i, :, :])
515 [_, idxs] = torch.sort(dist, dim=1)
516 idx[i, :, :] = idxs[:, 0:nsample]
517 '''
518
519 # '''
520 # new_xyz_repeat = new_xyz.repeat(1, 1, n).view(b, m * n, 3)
521 # xyz_repeat = xyz.repeat(1, m, 1).view(b, m * n, 3)
522 # dist = (new_xyz_repeat - xyz_repeat).pow(2).sum(dim=2).view(b, m, n)
523 dist = (new_xyz.repeat(1, 1, n).view(b, m * n, 3) - xyz.repeat(1, m, 1).view(b, m * n, 3)).pow(2).sum(dim=2).view(b, m, n)
524 [_, idxs] = torch.sort(dist, dim=2)
525 idx = idxs[:, :, 1:nsample+1].int()
526 # '''
527 return idx
528
529 @staticmethod
530 def backward(ctx):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected