differt 0.3.0__tar.gz → 0.4.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.
Files changed (34) hide show
  1. {differt-0.3.0 → differt-0.4.0}/PKG-INFO +3 -3
  2. {differt-0.3.0 → differt-0.4.0}/README.md +1 -1
  3. {differt-0.3.0 → differt-0.4.0}/pyproject.toml +1 -1
  4. {differt-0.3.0 → differt-0.4.0}/src/differt/geometry/_triangle_mesh.py +61 -24
  5. {differt-0.3.0 → differt-0.4.0}/src/differt/plugins/deepmimo.py +1 -1
  6. {differt-0.3.0 → differt-0.4.0}/src/differt/scene/_triangle_scene.py +112 -35
  7. {differt-0.3.0 → differt-0.4.0}/.gitignore +0 -0
  8. {differt-0.3.0 → differt-0.4.0}/LICENSE.md +0 -0
  9. {differt-0.3.0 → differt-0.4.0}/src/differt/__init__.py +0 -0
  10. {differt-0.3.0 → differt-0.4.0}/src/differt/_version.py +0 -0
  11. {differt-0.3.0 → differt-0.4.0}/src/differt/em/__init__.py +0 -0
  12. {differt-0.3.0 → differt-0.4.0}/src/differt/em/_antenna.py +0 -0
  13. {differt-0.3.0 → differt-0.4.0}/src/differt/em/_constants.py +0 -0
  14. {differt-0.3.0 → differt-0.4.0}/src/differt/em/_fresnel.py +0 -0
  15. {differt-0.3.0 → differt-0.4.0}/src/differt/em/_interaction_type.py +0 -0
  16. {differt-0.3.0 → differt-0.4.0}/src/differt/em/_material.py +0 -0
  17. {differt-0.3.0 → differt-0.4.0}/src/differt/em/_utd.py +0 -0
  18. {differt-0.3.0 → differt-0.4.0}/src/differt/em/_utils.py +0 -0
  19. {differt-0.3.0 → differt-0.4.0}/src/differt/geometry/__init__.py +0 -0
  20. {differt-0.3.0 → differt-0.4.0}/src/differt/geometry/_paths.py +0 -0
  21. {differt-0.3.0 → differt-0.4.0}/src/differt/geometry/_utils.py +0 -0
  22. {differt-0.3.0 → differt-0.4.0}/src/differt/plotting/__init__.py +0 -0
  23. {differt-0.3.0 → differt-0.4.0}/src/differt/plotting/_core.py +0 -0
  24. {differt-0.3.0 → differt-0.4.0}/src/differt/plotting/_utils.py +0 -0
  25. {differt-0.3.0 → differt-0.4.0}/src/differt/plugins/__init__.py +0 -0
  26. {differt-0.3.0 → differt-0.4.0}/src/differt/plugins/_deepmimo_types.py +0 -0
  27. {differt-0.3.0 → differt-0.4.0}/src/differt/py.typed +0 -0
  28. {differt-0.3.0 → differt-0.4.0}/src/differt/rt/__init__.py +0 -0
  29. {differt-0.3.0 → differt-0.4.0}/src/differt/rt/_fermat.py +0 -0
  30. {differt-0.3.0 → differt-0.4.0}/src/differt/rt/_image_method.py +0 -0
  31. {differt-0.3.0 → differt-0.4.0}/src/differt/rt/_utils.py +0 -0
  32. {differt-0.3.0 → differt-0.4.0}/src/differt/scene/__init__.py +0 -0
  33. {differt-0.3.0 → differt-0.4.0}/src/differt/scene/_sionna.py +0 -0
  34. {differt-0.3.0 → differt-0.4.0}/src/differt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DiffeRT
3
- Version: 0.3.0
3
+ Version: 0.4.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,7 +21,7 @@ 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.3.0
24
+ Requires-Dist: differt-core==0.4.0
25
25
  Requires-Dist: equinox>=0.12.2
26
26
  Requires-Dist: filelock>=3.15.4
27
27
  Requires-Dist: jax>=0.4.32
@@ -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.3.0}
143
+ version = {v0.4.0}
144
144
  }
