differt 0.0.18__tar.gz → 0.0.20__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.
- {differt-0.0.18 → differt-0.0.20}/PKG-INFO +2 -2
- {differt-0.0.18 → differt-0.0.20}/pyproject.toml +1 -1
- {differt-0.0.18 → differt-0.0.20}/src/differt/geometry/paths.py +148 -10
- {differt-0.0.18 → differt-0.0.20}/src/differt/geometry/triangle_mesh.py +47 -24
- {differt-0.0.18 → differt-0.0.20}/src/differt/geometry/utils.py +46 -1
- {differt-0.0.18 → differt-0.0.20}/src/differt/plotting/__init__.py +9 -1
- {differt-0.0.18 → differt-0.0.20}/src/differt/plotting/_core.py +207 -6
- {differt-0.0.18 → differt-0.0.20}/src/differt/rt/utils.py +36 -25
- differt-0.0.20/src/differt/scene/triangle_scene.py +452 -0
- differt-0.0.18/src/differt/scene/triangle_scene.py +0 -284
- {differt-0.0.18 → differt-0.0.20}/.gitignore +0 -0
- {differt-0.0.18 → differt-0.0.20}/LICENSE.md +0 -0
- {differt-0.0.18 → differt-0.0.20}/README.md +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/__init__.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/em/__init__.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/em/constants.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/em/special.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/em/utd.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/em/utils.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/geometry/__init__.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/plotting/_utils.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/rt/__init__.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/rt/fermat.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/rt/image_method.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/scene/__init__.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/scene/sionna.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/utils.py +0 -0
- {differt-0.0.18 → differt-0.0.20}/src/differt/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.20
|
|
4
4
|
Summary: Differentiable Ray Tracing Toolbox for Radio Propagation Simulations
|
|
5
5
|
Project-URL: Changelog, https://github.com/jeertmans/DiffeRT/releases
|
|
6
6
|
Project-URL: Documentation, https://eertmans.be/DiffeRT
|
|
@@ -21,7 +21,7 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
21
21
|
Requires-Python: >=3.10
|
|
22
22
|
Requires-Dist: beartype>=0.17.2
|
|
23
23
|
Requires-Dist: chex>=0.1.86
|
|
24
|
-
Requires-Dist: differt-core==0.0.
|
|
24
|
+
Requires-Dist: differt-core==0.0.20
|
|
25
25
|
Requires-Dist: equinox>=0.11.5
|
|
26
26
|
Requires-Dist: filelock>=3.15.4
|
|
27
27
|
Requires-Dist: jax>=0.4.32
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Ray paths utilities."""
|
|
2
2
|
|
|
3
|
+
import sys
|
|
3
4
|
from collections.abc import Callable, Iterator
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
@@ -8,10 +9,69 @@ import jax
|
|
|
8
9
|
import jax.numpy as jnp
|
|
9
10
|
import numpy as np
|
|
10
11
|
from beartype import beartype as typechecker
|
|
11
|
-
from jaxtyping import Array, ArrayLike, Bool, Float, Int, jaxtyped
|
|
12
|
+
from jaxtyping import Array, ArrayLike, Bool, Float, Int, Shaped, jaxtyped
|
|
12
13
|
|
|
13
14
|
from differt.plotting import draw_paths
|
|
14
15
|
|
|
16
|
+
if sys.version_info >= (3, 11):
|
|
17
|
+
from typing import Self
|
|
18
|
+
else:
|
|
19
|
+
from typing_extensions import Self
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@jax.jit
|
|
23
|
+
@jaxtyped(typechecker=typechecker)
|
|
24
|
+
def _cluster_ids(array: Shaped[Array, "batch n"]) -> Int[Array, " batch"]:
|
|
25
|
+
@jaxtyped(typechecker=typechecker)
|
|
26
|
+
def scan_fun(
|
|
27
|
+
indices: Int[Array, " batch"],
|
|
28
|
+
row_and_index: tuple[Shaped[Array, " n"], Int[Array, " "]],
|
|
29
|
+
) -> tuple[Int[Array, " batch"], None]:
|
|
30
|
+
row, index = row_and_index
|
|
31
|
+
indices = jnp.where((array == row).all(axis=-1), index, indices)
|
|
32
|
+
return indices, None
|
|
33
|
+
|
|
34
|
+
return jax.lax.scan(
|
|
35
|
+
scan_fun,
|
|
36
|
+
init=jnp.empty(array.shape[0], dtype=jnp.int32),
|
|
37
|
+
xs=(array, jnp.arange(array.shape[0])),
|
|
38
|
+
reverse=True,
|
|
39
|
+
)[0]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@jax.jit
|
|
43
|
+
@jaxtyped(typechecker=typechecker)
|
|
44
|
+
def merge_cluster_ids(
|
|
45
|
+
cluster_ids_a: Int[Array, " *batch"],
|
|
46
|
+
cluster_ids_b: Int[Array, " *batch"],
|
|
47
|
+
) -> Int[Array, " *batch"]:
|
|
48
|
+
"""
|
|
49
|
+
Merge two arrays of cluster indices as returned by :meth:`Paths.multipath_clusters`.
|
|
50
|
+
|
|
51
|
+
Let the returned array be ``cluster_ids``,
|
|
52
|
+
then ``cluster_ids[i] == cluster_ids[j]`` for all ``i``,
|
|
53
|
+
``j`` indices if
|
|
54
|
+
``(groups_a[i], groups_b[i]) == (groups_a[j], groups_b[j])``,
|
|
55
|
+
granted that arrays have been reshaped to uni-dimensional
|
|
56
|
+
arrays. Of course, this method handles multiple dimensions
|
|
57
|
+
and will reshape the output array to match initial shape.
|
|
58
|
+
|
|
59
|
+
Warning:
|
|
60
|
+
The indices used in the returned array have nothing to
|
|
61
|
+
do with the ones used in individual arrays.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
cluster_ids_a: The first array of cluster indices.
|
|
65
|
+
cluster_ids_b: The second array of cluster indices.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
The new array group indices.
|
|
69
|
+
"""
|
|
70
|
+
batch = cluster_ids_a.shape
|
|
71
|
+
return _cluster_ids(
|
|
72
|
+
jnp.stack((cluster_ids_a, cluster_ids_b), axis=-1).reshape(-1, 2),
|
|
73
|
+
).reshape(batch)
|
|
74
|
+
|
|
15
75
|
|
|
16
76
|
@jaxtyped(typechecker=typechecker)
|
|
17
77
|
class Paths(eqx.Module):
|
|
@@ -41,6 +101,30 @@ class Paths(eqx.Module):
|
|
|
41
101
|
store valid paths.
|
|
42
102
|
"""
|
|
43
103
|
|
|
104
|
+
@jaxtyped(
|
|
105
|
+
typechecker=None
|
|
106
|
+
) # typing.Self is (currently) not compatible with jaxtyping and beartype
|
|
107
|
+
def reshape(self, *batch: int) -> Self:
|
|
108
|
+
"""
|
|
109
|
+
Return a copy with reshaped paths' batch dimensions to match a given shape.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
batch: The new batch shapes.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
A new paths instance with specified batch dimensions.
|
|
116
|
+
"""
|
|
117
|
+
vertices = self.vertices.reshape(*batch, self.path_length, 3)
|
|
118
|
+
objects = self.objects.reshape(*batch, self.path_length)
|
|
119
|
+
mask = self.mask.reshape(*batch) if self.mask is not None else None
|
|
120
|
+
|
|
121
|
+
return eqx.tree_at(
|
|
122
|
+
lambda p: (p.vertices, p.objects, p.mask),
|
|
123
|
+
self,
|
|
124
|
+
(vertices, objects, mask),
|
|
125
|
+
is_leaf=lambda x: x is None,
|
|
126
|
+
)
|
|
127
|
+
|
|
44
128
|
@property
|
|
45
129
|
@jaxtyped(typechecker=typechecker)
|
|
46
130
|
def path_length(self) -> int:
|
|
@@ -90,6 +174,59 @@ class Paths(eqx.Module):
|
|
|
90
174
|
return objects[mask, ...]
|
|
91
175
|
return objects
|
|
92
176
|
|
|
177
|
+
@eqx.filter_jit
|
|
178
|
+
@jaxtyped(typechecker=typechecker)
|
|
179
|
+
def multipath_clusters(
|
|
180
|
+
self,
|
|
181
|
+
axis: int = -1,
|
|
182
|
+
) -> Int[Array, " *partial_batch"]:
|
|
183
|
+
"""
|
|
184
|
+
Return an array of same multipath cluster indices.
|
|
185
|
+
|
|
186
|
+
Let the returned array be ``cluster_ids``,
|
|
187
|
+
then ``cluster_ids[i] == cluster_ids[j]`` for all ``i``,
|
|
188
|
+
``j`` indices if ``self.mask[i, :] == self.mask[j, :]``,
|
|
189
|
+
granted that each array has been reshaped to a two-dimensional
|
|
190
|
+
array and that ``axis`` is the last dimension. Of course, this
|
|
191
|
+
method handles multiple dimensions and will reshape the output
|
|
192
|
+
array to match initial shape, except for dimension ``axis``
|
|
193
|
+
that is removed.
|
|
194
|
+
|
|
195
|
+
The purpose of this method is to easily identify similar
|
|
196
|
+
multipath structures, when a group of paths all have the
|
|
197
|
+
same path candidates that are valid.
|
|
198
|
+
|
|
199
|
+
If the different path candidates are not all on the same axis,
|
|
200
|
+
e.g., as a result of masking invalid paths, then you can still
|
|
201
|
+
use :meth:`group_by_objects` to identify similar paths.
|
|
202
|
+
Note that :meth:`group_by_objects` will possibly return
|
|
203
|
+
different indices for different transmitter / receiver pairs,
|
|
204
|
+
as they have different indices. To avoid this, you should probably
|
|
205
|
+
slice the :attr:`objects` array to exclude first and last objects, i.e.,
|
|
206
|
+
with ``self.objects[..., 1:-1]``.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
axis: The axis along to compare paths.
|
|
210
|
+
|
|
211
|
+
By default, the last axis is used to match the
|
|
212
|
+
``num_path_candidates`` axis as returned by
|
|
213
|
+
:meth:`TriangleScene.compute_paths<differt.scene.triangle_scene.TriangleScene.compute_paths`.
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
The array of group indices.
|
|
217
|
+
|
|
218
|
+
Raises:
|
|
219
|
+
ValueError: If :attr:`mask` is None.
|
|
220
|
+
"""
|
|
221
|
+
if self.mask is None:
|
|
222
|
+
msg = "Cannot create multiplath clusters from non-existing mask!"
|
|
223
|
+
raise ValueError(msg)
|
|
224
|
+
|
|
225
|
+
mask = jnp.moveaxis(self.mask, axis, -1)
|
|
226
|
+
*partial_batch, last_axis = mask.shape
|
|
227
|
+
|
|
228
|
+
return _cluster_ids(mask.reshape(-1, last_axis)).reshape(partial_batch)
|
|
229
|
+
|
|
93
230
|
@jax.jit
|
|
94
231
|
@jaxtyped(typechecker=typechecker)
|
|
95
232
|
def group_by_objects(self) -> Int[Array, " *batch"]:
|
|
@@ -99,6 +236,10 @@ class Paths(eqx.Module):
|
|
|
99
236
|
This function is useful to group paths that
|
|
100
237
|
undergo the same types of interactions.
|
|
101
238
|
|
|
239
|
+
Internally, it uses the same logic as
|
|
240
|
+
:meth:`multipath_clusters`, but applied to object indices
|
|
241
|
+
rather than on mask.
|
|
242
|
+
|
|
102
243
|
Returns:
|
|
103
244
|
An array of group indices.
|
|
104
245
|
|
|
@@ -131,19 +272,15 @@ class Paths(eqx.Module):
|
|
|
131
272
|
>>> paths = Paths(vertices, objects)
|
|
132
273
|
>>> groups = paths.group_by_objects()
|
|
133
274
|
>>> groups
|
|
134
|
-
Array([[
|
|
135
|
-
[
|
|
275
|
+
Array([[ 0, 0, 2, 3, 4, 2],
|
|
276
|
+
[ 3, 7, 7, 9, 10, 2]], dtype=int32)
|
|
136
277
|
"""
|
|
137
278
|
*batch, path_length = self.objects.shape
|
|
138
279
|
|
|
139
280
|
objects = self.objects.reshape((-1, path_length))
|
|
140
|
-
|
|
141
|
-
objects, axis=0, size=objects.shape[0], return_inverse=True
|
|
142
|
-
)[1]
|
|
143
|
-
|
|
144
|
-
return inverse.reshape(batch)
|
|
281
|
+
return _cluster_ids(objects).reshape(batch)
|
|
145
282
|
|
|
146
|
-
def __iter__(self) -> Iterator[
|
|
283
|
+
def __iter__(self) -> Iterator[Self]:
|
|
147
284
|
"""Return an iterator over masked paths.
|
|
148
285
|
|
|
149
286
|
Each item of the iterator is itself an instance :class:`Paths`,
|
|
@@ -152,10 +289,11 @@ class Paths(eqx.Module):
|
|
|
152
289
|
Yields:
|
|
153
290
|
Masked paths, one at a time.
|
|
154
291
|
"""
|
|
292
|
+
cls = type(self)
|
|
155
293
|
for vertices, objects in zip(
|
|
156
294
|
self.masked_vertices, self.masked_objects, strict=False
|
|
157
295
|
):
|
|
158
|
-
yield
|
|
296
|
+
yield cls(vertices=vertices, objects=objects, mask=None)
|
|
159
297
|
|
|
160
298
|
@eqx.filter_jit
|
|
161
299
|
@jaxtyped(typechecker=typechecker)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Mesh geometry made of triangles and utilities."""
|
|
2
2
|
# ruff: noqa: ERA001
|
|
3
3
|
|
|
4
|
+
import sys
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
6
7
|
import equinox as eqx
|
|
@@ -15,6 +16,11 @@ from differt.plotting import draw_mesh
|
|
|
15
16
|
|
|
16
17
|
from .utils import normalize, orthogonal_basis, rotation_matrix_along_axis
|
|
17
18
|
|
|
19
|
+
if sys.version_info >= (3, 11):
|
|
20
|
+
from typing import Self
|
|
21
|
+
else:
|
|
22
|
+
from typing_extensions import Self
|
|
23
|
+
|
|
18
24
|
|
|
19
25
|
@jax.jit
|
|
20
26
|
@jaxtyped(typechecker=typechecker)
|
|
@@ -116,8 +122,10 @@ class TriangleMesh(eqx.Module):
|
|
|
116
122
|
multiple meshes together, this array contain start end end indices for each sub mesh.
|
|
117
123
|
"""
|
|
118
124
|
|
|
119
|
-
@jaxtyped(
|
|
120
|
-
|
|
125
|
+
@jaxtyped(
|
|
126
|
+
typechecker=None
|
|
127
|
+
) # typing.Self is (currently) not compatible with jaxtyping and beartype
|
|
128
|
+
def __getitem__(self, key: slice | Int[ArrayLike, "*batch"]) -> Self:
|
|
121
129
|
"""Return a copy of this mesh, taking only specific triangles.
|
|
122
130
|
|
|
123
131
|
Warning:
|
|
@@ -131,17 +139,23 @@ class TriangleMesh(eqx.Module):
|
|
|
131
139
|
Returns:
|
|
132
140
|
A new mesh.
|
|
133
141
|
"""
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
return eqx.tree_at(
|
|
143
|
+
lambda m: (
|
|
144
|
+
m.vertices,
|
|
145
|
+
m.triangles,
|
|
146
|
+
m.face_colors,
|
|
147
|
+
m.face_materials,
|
|
148
|
+
m.object_bounds,
|
|
149
|
+
),
|
|
150
|
+
self,
|
|
151
|
+
(
|
|
152
|
+
self.vertices,
|
|
153
|
+
self.triangles[key, :],
|
|
154
|
+
self.face_colors[key, :] if self.face_colors is not None else None,
|
|
155
|
+
self.face_materials[key] if self.face_materials is not None else None,
|
|
156
|
+
None,
|
|
157
|
+
),
|
|
158
|
+
is_leaf=lambda x: x is None,
|
|
145
159
|
)
|
|
146
160
|
|
|
147
161
|
@property
|
|
@@ -162,7 +176,7 @@ class TriangleMesh(eqx.Module):
|
|
|
162
176
|
@classmethod
|
|
163
177
|
def from_core(
|
|
164
178
|
cls, core_mesh: differt_core.geometry.triangle_mesh.TriangleMesh
|
|
165
|
-
) ->
|
|
179
|
+
) -> Self:
|
|
166
180
|
"""
|
|
167
181
|
Return a triangle mesh from a mesh created by the :mod:`differt_core` module.
|
|
168
182
|
|
|
@@ -205,12 +219,15 @@ class TriangleMesh(eqx.Module):
|
|
|
205
219
|
@jaxtyped(typechecker=typechecker)
|
|
206
220
|
def bounding_box(self) -> Float[Array, "2 3"]:
|
|
207
221
|
"""The bounding box (min. and max. coordinates)."""
|
|
222
|
+
# Using self.triangle_vertices is important because, e.g., as a result of using
|
|
223
|
+
# __getitem__, some vertices in 'self.vertices' may no longer be used by this mesh.
|
|
224
|
+
vertices = self.triangle_vertices.reshape(-1, 3)
|
|
208
225
|
return jnp.vstack(
|
|
209
|
-
(jnp.min(
|
|
226
|
+
(jnp.min(vertices, axis=0), jnp.max(vertices, axis=0)),
|
|
210
227
|
)
|
|
211
228
|
|
|
212
229
|
@classmethod
|
|
213
|
-
def empty(cls) ->
|
|
230
|
+
def empty(cls) -> Self:
|
|
214
231
|
"""
|
|
215
232
|
Create a empty mesh.
|
|
216
233
|
|
|
@@ -220,11 +237,13 @@ class TriangleMesh(eqx.Module):
|
|
|
220
237
|
return cls(vertices=jnp.empty((0, 3)), triangles=jnp.empty((0, 3), dtype=int))
|
|
221
238
|
|
|
222
239
|
@jax.jit
|
|
223
|
-
@jaxtyped(
|
|
240
|
+
@jaxtyped(
|
|
241
|
+
typechecker=None
|
|
242
|
+
) # typing.Self is (currently) not compatible with jaxtyping and beartype
|
|
224
243
|
def set_face_colors(
|
|
225
244
|
self,
|
|
226
245
|
colors: Float[Array, "#{self.num_triangles} 3"] | Float[Array, "3"],
|
|
227
|
-
) ->
|
|
246
|
+
) -> Self:
|
|
228
247
|
"""
|
|
229
248
|
Return a copy of this mesh, with new face colors.
|
|
230
249
|
|
|
@@ -244,7 +263,9 @@ class TriangleMesh(eqx.Module):
|
|
|
244
263
|
)
|
|
245
264
|
|
|
246
265
|
@classmethod
|
|
247
|
-
@jaxtyped(
|
|
266
|
+
@jaxtyped(
|
|
267
|
+
typechecker=None
|
|
268
|
+
) # typing.Self is (currently) not compatible with jaxtyping and beartype
|
|
248
269
|
def plane(
|
|
249
270
|
cls,
|
|
250
271
|
vertex: Float[Array, "3"],
|
|
@@ -252,7 +273,7 @@ class TriangleMesh(eqx.Module):
|
|
|
252
273
|
normal: Float[Array, "3"] | None = None,
|
|
253
274
|
side_length: Float[ArrayLike, " "] = 1.0,
|
|
254
275
|
rotate: Float[ArrayLike, " "] | None = None,
|
|
255
|
-
) ->
|
|
276
|
+
) -> Self:
|
|
256
277
|
"""
|
|
257
278
|
Create an plane mesh, made of two triangles.
|
|
258
279
|
|
|
@@ -315,7 +336,7 @@ class TriangleMesh(eqx.Module):
|
|
|
315
336
|
return self.triangles.size == 0
|
|
316
337
|
|
|
317
338
|
@classmethod
|
|
318
|
-
def load_obj(cls, file: str) ->
|
|
339
|
+
def load_obj(cls, file: str) -> Self:
|
|
319
340
|
"""
|
|
320
341
|
Load a triangle mesh from a Wavefront .obj file.
|
|
321
342
|
|
|
@@ -332,7 +353,7 @@ class TriangleMesh(eqx.Module):
|
|
|
332
353
|
return cls.from_core(core_mesh)
|
|
333
354
|
|
|
334
355
|
@classmethod
|
|
335
|
-
def load_ply(cls, file: str) ->
|
|
356
|
+
def load_ply(cls, file: str) -> Self:
|
|
336
357
|
"""
|
|
337
358
|
Load a triangle mesh from a Stanford PLY .ply file.
|
|
338
359
|
|
|
@@ -369,14 +390,16 @@ class TriangleMesh(eqx.Module):
|
|
|
369
390
|
)
|
|
370
391
|
|
|
371
392
|
@eqx.filter_jit
|
|
372
|
-
@jaxtyped(
|
|
393
|
+
@jaxtyped(
|
|
394
|
+
typechecker=None
|
|
395
|
+
) # typing.Self is (currently) not compatible with jaxtyping and beartype
|
|
373
396
|
def sample(
|
|
374
397
|
self,
|
|
375
398
|
size: int,
|
|
376
399
|
replace: bool = False,
|
|
377
400
|
*,
|
|
378
401
|
key: PRNGKeyArray,
|
|
379
|
-
) ->
|
|
402
|
+
) -> Self:
|
|
380
403
|
"""
|
|
381
404
|
Generate a new mesh by randomly sampling triangles from this geometry.
|
|
382
405
|
|
|
@@ -4,7 +4,7 @@ import equinox as eqx
|
|
|
4
4
|
import jax
|
|
5
5
|
import jax.numpy as jnp
|
|
6
6
|
from beartype import beartype as typechecker
|
|
7
|
-
from jaxtyping import Array, ArrayLike, DTypeLike, Float, jaxtyped
|
|
7
|
+
from jaxtyping import Array, ArrayLike, DTypeLike, Float, Int, jaxtyped
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
@jax.jit
|
|
@@ -401,3 +401,48 @@ def assemble_paths(
|
|
|
401
401
|
),
|
|
402
402
|
axis=-2,
|
|
403
403
|
)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
@jax.jit
|
|
407
|
+
@jaxtyped(typechecker=typechecker)
|
|
408
|
+
def min_distance_between_clusters(
|
|
409
|
+
cluster_vertices: Float[Array, "*batch 3"],
|
|
410
|
+
cluster_ids: Int[Array, "*batch"],
|
|
411
|
+
) -> Float[Array, "*batch"]:
|
|
412
|
+
"""
|
|
413
|
+
Compute the minimal (Euclidean) distance between vertices in different clusters.
|
|
414
|
+
|
|
415
|
+
For every vertex, the minimum distance to another vertex that is not is the same
|
|
416
|
+
cluster is computed.
|
|
417
|
+
|
|
418
|
+
Args:
|
|
419
|
+
cluster_vertices: The array of vertex coordinates.
|
|
420
|
+
cluster_ids: The array of corresponding cluster indices.
|
|
421
|
+
|
|
422
|
+
Returns:
|
|
423
|
+
The array of minimal distances.
|
|
424
|
+
"""
|
|
425
|
+
|
|
426
|
+
@jaxtyped(typechecker=typechecker)
|
|
427
|
+
def scan_fun(
|
|
428
|
+
_: None, vertex_and_cluster_id: tuple[Float[Array, "3"], Int[Array, " "]]
|
|
429
|
+
) -> tuple[None, Float[Array, " "]]:
|
|
430
|
+
vertex, cluster_id = vertex_and_cluster_id
|
|
431
|
+
min_dist = jnp.min(
|
|
432
|
+
jnp.linalg.norm(
|
|
433
|
+
cluster_vertices - vertex,
|
|
434
|
+
axis=-1,
|
|
435
|
+
),
|
|
436
|
+
initial=jnp.inf,
|
|
437
|
+
where=(cluster_id != cluster_ids),
|
|
438
|
+
)
|
|
439
|
+
return None, min_dist
|
|
440
|
+
|
|
441
|
+
return jax.lax.scan(
|
|
442
|
+
scan_fun,
|
|
443
|
+
init=None,
|
|
444
|
+
xs=(
|
|
445
|
+
cluster_vertices.reshape(-1, 3),
|
|
446
|
+
cluster_ids.reshape(-1),
|
|
447
|
+
),
|
|
448
|
+
)[1].reshape(cluster_ids.shape)
|
|
@@ -89,6 +89,7 @@ the Matplotlib backend.
|
|
|
89
89
|
|
|
90
90
|
__all__ = (
|
|
91
91
|
"dispatch",
|
|
92
|
+
"draw_contour",
|
|
92
93
|
"draw_image",
|
|
93
94
|
"draw_markers",
|
|
94
95
|
"draw_mesh",
|
|
@@ -104,7 +105,14 @@ __all__ = (
|
|
|
104
105
|
"view_from_canvas",
|
|
105
106
|
)
|
|
106
107
|
|
|
107
|
-
from ._core import
|
|
108
|
+
from ._core import (
|
|
109
|
+
draw_contour,
|
|
110
|
+
draw_image,
|
|
111
|
+
draw_markers,
|
|
112
|
+
draw_mesh,
|
|
113
|
+
draw_paths,
|
|
114
|
+
draw_rays,
|
|
115
|
+
)
|
|
108
116
|
from ._utils import (
|
|
109
117
|
dispatch,
|
|
110
118
|
get_backend,
|