differt 0.1.1__tar.gz → 0.2.0__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.1.1 → differt-0.2.0}/PKG-INFO +4 -4
- {differt-0.1.1 → differt-0.2.0}/README.md +1 -1
- {differt-0.1.1 → differt-0.2.0}/pyproject.toml +2 -2
- differt-0.2.0/src/differt/__init__.py +8 -0
- differt-0.2.0/src/differt/_version.py +6 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/geometry/_triangle_mesh.py +154 -19
- {differt-0.1.1 → differt-0.2.0}/src/differt/geometry/_utils.py +61 -14
- {differt-0.1.1 → differt-0.2.0}/src/differt/rt/_fermat.py +107 -47
- {differt-0.1.1 → differt-0.2.0}/src/differt/rt/_image_method.py +17 -4
- {differt-0.1.1 → differt-0.2.0}/src/differt/rt/_utils.py +54 -8
- {differt-0.1.1 → differt-0.2.0}/src/differt/scene/_triangle_scene.py +39 -18
- {differt-0.1.1 → differt-0.2.0}/src/differt/utils.py +20 -75
- differt-0.1.1/src/differt/__init__.py +0 -6
- differt-0.1.1/src/differt/_version.py +0 -6
- {differt-0.1.1 → differt-0.2.0}/.gitignore +0 -0
- {differt-0.1.1 → differt-0.2.0}/LICENSE.md +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/em/__init__.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/em/_antenna.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/em/_constants.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/em/_fresnel.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/em/_interaction_type.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/em/_material.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/em/_utd.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/em/_utils.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/geometry/__init__.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/geometry/_paths.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/plotting/__init__.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/plotting/_core.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/plotting/_utils.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/plugins/__init__.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/plugins/_deepmimo_types.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/plugins/deepmimo.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/py.typed +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/rt/__init__.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/scene/__init__.py +0 -0
- {differt-0.1.1 → differt-0.2.0}/src/differt/scene/_sionna.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
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,10 +21,10 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
21
21
|
Classifier: Topic :: Scientific/Engineering
|
|
22
22
|
Requires-Python: >=3.10
|
|
23
23
|
Requires-Dist: chex>=0.1.86
|
|
24
|
-
Requires-Dist: differt-core==0.
|
|
24
|
+
Requires-Dist: differt-core==0.2.0
|
|
25
25
|
Requires-Dist: equinox>=0.12.2
|
|
26
26
|
Requires-Dist: filelock>=3.15.4
|
|
27
|
-
Requires-Dist: jax
|
|
27
|
+
Requires-Dist: jax>=0.4.32
|
|
28
28
|
Requires-Dist: jaxtyping>=0.3.2
|
|
29
29
|
Requires-Dist: numpy>=1.26.1
|
|
30
30
|
Requires-Dist: optax>=0.1.7
|
|
@@ -140,7 +140,7 @@ If you use this software, please cite it as:
|
|
|
140
140
|
author = {Eertmans, Jérome},
|
|
141
141
|
url = {https://github.com/jeertmans/DiffeRT},
|
|
142
142
|
license = {MIT},
|
|
143
|
-
version = {v0.
|
|
143
|
+
version = {v0.2.0}
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
146
|
|
|
@@ -16,10 +16,10 @@ classifiers = [
|
|
|
16
16
|
]
|
|
17
17
|
dependencies = [
|
|
18
18
|
"chex>=0.1.86",
|
|
19
|
-
"differt-core==0.
|
|
19
|
+
"differt-core==0.2.0",
|
|
20
20
|
"equinox>=0.12.2",
|
|
21
21
|
"filelock>=3.15.4",
|
|
22
|
-
"jax>=0.4.32
|
|
22
|
+
"jax>=0.4.32", # TODO: fixme, issue with pmap
|
|
23
23
|
"jaxtyping>=0.3.2",
|
|
24
24
|
"numpy>=1.26.1",
|
|
25
25
|
"optax>=0.1.7",
|
|
@@ -235,6 +235,20 @@ class TriangleMesh(eqx.Module):
|
|
|
235
235
|
:attr:`num_triangles` is even, but each two consecutive
|
|
236
236
|
triangles are assumed to represent a quadrilateral surface.
|
|
237
237
|
"""
|
|
238
|
+
mask: Bool[Array, " num_triangles"] | None = eqx.field(
|
|
239
|
+
converter=lambda x: jnp.asarray(x) if x is not None else None, default=None
|
|
240
|
+
)
|
|
241
|
+
"""An optional mask to indicate which triangles are active.
|
|
242
|
+
|
|
243
|
+
Using a mask allows to represent multiple sub-meshes of a single mesh, without changing
|
|
244
|
+
the memory allocated to each sub-mesh. Masks can be conveniently created using the
|
|
245
|
+
:meth:`sample` method by passing ``by_masking=True``.
|
|
246
|
+
|
|
247
|
+
.. important::
|
|
248
|
+
|
|
249
|
+
Unless specified, the transformation or selection operations, like :meth:`rotate`,
|
|
250
|
+
will not take the mask into account, and will apply to all triangles.
|
|
251
|
+
"""
|
|
238
252
|
|
|
239
253
|
def __check_init__(self) -> None: # noqa: PLW3201
|
|
240
254
|
if self.assume_quads and (self.triangles.shape[0] % 2) != 0:
|
|
@@ -265,6 +279,7 @@ class TriangleMesh(eqx.Module):
|
|
|
265
279
|
m.face_colors,
|
|
266
280
|
m.face_materials,
|
|
267
281
|
m.object_bounds,
|
|
282
|
+
m.mask,
|
|
268
283
|
),
|
|
269
284
|
self,
|
|
270
285
|
(
|
|
@@ -273,6 +288,7 @@ class TriangleMesh(eqx.Module):
|
|
|
273
288
|
self.face_colors[key, :] if self.face_colors is not None else None,
|
|
274
289
|
self.face_materials[key] if self.face_materials is not None else None,
|
|
275
290
|
None,
|
|
291
|
+
self.mask[key] if self.mask is not None else None,
|
|
276
292
|
),
|
|
277
293
|
is_leaf=lambda x: x is None,
|
|
278
294
|
)
|
|
@@ -297,6 +313,7 @@ class TriangleMesh(eqx.Module):
|
|
|
297
313
|
m.face_colors,
|
|
298
314
|
m.face_materials,
|
|
299
315
|
m.object_bounds,
|
|
316
|
+
m.mask,
|
|
300
317
|
),
|
|
301
318
|
self,
|
|
302
319
|
(
|
|
@@ -309,6 +326,7 @@ class TriangleMesh(eqx.Module):
|
|
|
309
326
|
if self.face_materials is not None
|
|
310
327
|
else None,
|
|
311
328
|
jnp.array([[0, stop - start]]),
|
|
329
|
+
self.mask[start:stop] if self.mask is not None else None,
|
|
312
330
|
),
|
|
313
331
|
is_leaf=lambda x: x is None,
|
|
314
332
|
)
|
|
@@ -441,12 +459,22 @@ class TriangleMesh(eqx.Module):
|
|
|
441
459
|
|
|
442
460
|
@property
|
|
443
461
|
def bounding_box(self) -> Float[Array, "2 3"]:
|
|
444
|
-
"""The bounding box (min. and max. coordinates).
|
|
462
|
+
"""The bounding box (min. and max. coordinates).
|
|
463
|
+
|
|
464
|
+
.. important::
|
|
465
|
+
|
|
466
|
+
Setting :attr:`mask` will have an effect on the bounding box,
|
|
467
|
+
as the bounding box is computed only for the active triangles.
|
|
468
|
+
"""
|
|
445
469
|
# Using self.triangle_vertices is important because, e.g., as a result of using
|
|
446
470
|
# __getitem__, some vertices in 'self.vertices' may no longer be used by this mesh.
|
|
447
471
|
vertices = self.triangle_vertices.reshape(-1, 3)
|
|
472
|
+
where = jnp.repeat(self.mask, 3)[:, None] if self.mask is not None else None
|
|
448
473
|
return jnp.vstack(
|
|
449
|
-
(
|
|
474
|
+
(
|
|
475
|
+
jnp.min(vertices, axis=0, initial=+jnp.inf, where=where),
|
|
476
|
+
jnp.max(vertices, axis=0, initial=-jnp.inf, where=where),
|
|
477
|
+
),
|
|
450
478
|
)
|
|
451
479
|
|
|
452
480
|
@property
|
|
@@ -539,6 +567,43 @@ class TriangleMesh(eqx.Module):
|
|
|
539
567
|
"""
|
|
540
568
|
return _TriangleMeshVerticesUpdateHelper(self)
|
|
541
569
|
|
|
570
|
+
def masked(self) -> Self:
|
|
571
|
+
"""Return a pruned copy of this object that only keeps masked (i.e., active) triangles.
|
|
572
|
+
|
|
573
|
+
.. important::
|
|
574
|
+
This method does not preserve the :attr:`object_bounds` attribute.
|
|
575
|
+
|
|
576
|
+
Returns:
|
|
577
|
+
A new paths instance with flattened batch dimensions and only valid paths.
|
|
578
|
+
"""
|
|
579
|
+
if self.mask is None:
|
|
580
|
+
return jax.tree.map(lambda m: m, self)
|
|
581
|
+
|
|
582
|
+
return eqx.tree_at(
|
|
583
|
+
lambda m: (
|
|
584
|
+
m.vertices,
|
|
585
|
+
m.triangles,
|
|
586
|
+
m.face_colors,
|
|
587
|
+
m.face_materials,
|
|
588
|
+
m.object_bounds,
|
|
589
|
+
m.mask,
|
|
590
|
+
),
|
|
591
|
+
self,
|
|
592
|
+
(
|
|
593
|
+
self.vertices,
|
|
594
|
+
self.triangles[self.mask, :],
|
|
595
|
+
self.face_colors[self.mask, :]
|
|
596
|
+
if self.face_colors is not None
|
|
597
|
+
else None,
|
|
598
|
+
self.face_materials[self.mask]
|
|
599
|
+
if self.face_materials is not None
|
|
600
|
+
else None,
|
|
601
|
+
None,
|
|
602
|
+
None,
|
|
603
|
+
),
|
|
604
|
+
is_leaf=lambda x: x is None,
|
|
605
|
+
)
|
|
606
|
+
|
|
542
607
|
def rotate(self, rotation_matrix: Float[ArrayLike, "3 3"]) -> Self:
|
|
543
608
|
"""
|
|
544
609
|
Return a new mesh by applying a rotation matrix to all triangle coordinates.
|
|
@@ -597,7 +662,7 @@ class TriangleMesh(eqx.Module):
|
|
|
597
662
|
"""
|
|
598
663
|
return cls(vertices=jnp.empty((0, 3)), triangles=jnp.empty((0, 3), dtype=int))
|
|
599
664
|
|
|
600
|
-
def append(self, other: "TriangleMesh") -> Self:
|
|
665
|
+
def append(self, other: "TriangleMesh") -> Self: # noqa: C901, PLR0912
|
|
601
666
|
"""
|
|
602
667
|
Return a new mesh by appending another mesh to this one.
|
|
603
668
|
|
|
@@ -620,6 +685,8 @@ class TriangleMesh(eqx.Module):
|
|
|
620
685
|
* The material names are merged, keeping only unique names;
|
|
621
686
|
* The object bounds are concatenated only if both meshes have them set,
|
|
622
687
|
otherwise, the object bounds are set to :data:`None`;
|
|
688
|
+
* The masks are concatenated if present in both meshes. If one mesh has a mask while the other does not,
|
|
689
|
+
then the mesh with no mask will have its mask set to all triangles being active (i.e., :data:`True`).
|
|
623
690
|
* The :attr:`assume_quads` flag is set to :data:`True` if both meshes have it set to :data:`True`.
|
|
624
691
|
|
|
625
692
|
Two important exceptions are:
|
|
@@ -734,6 +801,25 @@ class TriangleMesh(eqx.Module):
|
|
|
734
801
|
if (self.object_bounds is not None and other.object_bounds is not None)
|
|
735
802
|
else None
|
|
736
803
|
)
|
|
804
|
+
|
|
805
|
+
if self.mask is not None and other.mask is not None:
|
|
806
|
+
mask = jnp.concatenate((self.mask, other.mask), axis=0)
|
|
807
|
+
elif self.mask is not None:
|
|
808
|
+
mask = jnp.concatenate(
|
|
809
|
+
(self.mask, jnp.ones_like(self.mask, shape=(other.num_triangles,))),
|
|
810
|
+
axis=0,
|
|
811
|
+
)
|
|
812
|
+
elif other.mask is not None:
|
|
813
|
+
mask = jnp.concatenate(
|
|
814
|
+
(
|
|
815
|
+
jnp.ones_like(other.mask, shape=(self.num_triangles,)),
|
|
816
|
+
other.mask,
|
|
817
|
+
),
|
|
818
|
+
axis=0,
|
|
819
|
+
)
|
|
820
|
+
else:
|
|
821
|
+
mask = None
|
|
822
|
+
|
|
737
823
|
assume_quads = self.assume_quads and other.assume_quads
|
|
738
824
|
mesh = replace(self, material_names=material_names, assume_quads=assume_quads)
|
|
739
825
|
return eqx.tree_at(
|
|
@@ -743,9 +829,10 @@ class TriangleMesh(eqx.Module):
|
|
|
743
829
|
m.face_colors,
|
|
744
830
|
m.face_materials,
|
|
745
831
|
m.object_bounds,
|
|
832
|
+
m.mask,
|
|
746
833
|
),
|
|
747
834
|
mesh,
|
|
748
|
-
(vertices, triangles, face_colors, face_materials, object_bounds),
|
|
835
|
+
(vertices, triangles, face_colors, face_materials, object_bounds, mask),
|
|
749
836
|
is_leaf=lambda x: x is None,
|
|
750
837
|
)
|
|
751
838
|
|
|
@@ -761,6 +848,7 @@ class TriangleMesh(eqx.Module):
|
|
|
761
848
|
Returns:
|
|
762
849
|
A new mesh with duplicate vertices removed.
|
|
763
850
|
"""
|
|
851
|
+
# TODO: handle mask
|
|
764
852
|
vertices, unique_inverse = jnp.unique(
|
|
765
853
|
self.vertices, axis=0, return_inverse=True
|
|
766
854
|
)
|
|
@@ -817,6 +905,7 @@ class TriangleMesh(eqx.Module):
|
|
|
817
905
|
>>> fig = sorted_mesh.plot(opacity=0.5, backend="plotly")
|
|
818
906
|
>>> fig # doctest: +SKIP
|
|
819
907
|
"""
|
|
908
|
+
# TODO: handle mask
|
|
820
909
|
indices = jnp.lexsort(self.vertices.T[::-1])
|
|
821
910
|
vertices = self.vertices[indices]
|
|
822
911
|
triangles = jnp.argsort(indices)[self.triangles]
|
|
@@ -1383,8 +1472,9 @@ class TriangleMesh(eqx.Module):
|
|
|
1383
1472
|
... )
|
|
1384
1473
|
>>> fig # doctest: +SKIP
|
|
1385
1474
|
"""
|
|
1386
|
-
|
|
1387
|
-
|
|
1475
|
+
mesh = self.masked()
|
|
1476
|
+
if "face_colors" not in kwargs and mesh.face_colors is not None:
|
|
1477
|
+
kwargs["face_colors"] = mesh.face_colors
|
|
1388
1478
|
|
|
1389
1479
|
normals_kwargs = {} if normals_kwargs is None else normals_kwargs
|
|
1390
1480
|
triangle_edges_kwargs = (
|
|
@@ -1396,26 +1486,26 @@ class TriangleMesh(eqx.Module):
|
|
|
1396
1486
|
|
|
1397
1487
|
with reuse(pass_all_kwargs=False, **kwargs) as result:
|
|
1398
1488
|
draw_mesh(
|
|
1399
|
-
vertices=
|
|
1400
|
-
triangles=
|
|
1489
|
+
vertices=mesh.vertices,
|
|
1490
|
+
triangles=mesh.triangles,
|
|
1401
1491
|
**kwargs,
|
|
1402
1492
|
)
|
|
1403
1493
|
|
|
1404
1494
|
if show_normals:
|
|
1405
1495
|
draw_rays(
|
|
1406
|
-
|
|
1407
|
-
|
|
1496
|
+
mesh.triangle_vertices.mean(axis=-2),
|
|
1497
|
+
mesh.normals,
|
|
1408
1498
|
**normals_kwargs,
|
|
1409
1499
|
)
|
|
1410
1500
|
|
|
1411
1501
|
if show_triangle_edges:
|
|
1412
1502
|
draw_paths(
|
|
1413
|
-
|
|
1503
|
+
mesh.triangle_edges,
|
|
1414
1504
|
**triangle_edges_kwargs,
|
|
1415
1505
|
)
|
|
1416
1506
|
if show_diffraction_edges:
|
|
1417
1507
|
draw_paths(
|
|
1418
|
-
|
|
1508
|
+
mesh.diffraction_edges,
|
|
1419
1509
|
**diffraction_edges_kwargs,
|
|
1420
1510
|
)
|
|
1421
1511
|
|
|
@@ -1423,10 +1513,11 @@ class TriangleMesh(eqx.Module):
|
|
|
1423
1513
|
|
|
1424
1514
|
def sample(
|
|
1425
1515
|
self,
|
|
1426
|
-
size: int,
|
|
1516
|
+
size: int | Float[ArrayLike, " "],
|
|
1427
1517
|
replace: bool = False,
|
|
1428
1518
|
preserve: bool = False,
|
|
1429
1519
|
*,
|
|
1520
|
+
by_masking: bool = False,
|
|
1430
1521
|
key: PRNGKeyArray,
|
|
1431
1522
|
) -> Self:
|
|
1432
1523
|
"""
|
|
@@ -1438,7 +1529,13 @@ class TriangleMesh(eqx.Module):
|
|
|
1438
1529
|
|
|
1439
1530
|
Args:
|
|
1440
1531
|
size: The size of the sample, i.e., the number of triangles.
|
|
1532
|
+
|
|
1533
|
+
If a floating point number is provided, it is interpreted as a fill factor,
|
|
1534
|
+
i.e., the fraction of triangles to sample from the mesh. This is only supported
|
|
1535
|
+
if ``by_masking`` is set to :data:`True`.
|
|
1441
1536
|
replace: Whether to sample with or without replacement.
|
|
1537
|
+
|
|
1538
|
+
Cannot be used with ``by_masking`` set to :data:`True`.
|
|
1442
1539
|
preserve: Whether to preserve :attr:`object_bounds`, otherwise
|
|
1443
1540
|
it is discarded.
|
|
1444
1541
|
|
|
@@ -1447,17 +1544,53 @@ class TriangleMesh(eqx.Module):
|
|
|
1447
1544
|
|
|
1448
1545
|
Setting this to :data:`True` has no effect if :attr:`object_bounds`
|
|
1449
1546
|
is :data:`None`.
|
|
1547
|
+
|
|
1548
|
+
Cannot be used with ``by_masking`` set to :data:`True`.
|
|
1549
|
+
by_masking: Whether to sample by masking the triangles.
|
|
1550
|
+
If :data:`True`, then the :attr:`mask` attribute set (ignoring any existing mask).
|
|
1450
1551
|
key: The :func:`jax.random.key` to be used.
|
|
1451
1552
|
|
|
1452
1553
|
Returns:
|
|
1453
1554
|
A new random mesh.
|
|
1555
|
+
|
|
1556
|
+
Raises:
|
|
1557
|
+
TypeError: If ``by_masking`` is :data:`False` and ``size`` is not an integer.
|
|
1558
|
+
ValueError: If ``by_masking`` is :data:`True` and ``replace`` or ``preserve`` are set to :data:`True`.
|
|
1454
1559
|
"""
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1560
|
+
if by_masking:
|
|
1561
|
+
if replace:
|
|
1562
|
+
msg = "Cannot sample with replacement when 'by_masking' is True."
|
|
1563
|
+
raise ValueError(msg)
|
|
1564
|
+
if preserve:
|
|
1565
|
+
msg = "Cannot preserve 'object_bounds' when 'by_masking' is True."
|
|
1566
|
+
raise ValueError(msg)
|
|
1567
|
+
if isinstance(size, int):
|
|
1568
|
+
mask = jnp.zeros(self.num_objects, dtype=bool)
|
|
1569
|
+
mask = mask.at[:size].set(True)
|
|
1570
|
+
mask = jax.random.permutation(key, mask)
|
|
1571
|
+
else:
|
|
1572
|
+
mask = jax.random.uniform(key, (self.num_objects,)) <= size
|
|
1573
|
+
|
|
1574
|
+
if self.assume_quads:
|
|
1575
|
+
mask = jnp.repeat(mask, 2)
|
|
1576
|
+
|
|
1577
|
+
return eqx.tree_at(
|
|
1578
|
+
lambda m: (m.object_bounds, m.mask),
|
|
1579
|
+
self,
|
|
1580
|
+
(None, mask),
|
|
1581
|
+
is_leaf=lambda x: x is None,
|
|
1582
|
+
)
|
|
1583
|
+
|
|
1584
|
+
if isinstance(size, int):
|
|
1585
|
+
indices = jax.random.choice(
|
|
1586
|
+
key,
|
|
1587
|
+
self.num_objects,
|
|
1588
|
+
shape=(size,),
|
|
1589
|
+
replace=replace,
|
|
1590
|
+
)
|
|
1591
|
+
else:
|
|
1592
|
+
msg = "'size' must be an integer when 'by_masking' is False."
|
|
1593
|
+
raise TypeError(msg)
|
|
1461
1594
|
|
|
1462
1595
|
if self.assume_quads:
|
|
1463
1596
|
indices *= 2
|
|
@@ -1484,6 +1617,7 @@ class TriangleMesh(eqx.Module):
|
|
|
1484
1617
|
m.face_colors,
|
|
1485
1618
|
m.face_materials,
|
|
1486
1619
|
m.object_bounds,
|
|
1620
|
+
m.mask,
|
|
1487
1621
|
),
|
|
1488
1622
|
self,
|
|
1489
1623
|
(
|
|
@@ -1494,6 +1628,7 @@ class TriangleMesh(eqx.Module):
|
|
|
1494
1628
|
if self.face_materials is not None
|
|
1495
1629
|
else None,
|
|
1496
1630
|
object_bounds,
|
|
1631
|
+
self.mask[indices] if self.mask is not None else None,
|
|
1497
1632
|
),
|
|
1498
1633
|
is_leaf=lambda x: x is None,
|
|
1499
1634
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from functools import partial
|
|
2
|
-
from typing import Literal, overload
|
|
2
|
+
from typing import Literal, no_type_check, overload
|
|
3
3
|
|
|
4
4
|
import jax
|
|
5
5
|
import jax.numpy as jnp
|
|
@@ -468,30 +468,77 @@ def fibonacci_lattice(
|
|
|
468
468
|
return spherical_to_cartesian(pa).astype(dtype)
|
|
469
469
|
|
|
470
470
|
|
|
471
|
+
@overload
|
|
472
|
+
def assemble_paths(
|
|
473
|
+
from_vertices: Float[ArrayLike, "*#batch 3"],
|
|
474
|
+
intermediate_vertices: Float[ArrayLike, "*#batch num_inter_vertices 3"],
|
|
475
|
+
to_vertices: Float[ArrayLike, "*#batch 3"],
|
|
476
|
+
) -> Float[Array, "*batch num_inter_vertices+2 3"]: ...
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
@overload
|
|
480
|
+
def assemble_paths(
|
|
481
|
+
from_vertices: Float[ArrayLike, "*#batch 3"],
|
|
482
|
+
intermediate_vertices: Float[ArrayLike, "*#batch 3"],
|
|
483
|
+
to_vertices: None = None,
|
|
484
|
+
) -> Float[Array, "*batch 2 3"]: ...
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
# NOTE: Jaxtyping does not match the correct shape for `intermediate_vertices` and will match
|
|
488
|
+
# `Float[ArrayLike, "*#batch 3"]` instead of `Float[ArrayLike, "*#batch num_inter_vertices 3"]`.
|
|
489
|
+
# This is why we use `no_type_check` here.
|
|
490
|
+
# TODO: fix this.
|
|
491
|
+
@no_type_check
|
|
471
492
|
def assemble_paths(
|
|
472
|
-
|
|
473
|
-
|
|
493
|
+
from_vertices: Float[ArrayLike, "*#batch 3"],
|
|
494
|
+
intermediate_vertices: Float[ArrayLike, "*#batch num_inter_vertices 3"]
|
|
495
|
+
| Float[ArrayLike, "*#batch 3"],
|
|
496
|
+
to_vertices: Float[ArrayLike, "*#batch 3"] | None = None,
|
|
497
|
+
) -> Float[Array, "*batch num_inter_vertices+2 3"] | Float[Array, "*batch 2 3"]:
|
|
474
498
|
"""
|
|
475
|
-
Assemble paths by concatenating
|
|
499
|
+
Assemble paths vertices by concatenating start-, intermediate, and end-vertices.
|
|
476
500
|
|
|
477
501
|
Arrays broadcasting is automatically performed, and the total
|
|
478
|
-
|
|
502
|
+
number of vertices per path is simply ``num_inter_vertices+2``.
|
|
479
503
|
|
|
480
504
|
Args:
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
505
|
+
from_vertices: The starting vertices of the paths.
|
|
506
|
+
intermediate_vertices: The intermediate vertices of the paths.
|
|
507
|
+
If ``to_vertices`` is not provided, then this argument is interpreted
|
|
508
|
+
as the end vertices of the paths.
|
|
509
|
+
to_vertices: The ending vertices of the paths.
|
|
485
510
|
|
|
486
511
|
Returns:
|
|
487
|
-
The assembled
|
|
512
|
+
The assembled path vertices.
|
|
488
513
|
"""
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
514
|
+
from_vertices = jnp.asarray(from_vertices)
|
|
515
|
+
intermediate_vertices = jnp.asarray(intermediate_vertices)
|
|
516
|
+
if to_vertices is None:
|
|
517
|
+
batch = jnp.broadcast_shapes(
|
|
518
|
+
from_vertices.shape[:-1], intermediate_vertices.shape[:-1]
|
|
519
|
+
)
|
|
520
|
+
return jnp.concatenate(
|
|
521
|
+
(
|
|
522
|
+
jnp.broadcast_to(from_vertices[..., None, :], (*batch, 1, 3)),
|
|
523
|
+
jnp.broadcast_to(intermediate_vertices[..., None, :], (*batch, 1, 3)),
|
|
524
|
+
),
|
|
525
|
+
axis=-2,
|
|
526
|
+
)
|
|
527
|
+
to_vertices = jnp.asarray(to_vertices)
|
|
528
|
+
batch = jnp.broadcast_shapes(
|
|
529
|
+
from_vertices.shape[:-1],
|
|
530
|
+
intermediate_vertices.shape[:-2],
|
|
531
|
+
to_vertices.shape[:-1],
|
|
532
|
+
)
|
|
492
533
|
|
|
493
534
|
return jnp.concatenate(
|
|
494
|
-
|
|
535
|
+
(
|
|
536
|
+
jnp.broadcast_to(from_vertices[..., None, :], (*batch, 1, 3)),
|
|
537
|
+
jnp.broadcast_to(
|
|
538
|
+
intermediate_vertices, (*batch, *intermediate_vertices.shape[-2:])
|
|
539
|
+
),
|
|
540
|
+
jnp.broadcast_to(to_vertices[..., None, :], (*batch, 1, 3)),
|
|
541
|
+
),
|
|
495
542
|
axis=-2,
|
|
496
543
|
)
|
|
497
544
|
|