145
145
  ```
146
146
 
@@ -83,7 +83,7 @@ If you use this software, please cite it as:
83
83
  author = {Eertmans, Jérome},
84
84
  url = {https://github.com/jeertmans/DiffeRT},
85
85
  license = {MIT},
86
- version = {v0.3.0}
86
+ version = {v0.4.0}
87
87
  }
88
88
  ```
89
89
 
@@ -16,7 +16,7 @@ classifiers = [
16
16
  ]
17
17
  dependencies = [
18
18
  "chex>=0.1.86",
19
- "differt-core==0.3.0",
19
+ "differt-core==0.4.0",
20
20
  "equinox>=0.12.2",
21
21
  "filelock>=3.15.4",
22
22
  "jax>=0.4.32", # TODO: fixme, issue with pmap
@@ -213,7 +213,7 @@ class TriangleMesh(eqx.Module):
213
213
  converter=tuple, default_factory=tuple, static=True
214
214
  )
215
215
  """The list of material names (must be unique)."""
216
- object_bounds: Int[Array, "num_objects 2"] | None = eqx.field(
216
+ object_bounds: Int[Array, "num_primitives 2"] | None = eqx.field(
217
217
  converter=lambda x: jnp.asarray(x) if x is not None else None, default=None
218
218
  )
219
219
  """The array of object indices.
@@ -350,10 +350,10 @@ class TriangleMesh(eqx.Module):
350
350
  return self.triangles.shape[0] // 2
351
351
 
352
352
  @property
353
- def num_objects(self) -> int:
354
- """The number of objects.
353
+ def num_primitives(self) -> int:
354
+ """The number of primitives.
355
355
 
356
- This is a convenient alias to :attr:`num_quads` :attr:`assume_quads` is :data:`True`
356
+ This is a convenient alias to :attr:`num_quads` if :attr:`assume_quads` is :data:`True`
357
357
  else :attr:`num_triangles`.
358
358
  """
359
359
  return self.num_quads if self.assume_quads else self.num_triangles
@@ -662,7 +662,7 @@ class TriangleMesh(eqx.Module):
662
662
  """
663
663
  return cls(vertices=jnp.empty((0, 3)), triangles=jnp.empty((0, 3), dtype=int))
664
664
 
665
- def append(self, other: "TriangleMesh") -> Self: # noqa: C901, PLR0912
665
+ def append(self, other: "TriangleMesh") -> Self:
666
666
  """
667
667
  Return a new mesh by appending another mesh to this one.
668
668
 
@@ -1061,7 +1061,7 @@ class TriangleMesh(eqx.Module):
1061
1061
  )
1062
1062
  elif self.assume_quads:
1063
1063
  quad_colors = jax.random.uniform(key, (self.num_quads, 3))
1064
- repeats = jnp.full(self.num_objects, 2)
1064
+ repeats = jnp.full(self.num_primitives, 2)
1065
1065
  colors = jnp.repeat(
1066
1066
  quad_colors, repeats, axis=0, total_repeat_length=self.num_triangles
1067
1067
  )
@@ -1095,11 +1095,11 @@ class TriangleMesh(eqx.Module):
1095
1095
  A new mesh with updated face materials.
1096
1096
 
1097
1097
  Raises:
1098
- ValueError: If the number of names is not 1, :attr:`num_triangles`, or :attr:`num_objects` (if :attr:`assume_quads` is set to :data:`True`).
1098
+ ValueError: If the number of names is not 1, :attr:`num_triangles`, or :attr:`num_primitives` (if :attr:`assume_quads` is set to :data:`True`).
1099
1099
  """
1100
- if len(names) not in {1, self.num_triangles, self.num_objects}:
1100
+ if len(names) not in {1, self.num_triangles, self.num_primitives}:
1101
1101
  if self.assume_quads:
1102
- msg = f"Expected either 1, {self.num_triangles}, or {self.num_objects} names, got {len(names)}."
1102
+ msg = f"Expected either 1, {self.num_triangles}, or {self.num_primitives} names, got {len(names)}."
1103
1103
  else:
1104
1104
  msg = f"Expected either 1, or {self.num_triangles} names, got {len(names)}."
1105
1105
  raise ValueError(msg)
@@ -1518,20 +1518,23 @@ class TriangleMesh(eqx.Module):
1518
1518
  preserve: bool = False,
1519
1519
  *,
1520
1520
  by_masking: bool = False,
1521
+ sample_objects: bool = False,
1521
1522
  key: PRNGKeyArray,
1522
1523
  ) -> Self:
1523
1524
  """
