utils.py

class gnp.utils.QueryTorchGeometric(x: Tensor, device='cpu')[source]

Bases: object

A wrapper for performing k-nearest neighbor and radius queries on a point cloud using PyTorch Geometric.

Parameters:
  • x (torch.Tensor) -- The point cloud data to be queried, of shape (N, D).

  • device (str, optional) -- The device to store the point cloud on, by default "cpu".

query_knn(queries: Tensor, k: int) Tuple[Tensor, Tensor][source]

Find the k-nearest neighbors for a set of query points.

Parameters:
  • queries (torch.Tensor) -- The query points, of shape (M, D).

  • k (int) -- The number of nearest neighbors to find.

Returns:

A tuple containing: - The distances to the k-nearest neighbors, shape (M, k). - The indices of the k-nearest neighbors, shape (M, k).

Return type:

Tuple[torch.Tensor, torch.Tensor]

static query_radius(x: Tensor, y: Tensor, radius: float, max_num_neighbors: int = 100) Tuple[Tensor, Tensor][source]

Find all points in x within a given radius of points in y.

This method finds all pairs (i, j) such that the distance between x[i] and y[j] is less than the radius.

Parameters:
  • x (torch.Tensor) -- The point cloud to search within (the "haystack").

  • y (torch.Tensor) -- The query points (the "needles").

  • radius (float) -- The search radius.

  • max_num_neighbors (int, optional) -- The maximum number of neighbors to return for each query point, by default 100.

Returns:

A tuple containing: - index_x: Indices of the found points in x. - index_y: Indices of the corresponding query points in y.

Return type:

Tuple[torch.Tensor, torch.Tensor]

gnp.utils.smooth_values_by_gaussian(x: Tensor, values: Tensor, radius: float) Tensor[source]

Smooth values on a point cloud using a truncated Gaussian kernel.

For each point, this function computes a weighted average of the values of its neighbors within a given radius. The weights are determined by a Gaussian function of the distance.

Parameters:
  • x (torch.Tensor) -- The input data points, shape (N, D).

  • values (torch.Tensor) -- The values associated with each point to be smoothed, shape (N,).

  • radius (float) -- The truncation radius for the Gaussian kernel. The standard deviation of the Gaussian is set to one-third of this radius.

Returns:

A tensor of shape (N,) containing the smoothed values.

Return type:

torch.Tensor

gnp.utils.subsample_points_by_radius(x: Tensor, radius: float) Tensor[source]

Subsample points using a parallel maximal independent set approach.

Parameters:
  • x (torch.Tensor) -- The input points to subsample, shape (N, D).

  • radius (float) -- The radius for defining neighborhoods.

Returns:

A tensor containing the indices of the subsampled points.

Return type:

torch.Tensor