gridpoints 1.1.1__tar.gz → 1.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gridpoints
3
- Version: 1.1.1
3
+ Version: 1.1.2
4
4
  Summary: fast multidimensional sorting tool for point clouds using the monotonic lagrangian grid
5
5
  Author: Armand de Cacqueray
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "gridpoints"
7
- version = "1.1.1"
7
+ version = "1.1.2"
8
8
  description = "fast multidimensional sorting tool for point clouds using the monotonic lagrangian grid "
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -10,4 +10,4 @@ __all__ = (
10
10
  "pad",
11
11
  )
12
12
 
13
- __version__ = "1.1.1"
13
+ __version__ = "1.1.2"
@@ -2,7 +2,7 @@
2
2
  Helper to complete point clouds so that they fit a grid.
3
3
  """
4
4
 
5
- from .array_libs import arange, astype, empty
5
+ from .array_libs import arange, astype, empty, get_backend
6
6
 
7
7
 
8
8
  def pad(X, n_total, value="nan"):
@@ -26,23 +26,31 @@ def pad(X, n_total, value="nan"):
26
26
  X_padded : array (n_total, D) or (B, n_total, D)
27
27
  """
28
28
  assert value in ("nan", "inf"), f"value must be 'nan' or 'inf', got {value!r}"
29
- single = hasattr(X, 'ndim') and X.ndim == 2
30
- clouds = [X] if single else list(X)
31
- assert max(len(c) for c in clouds) <= n_total, "more points than n_total"
29
+ is_array = hasattr(X, 'ndim')
30
+ ref = X if is_array else X[0]
31
+ assert (X.shape[-2] if is_array else max(len(c) for c in X)) <= n_total, "more points than n_total"
32
32
 
33
- ref = clouds[0]
34
33
  dtype = str(ref.dtype).replace('torch.', '')
35
34
  if 'float' not in dtype: # integers cannot hold nan / inf
36
35
  dtype = 'float64'
37
36
  D = ref.shape[-1]
38
- out = empty((len(clouds), n_total, D), dtype, ref)
39
- out[...] = float(value)
37
+ shape = (n_total, D) if is_array and X.ndim == 2 else (len(X), n_total, D)
40
38
 
41
- for b, cloud in enumerate(clouds):
42
- out[b, :len(cloud)] = astype(cloud, dtype)
43
- if value == "inf": # point k gets the signs given by the bits of k, one per coordinate
44
- k = arange(n_total - len(cloud), 'int64', ref)[:, None]
45
- bits = (k >> (D - 1 - arange(D, 'int64', ref))[None, :]) & 1
46
- out[b, len(cloud):] = astype(1 - 2 * bits, dtype) * float("inf")
39
+ # 1. Prefill with nan, then copy the true points in.
40
+ out = empty(shape, dtype, ref)
41
+ out[...] = float('nan')
42
+ if is_array:
43
+ out[..., :X.shape[-2], :] = astype(X, dtype)
44
+ else:
45
+ for b, cloud in enumerate(X):
46
+ out[b, :len(cloud)] = astype(cloud, dtype)
47
47
 
48
- return out[0] if single else out
48
+ # 2. Turn the nans into +/-inf: point k, coordinate d gets the sign of bit d of k.
49
+ if value == "inf":
50
+ xp, _ = get_backend(out)
51
+ k = arange(n_total, 'int64', ref)[:, None]
52
+ d = arange(D, 'int64', ref)[None, :]
53
+ signs = astype(1 - 2 * ((k // 2 ** (D - 1 - d)) % 2), dtype) # (n_total, D)
54
+ out = xp.where(xp.isnan(out), signs * float('inf'), out)
55
+
56
+ return out
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gridpoints
3
- Version: 1.1.1
3
+ Version: 1.1.2
4
4
  Summary: fast multidimensional sorting tool for point clouds using the monotonic lagrangian grid
5
5
  Author: Armand de Cacqueray
6
6
  License: MIT
File without changes
File without changes
File without changes