1524
- Generate a new mesh by randomly sampling triangles from this geometry.
1525
+ Generate a new mesh by randomly sampling primitives from this geometry.
1525
1526
 
1526
- Warning:
1527
- If :attr:`assume_quads` is :data:`True`, then quadrilaterals are
1528
- sampled.
1527
+ Important:
1528
+ If ``by_masking`` is set to :data:`True`, then this function is compatible
1529
+ with :func:`jax.jit`. Conversely, if ``by_masking`` is set to :data:`False`,
1530
+ then this function is **not** compatible with :func:`jax.jit`,
1531
+ as the size of the output mesh is not known at compile time.
1529
1532
 
1530
1533
  Args:
1531
- size: The size of the sample, i.e., the number of triangles.
1534
+ size: The size of the sample, i.e., the number of primitives (or objects, if ``sample_objects`` is :data:`True`).
1532
1535
 
1533
1536
  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
1537
+ i.e., the fraction of primitives to sample from the mesh. This is only supported
1535
1538
  if ``by_masking`` is set to :data:`True`.
1536
1539
  replace: Whether to sample with or without replacement.
1537
1540
 
@@ -1546,8 +1549,11 @@ class TriangleMesh(eqx.Module):
1546
1549
  is :data:`None`.
1547
1550
 
1548
1551
  Cannot be used with ``by_masking`` set to :data:`True`.
1549
- by_masking: Whether to sample by masking the triangles.
1552
+ by_masking: Whether to sample by masking the primitives.
1550
1553
  If :data:`True`, then the :attr:`mask` attribute set (ignoring any existing mask).
1554
+ sample_objects: Whether to sample by objects, i.e., sampling whole objects at once.
1555
+ The value of ``size`` is interpreted as the number of objects to sample,
1556
+ or the fill factor of objects to sample.
1551
1557
  key: The :func:`jax.random.key` to be used.
1552
1558
 
1553
1559
  Returns:
@@ -1556,35 +1562,56 @@ class TriangleMesh(eqx.Module):
1556
1562
  Raises:
1557
1563
  TypeError: If ``by_masking`` is :data:`False` and ``size`` is not an integer.
1558
1564
  ValueError: If ``by_masking`` is :data:`True` and ``replace`` or ``preserve`` are set to :data:`True`.
1565
+ ValueError: If ``sample_objects`` is :data:`True` and :attr:`object_bounds` is :data:`None`.
1559
1566
  """
1567
+ if sample_objects:
1568
+ if self.object_bounds is None:
1569
+ msg = "Cannot sample by objects when 'object_bounds' is None."
1570
+ raise ValueError(msg)
1571
+ num = self.object_bounds.shape[0]
1572
+ else:
1573
+ num = self.num_primitives
1560
1574
  if by_masking:
1561
1575
  if replace:
1562
1576
  msg = "Cannot sample with replacement when 'by_masking' is True."
1563
1577
  raise ValueError(msg)
1564
- if preserve:
1565
- msg = "Cannot preserve 'object_bounds' when 'by_masking' is True."
1578
+ if preserve and not sample_objects:
1579
+ msg = "Cannot preserve 'object_bounds' when 'by_masking' is True and 'sample_objects' is False."
1566
1580
  raise ValueError(msg)
1567
1581
  if isinstance(size, int):
1568
- mask = jnp.zeros(self.num_objects, dtype=bool)
1582
+ mask = jnp.zeros(num, dtype=bool)
1569
1583
  mask = mask.at[:size].set(True)
1570
1584
  mask = jax.random.permutation(key, mask)
1571
1585
  else:
1572
- mask = jax.random.uniform(key, (self.num_objects,)) <= size
1573
-
1574
- if self.assume_quads:
1586
+ mask = jax.random.uniform(key, (num,)) <= size
1587
+
1588
+ if sample_objects:
1589
+ indices = jnp.arange(self.num_triangles)
1590
+ indices_inside_bounds = (
1591
+ self.object_bounds[:, 0] <= indices[:, None] # type: ignore[reportOptionalSubscript]
1592
+ ) & (indices[:, None] < self.object_bounds[:, 1]) # type: ignore[reportOptionalSubscript]
1593
+ triangle_indices = indices_inside_bounds.argmax(
1594
+ axis=1
1595
+ ) # Exactly one bound should be true for each triangle
1596
+ mask = jnp.take(
1597
+ mask,
1598
+ triangle_indices,
1599
+ indices_are_sorted=True, # Object bounds are sorted
1600
+ )
1601
+ elif self.assume_quads:
1575
1602
  mask = jnp.repeat(mask, 2)
1576
1603
 
1577
1604
  return eqx.tree_at(
1578
1605
  lambda m: (m.object_bounds, m.mask),
1579
1606
  self,
1580
- (None, mask),
1607
+ (self.object_bounds if preserve else None, mask),
1581
1608
  is_leaf=lambda x: x is None,
1582
1609
  )
1583
1610
 
1584
1611
  if isinstance(size, int):
1585
1612
  indices = jax.random.choice(
1586
1613
  key,
1587
- self.num_objects,
1614
+ num,
1588
1615
  shape=(size,),
1589
1616
  replace=replace,
1590
1617
  )
@@ -1592,6 +1619,11 @@ class TriangleMesh(eqx.Module):
1592
1619
  msg = "'size' must be an integer when 'by_masking' is False."
1593
1620
  raise TypeError(msg)
1594
1621
 
1622
+ if sample_objects:
1623
+ indices = jnp.concatenate([
1624
+ jnp.arange(self.object_bounds[i, 0], self.object_bounds[i, 1]) # type: ignore[reportOptionalSubscript]
1625
+ for i in indices
1626
+ ])
1595
1627
  if self.assume_quads:
1596
1628
  indices *= 2
1597
1629
 
@@ -1604,6 +1636,11 @@ class TriangleMesh(eqx.Module):
1604
1636
  ),
1605
1637
  axis=-1,
1606
1638
  )
1639
+ # Some object may not have any triangles left after sampling,
1640
+ # so we remove them.
1641
+ object_bounds = object_bounds.compress(
1642
+ object_bounds[:, 0] < object_bounds[:, 1], axis=0
1643
+ )
1607
1644
  else:
1608
1645
  object_bounds = None
1609
1646
 
@@ -120,7 +120,7 @@ class DeepMIMO(eqx.Module, Generic[ArrayType]):
120
120
  )
121
121
 
122
122
  if vertices.shape != self.inter_pos.shape: # pragma: no cover
123
- msg = "Cannot sort based on provided paths: shape mismatch, got {vertices.shape!r} but expected {self.inter_pos.shape!r}."
123
+ msg = f"Cannot sort based on provided paths: shape mismatch, got {vertices.shape!r} but expected {self.inter_pos.shape!r}."
124
124
  raise ValueError(msg)
125
125
 
126
126
  max_num_interactions = self.inter.shape[-1]
@@ -1,12 +1,13 @@
1
1
  import math
2
2
  import os
3
3
  import warnings
4
- from collections.abc import Mapping
4
+ from collections.abc import Iterator, Mapping
5
5
  from typing import TYPE_CHECKING, Any, Literal, overload
6
6
 
7
7
  import equinox as eqx
8
8
  import jax
9
9
  import jax.numpy as jnp
10
+ import numpy as np
10
11
  from jax.experimental.shard_map import shard_map
11
12
  from jax.sharding import PartitionSpec as P
12
13
  from jaxtyping import Array, ArrayLike, Bool, Float, Int
@@ -25,14 +26,13 @@ from differt.rt import (
25
26
  SizedIterator,
26
27
  consecutive_vertices_are_on_same_side_of_mirrors,
27
28
  first_triangles_hit_by_rays,
28
- generate_all_path_candidates,
29
- generate_all_path_candidates_chunks_iter,
30
29
  image_method,
31
30
  rays_intersect_any_triangle,
32
31
  rays_intersect_triangles,
33
32
  triangles_visible_from_vertices,
34
33
  )
35
34
  from differt.utils import dot, smoothing_function
35
+ from differt_core.rt import CompleteGraph, DiGraph
36
36
 
37
37
  if TYPE_CHECKING or "READTHEDOCS" in os.environ:
38
38
  import sys
@@ -52,7 +52,7 @@ else:
52
52
 
53
53
 
54
54
  @eqx.filter_jit
55
- def _compute_paths( # noqa: C901, PLR0915
55
+ def _compute_paths( # noqa: PLR0915
56
56
  mesh: TriangleMesh,
57
57
  tx_vertices: Float[Array, "num_tx_vertices 3"],
58
58
  rx_vertices: Float[Array, "num_rx_vertices 3"],
@@ -117,7 +117,7 @@ def _compute_paths( # noqa: C901, PLR0915
117
117
  # [num_path_candidates order 3]
118
118
  mirror_normals = jnp.take(mesh.normals, path_candidates, axis=0)
119
119
 
120
- def fun( # noqa: PLR0912
120
+ def fun(
121
121
  tx_vertices: Float[Array, "num_tx_vertices 3"],
122
122
  rx_vertices: Float[Array, "num_rx_vertices 3"],
123
123
  ) -> tuple[
@@ -845,7 +845,7 @@ class TriangleScene(eqx.Module):
845
845
  self,
846
846
  order: int | None = None,
847
847
  *,
848
- method: Literal["exhaustive", "hybrid"] = "exhaustive",
848
+ method: Literal["exhaustive"] = "exhaustive",
849
849
  chunk_size: None = None,
850
850
  num_rays: int = int(1e6),
851
851
  path_candidates: Int[ArrayLike, "num_path_candidates order"] | None = None,
@@ -858,12 +858,30 @@ class TriangleScene(eqx.Module):
858
858
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
859
859
  ) -> Paths: ...
860
860
 
861
+ @overload
862
+ def compute_paths(
863
+ self,
864
+ order: int,
865
+ *,
866
+ method: Literal["hybrid"],
867
+ chunk_size: None = None,
868
+ num_rays: int = int(1e6),
869
+ path_candidates: None = None,
870
+ parallel: bool = False,
871
+ epsilon: Float[ArrayLike, " "] | None = None,
872
+ hit_tol: Float[ArrayLike, " "] | None = None,
873
+ min_len: Float[ArrayLike, " "] | None = None,
874
+ max_dist: Float[ArrayLike, " "] = 1e-3,
875
+ smoothing_factor: Float[ArrayLike, " "] | None = None,
876
+ confidence_threshold: Float[ArrayLike, " "] = 0.5,
877
+ ) -> Paths: ...
878
+
861
879
  @overload
862
880
  def compute_paths(
863
881
  self,
864
882
  order: int | None = None,
865
883
  *,
866
- method: Literal["exhaustive", "hybrid"] = "exhaustive",
884
+ method: Literal["exhaustive"] = "exhaustive",
867
885
  chunk_size: int,
868
886
  num_rays: int = int(1e6),
869
887
  path_candidates: None = None,
@@ -876,6 +894,24 @@ class TriangleScene(eqx.Module):
876
894
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
877
895
  ) -> SizedIterator[Paths]: ...
878
896
 
897
+ @overload
898
+ def compute_paths(
899
+ self,
900
+ order: int,
901
+ *,
902
+ method: Literal["hybrid"],
903
+ chunk_size: int,
904
+ num_rays: int = int(1e6),
905
+ path_candidates: None = None,
906
+ parallel: bool = False,
907
+ epsilon: Float[ArrayLike, " "] | None = None,
908
+ hit_tol: Float[ArrayLike, " "] | None = None,
909
+ min_len: Float[ArrayLike, " "] | None = None,
910
+ max_dist: Float[ArrayLike, " "] = 1e-3,
911
+ smoothing_factor: Float[ArrayLike, " "] | None = None,
912
+ confidence_threshold: Float[ArrayLike, " "] = 0.5,
913
+ ) -> Iterator[Paths]: ...
914
+
879
915
  @overload
880
916
  def compute_paths(
881
917
  self,
@@ -912,7 +948,7 @@ class TriangleScene(eqx.Module):
912
948
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
913
949
  ) -> SBRPaths: ...
914
950
 
915
- def compute_paths( # noqa: C901, PLR0912
951
+ def compute_paths( # noqa: PLR0915
916
952
  self,
917
953
  order: int | None = None,
918
954
  *,
@@ -927,7 +963,7 @@ class TriangleScene(eqx.Module):
927
963
  max_dist: Float[ArrayLike, " "] = 1e-3,
928
964
  smoothing_factor: Float[ArrayLike, " "] | None = None,
929
965
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
930
- ) -> Paths | SizedIterator[Paths] | SBRPaths:
966
+ ) -> Paths | SizedIterator[Paths] | Iterator[Paths] | SBRPaths:
931
967
  """
932
968
  Compute paths between all pairs of transmitters and receivers in the scene, that undergo a fixed number of interaction with objects.
933
969
 
@@ -959,7 +995,7 @@ class TriangleScene(eqx.Module):
959
995
  it is likely to changed in future releases. Use with caution.
960
996
  * If ``'hybrid'``, a hybrid method is used, which estimates the objects
961
997
  visible from all transmitters, to reduce the number of path candidates,
962
- by launching a fixed number of rays, and then performs an extausive
998
+ by launching a fixed number of rays, and then performs an exhaustive
963
999
  search on those path candidates. This is a faster alternative to
964
1000
  ``'exhaustive'``, but still grows exponentially with the number of
965
1001
  bounces or the size of the scene. In the future, we plan on allowing
@@ -967,8 +1003,9 @@ class TriangleScene(eqx.Module):
967
1003
  number of path candidates.
968
1004
 
969
1005
  .. warning::
970
-
971
- The ``'hybrid'`` method is not yet implemented.
1006
+ This method is best used for a single transmitter and a single receiver,
1007
+ as the estimated visibility is merged across all transmitters and receivers,
1008
+ respectively.
972
1009
 
973
1010
  chunk_size: If specified, it will iterate through chunks of path
974
1011
  candidates, and yield the result as an iterator over paths chunks.
@@ -989,7 +1026,7 @@ class TriangleScene(eqx.Module):
989
1026
  rounded down toward the nearest even value (but object indices still refer
990
1027
  to triangle indices, not quadrilateral indices).
991
1028
 
992
- **Not compatible with** ``method == 'sbr'``.
1029
+ **Not compatible with** ``method == 'sbr'`` and ``method == 'hybrid'``.
993
1030
  parallel: If :data:`True`, ray tracing is performed in parallel across all available
994
1031
  devices. The number of transmitters times the number of receivers
995
1032
  **must** be a multiple of :func:`jax.device_count`, otherwise an error is raised.
@@ -1045,7 +1082,7 @@ class TriangleScene(eqx.Module):
1045
1082
  ValueError: If neither ``order`` nor ``path_candidates`` has been provided,
1046
1083
  or if both have been provided simultaneously.
1047
1084
 
1048
- If ``method == 'sbr'``, ``order`` is required.
1085
+ If ``method == 'sbr'`` or ``method == 'hybrid'`, and ``order`` is not provided.
1049
1086
 
1050
1087
  If ``parallel`` is :data:`True`, and the number of devices is not a divisor of the number of transmitters times the number of receivers, or the number of transmitters times the number of rays.
1051
1088
 
@@ -1089,39 +1126,72 @@ class TriangleScene(eqx.Module):
1089
1126
  epsilon=epsilon,
1090
1127
  max_dist=max_dist,
1091
1128
  ).reshape(*tx_batch, *rx_batch, -1)
1092
- if method == "hybrid":
1093
- msg = "Hybrid method not implemented yet."
1094
- raise NotImplementedError(msg) # TODO: implement
1095
- visibility = triangles_visible_from_vertices(
1096
- self.transmitters, self.mesh.triangle_vertices
1097
- )
1098
-
1099
- if self.mesh.assume_quads:
1100
- visibility = visibility.reshape(-1, 2).any(axis=-1)
1101
1129
 
1102
1130
  # 0 - Constants arrays of chunks
1103
- num_objects = (
1104
- self.mesh.num_quads if self.mesh.assume_quads else self.mesh.num_triangles
1105
- )
1131
+ assume_quads = self.mesh.assume_quads
1106
1132
 
1107
1133
  # [tx_batch_flattened 3]
1108
1134
  tx_vertices = self.transmitters.reshape(-1, 3)
1109
1135
  # [rx_batch_flattened 3]
1110
1136
  rx_vertices = self.receivers.reshape(-1, 3)
1111
1137
 
1138
+ graph = CompleteGraph(self.mesh.num_primitives)
1139
+
1140
+ if method == "hybrid":
1141
+ if order is None:
1142
+ msg = "Argument 'order' is required when 'method == \"hybrid\"'."
1143
+ raise ValueError(msg)
1144
+
1145
+ triangles_visible_from_tx = triangles_visible_from_vertices(
1146
+ tx_vertices,
1147
+ self.mesh.triangle_vertices,
1148
+ active_triangles=self.mesh.mask,
1149
+ num_rays=num_rays,
1150
+ epsilon=epsilon,
1151
+ ).any(axis=0) # reduce on all transmitters
1152
+
1153
+ triangles_visible_from_rx = triangles_visible_from_vertices(
1154
+ rx_vertices,
1155
+ self.mesh.triangle_vertices,
1156
+ active_triangles=self.mesh.mask,
1157
+ num_rays=num_rays,
1158
+ epsilon=epsilon,
1159
+ ).any(axis=0) # reduce on all receivers
1160
+
1161
+ if assume_quads:
1162
+ triangles_visible_from_tx = triangles_visible_from_tx.reshape(
1163
+ -1, 2
1164
+ ).any(axis=-1) # seeing any triangle of a quad is enough
1165
+ triangles_visible_from_rx = triangles_visible_from_rx.reshape(
1166
+ -1, 2
1167
+ ).any(axis=-1) # seeing any triangle of a quad is enough
1168
+
1169
+ graph = DiGraph.from_complete_graph(graph)
1170
+ from_, to = graph.insert_from_and_to_nodes(
1171
+ from_adjacency=np.asarray(triangles_visible_from_tx),
1172
+ to_adjacency=np.asarray(triangles_visible_from_rx),
1173
+ )
1174
+ else:
1175
+ from_ = graph.num_nodes
1176
+ to = from_ + 1
1177
+
1112
1178
  if chunk_size:
1113
- path_candidates_iter = generate_all_path_candidates_chunks_iter(
1114
- num_objects,
1115
- order, # type: ignore[reportArgumentType]
1179
+ path_candidates_iter = graph.all_paths_array_chunks(
1180
+ from_=from_,
1181
+ to=to,
1182
+ depth=order + 2, # type: ignore[reportOptionalOperand]
1183
+ include_from_and_to=False,
1116
1184
  chunk_size=chunk_size,
1117
1185
  )
1118
- size = path_candidates_iter.__len__
1119
1186
  it = (
1120
1187
  _compute_paths(
1121
1188
  self.mesh,
1122
1189
  tx_vertices,
1123
1190
  rx_vertices,
1124
- 2 * path_candidates if self.mesh.assume_quads else path_candidates,
1191
+ jnp.asarray(
1192
+ 2 * path_candidates if assume_quads else path_candidates,
1193
+ dtype=int,
1194
+ ),
1125
1195
  parallel=parallel,
1126
1196
  epsilon=epsilon,
1127
1197
  hit_tol=hit_tol,
@@ -1132,12 +1202,19 @@ class TriangleScene(eqx.Module):
1132
1202
  for path_candidates in path_candidates_iter
1133
1203
  )
1134
1204
 
1135
- return SizedIterator(it, size=size)
1205
+ if hasattr(path_candidates_iter, "__len__"):
1206
+ return SizedIterator(it, size=path_candidates_iter.__len__)
1207
+ return it
1136
1208
 
1137
1209
  if path_candidates is None:
1138
- path_candidates = generate_all_path_candidates(
1139
- num_objects,
1140
- order,
1210
+ path_candidates = jnp.asarray(
1211
+ graph.all_paths_array(
1212
+ from_=from_,
1213
+ to=to,
1214
+ depth=order + 2, # type: ignore[reportOptionalOperand]
1215
+ include_from_and_to=False,
1216
+ ),
1217
+ dtype=int,
1141
1218
  )
1142
1219
 
1143
1220
  if self.mesh.assume_quads:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes