differt 0.0.20__tar.gz → 0.0.21__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 (27) hide show
  1. {differt-0.0.20 → differt-0.0.21}/PKG-INFO +9 -4
  2. {differt-0.0.20 → differt-0.0.21}/pyproject.toml +1 -1
  3. {differt-0.0.20 → differt-0.0.21}/src/differt/geometry/paths.py +1 -1
  4. {differt-0.0.20 → differt-0.0.21}/src/differt/geometry/triangle_mesh.py +32 -4
  5. {differt-0.0.20 → differt-0.0.21}/src/differt/plotting/_core.py +6 -2
  6. {differt-0.0.20 → differt-0.0.21}/src/differt/plotting/_utils.py +9 -3
  7. {differt-0.0.20 → differt-0.0.21}/src/differt/rt/image_method.py +5 -2
  8. {differt-0.0.20 → differt-0.0.21}/src/differt/rt/utils.py +15 -5
  9. {differt-0.0.20 → differt-0.0.21}/src/differt/scene/triangle_scene.py +118 -23
  10. {differt-0.0.20 → differt-0.0.21}/src/differt/utils.py +17 -12
  11. {differt-0.0.20 → differt-0.0.21}/.gitignore +0 -0
  12. {differt-0.0.20 → differt-0.0.21}/LICENSE.md +0 -0
  13. {differt-0.0.20 → differt-0.0.21}/README.md +0 -0
  14. {differt-0.0.20 → differt-0.0.21}/src/differt/__init__.py +0 -0
  15. {differt-0.0.20 → differt-0.0.21}/src/differt/em/__init__.py +0 -0
  16. {differt-0.0.20 → differt-0.0.21}/src/differt/em/constants.py +0 -0
  17. {differt-0.0.20 → differt-0.0.21}/src/differt/em/special.py +0 -0
  18. {differt-0.0.20 → differt-0.0.21}/src/differt/em/utd.py +0 -0
  19. {differt-0.0.20 → differt-0.0.21}/src/differt/em/utils.py +0 -0
  20. {differt-0.0.20 → differt-0.0.21}/src/differt/geometry/__init__.py +0 -0
  21. {differt-0.0.20 → differt-0.0.21}/src/differt/geometry/utils.py +0 -0
  22. {differt-0.0.20 → differt-0.0.21}/src/differt/plotting/__init__.py +0 -0
  23. {differt-0.0.20 → differt-0.0.21}/src/differt/rt/__init__.py +0 -0
  24. {differt-0.0.20 → differt-0.0.21}/src/differt/rt/fermat.py +0 -0
  25. {differt-0.0.20 → differt-0.0.21}/src/differt/scene/__init__.py +0 -0
  26. {differt-0.0.20 → differt-0.0.21}/src/differt/scene/sionna.py +0 -0
  27. {differt-0.0.20 → differt-0.0.21}/src/differt/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: DiffeRT
3
- Version: 0.0.20
3
+ Version: 0.0.21
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.20
24
+ Requires-Dist: differt-core==0.0.21
25
25
  Requires-Dist: equinox>=0.11.5
26
26
  Requires-Dist: filelock>=3.15.4
27
27
  Requires-Dist: jax>=0.4.32
@@ -180,12 +180,17 @@ or benchmark it:
180
180
  pytest --benchmark-enable differt/tests/benchmarks
181
181
  ```
182
182
 
183
+ ## Citing
184
+
185
+ If you use this software, please cite it as
186
+ [detailed here](https://differt.readthedocs.io/latest/citing.html).
187
+
183
188
  [pypi-version-badge]: https://img.shields.io/pypi/v/DiffeRT?label=DiffeRT&color=blueviolet
184
189
  [pypi-version-url]: https://pypi.org/project/DiffeRT/
185
190
  [pypi-python-version-badge]: https://img.shields.io/pypi/pyversions/DiffeRT?color=orange
186
191
  [documentation-badge]: https://readthedocs.org/projects/differt/badge/?version=latest
187
192
  [documentation-url]: https://differt.readthedocs.io/latest/?badge=latest
188
- [doi-badge]: https://zenodo.org/badge/DOI/10.5281/zenodo.11386432.svg
189
- [doi-url]: https://doi.org/10.5281/zenodo.11386432
193
+ [doi-badge]: https://zenodo.org/badge/DOI/10.5281/zenodo.13895021.svg
194
+ [doi-url]: https://doi.org/10.5281/zenodo.13895021
190
195
  [codecov-badge]: https://codecov.io/gh/jeertmans/DiffeRT/branch/main/graph/badge.svg?token=v63alnTWzu
191
196
  [codecov-url]: https://codecov.io/gh/jeertmans/DiffeRT
@@ -16,7 +16,7 @@ classifiers = [
16
16
  dependencies = [
17
17
  "beartype>=0.17.2",
18
18
  "chex>=0.1.86",
19
- "differt-core==0.0.20",
19
+ "differt-core==0.0.21",
20
20
  "equinox>=0.11.5",
21
21
  "filelock>=3.15.4",
22
22
  "jax>=0.4.32",
@@ -251,7 +251,7 @@ class Paths(eqx.Module):
251
251
 
252
252
  >>> from differt.geometry.paths import Paths
253
253
  >>>
254
- >>> key = jax.random.PRNGKey(1234)
254
+ >>> key = jax.random.key(1234)
255
255
  >>> key_v, key_o = jax.random.split(key, 2)
256
256
  >>> *batch, path_length = (2, 6, 3)
257
257
  >>> vertices = jax.random.uniform(key_v, (*batch, path_length, 3))
@@ -121,6 +121,18 @@ class TriangleMesh(eqx.Module):
121
121
  If the present mesh contains multiple objects, usually as a result of appending
122
122
  multiple meshes together, this array contain start end end indices for each sub mesh.
123
123
  """
124
+ assume_quads: bool = eqx.field(default=False)
125
+ """Flag indicating whether triangles can be paired into quadrilaterals.
126
+
127
+ Setting this to :data:`True` will not check anything, except that
128
+ :attr:`num_triangles` should is even, but each two consecutive
129
+ triangles are assumed to represent a quadrilateral surface.
130
+ """
131
+
132
+ def __check_init__(self) -> None: # noqa: D105,PLW3201
133
+ if self.assume_quads and (self.triangles.shape[0] % 2) != 0:
134
+ msg = "You cannot set 'assume_quads' to 'True' if the number of triangles is not even!"
135
+ raise ValueError(msg)
124
136
 
125
137
  @jaxtyped(
126
138
  typechecker=None
@@ -163,6 +175,19 @@ class TriangleMesh(eqx.Module):
163
175
  """The number of triangles."""
164
176
  return self.triangles.shape[0]
165
177
 
178
+ @property
179
+ def num_quads(self) -> int:
180
+ """The number of quadrilaterals.
181
+
182
+ Raises:
183
+ ValueError: If :attr:`assume_quads` is :data:`False`.
184
+ """
185
+ if not self.assume_quads:
186
+ msg = "Cannot access the number of quadrilaterals if 'assume_quads' is set to 'False'."
187
+ raise ValueError(msg)
188
+
189
+ return self.triangles.shape[0] // 2
190
+
166
191
  @property
167
192
  @jax.jit
168
193
  @jaxtyped(typechecker=typechecker)
@@ -171,6 +196,9 @@ class TriangleMesh(eqx.Module):
171
196
 
172
197
  TODO: improve description.
173
198
  """
199
+ if self.triangles.size == 0:
200
+ return jnp.empty_like(self.vertices, shape=(0, 3, 3))
201
+
174
202
  return jnp.take(self.vertices, self.triangles, axis=0)
175
203
 
176
204
  @classmethod
@@ -294,11 +322,11 @@ class TriangleMesh(eqx.Module):
294
322
  A new plane mesh.
295
323
 
296
324
  Raises:
297
- ValueError: If one of two ``other_vertices`` or ``normal``
298
- were not provided.
325
+ ValueError: If neither ``other_vertices`` nor ``normal`` has been provided,
326
+ or if both have been provided simultaneously.
299
327
  """
300
328
  if (other_vertices == ()) == (normal is None):
301
- msg = "You must specify one of `other_vertices` or `normal`, not both."
329
+ msg = "You must specify one of 'other_vertices' or 'normal', not both."
302
330
  raise ValueError(msg)
303
331
  if other_vertices:
304
332
  if len(other_vertices) != 2: # noqa: PLR2004
@@ -406,7 +434,7 @@ class TriangleMesh(eqx.Module):
406
434
  Args:
407
435
  size: The size of the sample, i.e., the number of triangles.
408
436
  replace: Whether to sample with or without replacement.
409
- key: The :func:`jax.random.PRNGKey` to be used.
437
+ key: The :func:`jax.random.key` to be used.
410
438
 
411
439
  Returns:
412
440
  A new random mesh.
@@ -281,8 +281,12 @@ def draw_rays(
281
281
  >>> from differt.plotting import draw_rays
282
282
  >>>
283
283
  >>> ray_origins = np.zeros(3)
284
- >>> ray_directions = np.asarray(fibonacci_lattice(50)) # From JAX to NumPy array
285
- >>> ray_origins, ray_directions = np.broadcast_arrays(ray_origins, ray_directions)
284
+ >>> ray_directions = np.asarray(
285
+ ... fibonacci_lattice(50)
286
+ ... ) # From JAX to NumPy array
287
+ >>> ray_origins, ray_directions = np.broadcast_arrays(
288
+ ... ray_origins, ray_directions
289
+ ... )
286
290
  >>> fig = draw_rays(
287
291
  ... ray_origins,
288
292
  ... ray_directions,
@@ -153,9 +153,13 @@ def set_defaults(backend: str | None = None, **kwargs: Any) -> BackendName:
153
153
  'matplotlib'
154
154
  >>> my_plot() # So that now it defaults to 'matplotlib' and color='red'
155
155
  Using matplotlib backend with args = (), kwargs = {'color': 'red'}
156
- >>> my_plot(backend="vispy") # Of course, the 'vispy' backend is still available
156
+ >>> my_plot(
157
+ ... backend="vispy"
158
+ ... ) # Of course, the 'vispy' backend is still available
157
159
  Using vispy backend with args = (), kwargs = {'color': 'red'}
158
- >>> my_plot(backend="vispy", color="green") # And we can also override any default
160
+ >>> my_plot(
161
+ ... backend="vispy", color="green"
162
+ ... ) # And we can also override any default
159
163
  Using vispy backend with args = (), kwargs = {'color': 'green'}
160
164
  >>> dplt.set_defaults("vispy") # Reset all defaults
161
165
  'vispy'
@@ -204,7 +208,9 @@ def use(backend: str | None = None, **kwargs: Any) -> Iterator[BackendName]:
204
208
  >>>
205
209
  >>> my_plot() # When not specified, use default backend
206
210
  Using vispy backend with args = (), kwargs = {}
207
- >>> with dplt.use(): # No parameters = reset defaults (except the default backend)
211
+ >>> with (
212
+ ... dplt.use()
213
+ ... ): # No parameters = reset defaults (except the default backend)
208
214
  ... my_plot()
209
215
  Using vispy backend with args = (), kwargs = {}
210
216
  >>> with dplt.use("plotly"): # We can change the default backend
@@ -76,7 +76,10 @@ Examples:
76
76
  ... draw_paths(full_path, marker={"color": "green"}, name="Final path")
77
77
  ... markers = jnp.vstack((from_vertex, to_vertex))
78
78
  ... draw_markers(
79
- ... markers, labels=["BS", "UE"], marker={"color": "black"}, name="BS/UE"
79
+ ... markers,
80
+ ... labels=["BS", "UE"],
81
+ ... marker={"color": "black"},
82
+ ... name="BS/UE",
80
83
  ... )
81
84
  ... fig.update_layout(scene_aspectmode="data")
82
85
  >>> fig # doctest: +SKIP
@@ -120,7 +123,7 @@ def image_of_vertices_with_respect_to_mirrors(
120
123
  ... image_of_vertices_with_respect_to_mirrors,
121
124
  ... )
122
125
  >>>
123
- >>> key = jax.random.PRNGKey(0)
126
+ >>> key = jax.random.key(0)
124
127
  >>> (
125
128
  ... key0,
126
129
  ... key1,
@@ -230,13 +230,18 @@ def rays_intersect_triangles(
230
230
  >>> from differt.rt.utils import (
231
231
  ... rays_intersect_triangles,
232
232
  ... )
233
- >>> from differt.scene.sionna import get_sionna_scene, download_sionna_scenes
233
+ >>> from differt.scene.sionna import (
234
+ ... get_sionna_scene,
235
+ ... download_sionna_scenes,
236
+ ... )
234
237
  >>> from differt.scene.triangle_scene import TriangleScene
235
238
  >>>
236
239
  >>> download_sionna_scenes()
237
240
  >>> file = get_sionna_scene("simple_street_canyon")
238
241
  >>> scene = TriangleScene.load_xml(file)
239
- >>> scene = eqx.tree_at(lambda s: s.transmitters, scene, jnp.array([-33, 0, 32.0]))
242
+ >>> scene = eqx.tree_at(
243
+ ... lambda s: s.transmitters, scene, jnp.array([-33, 0, 32.0])
244
+ ... )
240
245
  >>> ray_origins, ray_directions = jnp.broadcast_arrays(
241
246
  ... scene.transmitters, fibonacci_lattice(25)
242
247
  ... )
@@ -362,7 +367,7 @@ def rays_intersect_any_triangle(
362
367
 
363
368
  @jaxtyped(typechecker=typechecker)
364
369
  def scan_fun(
365
- intersect: Bool[Array, " *#batch"],
370
+ intersect: Bool[Array, " *batch"],
366
371
  triangle_vertices: Float[Array, "*#batch 3 3"],
367
372
  ) -> tuple[Bool[Array, " *batch"], None]:
368
373
  t, hit = rays_intersect_triangles(
@@ -421,13 +426,18 @@ def triangles_visible_from_vertices(
421
426
  >>> from differt.rt.utils import (
422
427
  ... triangles_visible_from_vertices,
423
428
  ... )
424
- >>> from differt.scene.sionna import get_sionna_scene, download_sionna_scenes
429
+ >>> from differt.scene.sionna import (
430
+ ... get_sionna_scene,
431
+ ... download_sionna_scenes,
432
+ ... )
425
433
  >>> from differt.scene.triangle_scene import TriangleScene
426
434
  >>>
427
435
  >>> download_sionna_scenes()
428
436
  >>> file = get_sionna_scene("simple_street_canyon")
429
437
  >>> scene = TriangleScene.load_xml(file)
430
- >>> scene = eqx.tree_at(lambda s: s.transmitters, scene, jnp.array([-33, 0, 32.0]))
438
+ >>> scene = eqx.tree_at(
439
+ ... lambda s: s.transmitters, scene, jnp.array([-33, 0, 32.0])
440
+ ... )
431
441
  >>> visible_triangles = triangles_visible_from_vertices(
432
442
  ... scene.transmitters,
433
443
  ... scene.mesh.triangle_vertices,
@@ -2,6 +2,7 @@
2
2
  # ruff: noqa: ERA001
3
3
 
4
4
  import sys
5
+ import warnings
5
6
  from collections.abc import Mapping
6
7
  from typing import Any
7
8
 
@@ -50,20 +51,42 @@ def _compute_paths(
50
51
  path_candidates: Int[Array, "num_path_candidates order"],
51
52
  *,
52
53
  parallel: bool = False,
53
- **kwargs: Any,
54
+ epsilon: Float[ArrayLike, " "] | None = None,
55
+ hit_tol: Float[ArrayLike, " "] | None = None,
56
+ min_len: Float[ArrayLike, " "] | None = None,
54
57
  ) -> Paths:
55
- epsilon = kwargs.pop("epsilon", None)
56
- hit_tol = kwargs.pop("hit_tol", None)
58
+ if min_len is None:
59
+ dtype = jnp.result_type(mesh.vertices, from_vertices, to_vertices)
60
+ min_len = 10 * jnp.finfo(dtype).eps
57
61
 
58
62
  # 1 - Broadcast arrays
59
63
 
60
- num_path_candidates = path_candidates.shape[0]
64
+ num_path_candidates, order = path_candidates.shape
61
65
 
62
66
  # [num_path_candidates order 3]
63
- triangles = jnp.take(mesh.triangles, path_candidates, axis=0)
67
+ triangles = jnp.take(mesh.triangles, path_candidates, axis=0).reshape(
68
+ num_path_candidates, order, 3
69
+ ) # reshape required if mesh is empty
64
70
 
65
71
  # [num_path_candidates order 3 3]
66
- triangle_vertices = jnp.take(mesh.vertices, triangles, axis=0)
72
+ triangle_vertices = jnp.take(mesh.vertices, triangles, axis=0).reshape(
73
+ num_path_candidates, order, 3, 3
74
+ ) # reshape required if mesh is empty
75
+
76
+ if mesh.assume_quads:
77
+ # [num_path_candidates order 2 3]
78
+ quads = jnp.take(
79
+ mesh.triangles,
80
+ jnp.stack((path_candidates, path_candidates + 1), axis=-1),
81
+ axis=0,
82
+ ).reshape(num_path_candidates, order, 2, 3) # reshape required if mesh is empty
83
+
84
+ # [num_path_candidates order 2 3 3]
85
+ quad_vertices = jnp.take(mesh.vertices, quads, axis=0).reshape(
86
+ num_path_candidates, order, 2, 3, 3
87
+ ) # reshape required if mesh is empty
88
+ else:
89
+ quad_vertices = None
67
90
 
68
91
  # [num_path_candidates order 3]
69
92
  mirror_vertices = triangle_vertices[
@@ -112,12 +135,24 @@ def _compute_paths(
112
135
  # 3.1 - Check if paths vertices are inside respective triangles
113
136
 
114
137
  # [num_from_vertices num_to_vertices num_path_candidates]
115
- inside_triangles = rays_intersect_triangles(
116
- ray_origins[..., :-1, :],
117
- ray_directions[..., :-1, :],
118
- triangle_vertices,
119
- epsilon=epsilon,
120
- )[1].all(axis=-1) # Reduce on 'order' axis
138
+ if mesh.assume_quads:
139
+ inside_triangles = (
140
+ rays_intersect_triangles(
141
+ ray_origins[..., :-1, None, :],
142
+ ray_directions[..., :-1, None, :],
143
+ quad_vertices, # type: ignore[reportArgumentType]
144
+ epsilon=epsilon,
145
+ )[1]
146
+ .any(axis=-1)
147
+ .all(axis=-1)
148
+ ) # Reduce on 'order' axis and on the two triangles (per quad)
149
+ else:
150
+ inside_triangles = rays_intersect_triangles(
151
+ ray_origins[..., :-1, :],
152
+ ray_directions[..., :-1, :],
153
+ triangle_vertices,
154
+ epsilon=epsilon,
155
+ )[1].all(axis=-1) # Reduce on 'order' axis
121
156
 
122
157
  # 3.2 - Check if consecutive path vertices are on the same side of mirrors
123
158
 
@@ -139,9 +174,15 @@ def _compute_paths(
139
174
  hit_tol=hit_tol,
140
175
  ).any(axis=-1) # Reduce on 'order'
141
176
 
142
- # TODO: we also need to somehow mask degenerate paths, e.g., when two reflections occur on an edge
177
+ # 3.4 - Identify path segments that are too small (e.g., double-reflection inside an edge)
178
+
179
+ ray_lengths = jnp.sum(ray_directions * ray_directions, axis=-1) # Squared norm
143
180
 
144
- mask = inside_triangles & valid_reflections & ~blocked
181
+ too_small = (ray_lengths < min_len).any(
182
+ axis=-1
183
+ ) # Any path segment being too small
184
+
185
+ mask = inside_triangles & valid_reflections & ~blocked & ~too_small
145
186
 
146
187
  return full_paths, mask
147
188
 
@@ -349,31 +390,69 @@ class TriangleScene(eqx.Module):
349
390
 
350
391
  def compute_paths(
351
392
  self,
352
- order: int,
393
+ order: int | None = None,
353
394
  *,
354
395
  chunk_size: int | None = None,
396
+ path_candidates: Int[Array, "num_path_candidates order"] | None = None,
355
397
  parallel: bool = False,
356
- **kwargs: Any,
398
+ epsilon: Float[ArrayLike, " "] | None = None,
399
+ hit_tol: Float[ArrayLike, " "] | None = None,
400
+ min_len: Float[ArrayLike, " "] | None = None,
357
401
  ) -> Paths | SizedIterator[Paths]:
358
402
  """
359
403
  Compute paths between all pairs of transmitters and receivers in the scene, that undergo a fixed number of interaction with objects.
360
404
 
405
+ Note:
406
+ Currently, only :abbr:`LOS (line of sight)` and fixed ``order`` reflection paths are computed,
407
+ using the :func:`image_method<differt.rt.image_method.image_method>`. More types of interactions
408
+ and path tracing methods will be added in the future, so stay tuned!
409
+
361
410
  Args:
362
411
  order: The number of interaction, i.e., the number of bounces.
412
+
413
+ This or ``path_candidates`` must be specified.
363
414
  chunk_size: If specified, it will iterate through chunks of path
364
415
  candidates, and yield the result as an iterator over paths chunks.
416
+
417
+ Unused if ``path_candidates`` is provided.
418
+ path_candidates: An option array of path candidates, see :ref:`path_candidates`.
419
+
420
+ This is helpful to only generate paths on a subset of the scene.
421
+
422
+ If ``self.mesh.assume_quads`` is :data:`True`, then path candidates are
423
+ rounded down toward the nearest even value.
365
424
  parallel: If :data:`True`, ray tracing is performed in parallel across all available
366
425
  devices. Either the number of transmitters or the number of receivers
367
426
  **must** be a multiple of :func:`jax.device_count`, otherwise an error is raised.
368
- kwargs: Keyword arguments passed to
427
+ epsilon: Tolelance for checking ray / objects intersection, see
428
+ :func:`rays_intersect_triangles<differt.rt.utils.rays_intersect_triangles>`.
429
+ hit_tol: Tolerance for checking blockage (i.e., obstruction), see
369
430
  :func:`rays_intersect_any_triangle<differt.rt.utils.rays_intersect_any_triangle>`.
431
+ min_len: Minimal (squared) length that each path segment must have for a path to be valid.
432
+
433
+ If not specified, the default is ten times the epsilon value
434
+ of the currently used floating point dtype.
370
435
 
371
436
  Returns:
372
437
  The paths, as class wrapping path vertices, object indices, and a masked
373
438
  identify valid paths.
439
+
440
+ Raises:
441
+ ValueError: If neither ``order`` nor ``path_candidates`` has been provided,
442
+ or if both have been provided simultaneously.
374
443
  """
444
+ if (order is None) == (path_candidates is None):
445
+ msg = "You must specify one of 'order' or `path_candidates`, not both."
446
+ raise ValueError(msg)
447
+ if (chunk_size is not None) and (path_candidates is not None):
448
+ msg = "Argument 'chunk_size' is ignored when 'path_candidates' is provided."
449
+ warnings.warn(msg, UserWarning, stacklevel=2)
450
+ chunk_size = None
451
+
375
452
  # 0 - Constants arrays of chunks
376
- num_triangles = self.mesh.triangles.shape[0]
453
+ num_objects = (
454
+ self.mesh.num_quads if self.mesh.assume_quads else self.mesh.num_triangles
455
+ )
377
456
  tx_batch = self.transmitters.shape[:-1]
378
457
  rx_batch = self.receivers.shape[:-1]
379
458
 
@@ -384,7 +463,9 @@ class TriangleScene(eqx.Module):
384
463
 
385
464
  if chunk_size:
386
465
  path_candidates_iter = generate_all_path_candidates_chunks_iter(
387
- num_triangles, order, chunk_size=chunk_size
466
+ num_objects,
467
+ order, # type: ignore[reportArgumentType]
468
+ chunk_size=chunk_size,
388
469
  )
389
470
  size = path_candidates_iter.__len__
390
471
  it = (
@@ -392,23 +473,37 @@ class TriangleScene(eqx.Module):
392
473
  self.mesh,
393
474
  from_vertices,
394
475
  to_vertices,
395
- path_candidates,
476
+ 2 * path_candidates if self.mesh.assume_quads else path_candidates,
396
477
  parallel=parallel,
397
- **kwargs,
478
+ epsilon=epsilon,
479
+ hit_tol=hit_tol,
480
+ min_len=min_len,
398
481
  ).reshape(*tx_batch, *rx_batch, path_candidates.shape[0])
399
482
  for path_candidates in path_candidates_iter
400
483
  )
401
484
 
402
485
  return SizedIterator(it, size=size)
403
486
 
404
- path_candidates = generate_all_path_candidates(num_triangles, order)
487
+ if path_candidates is None:
488
+ path_candidates = generate_all_path_candidates(
489
+ num_objects,
490
+ order, # type: ignore[reportArgumentType]
491
+ )
492
+
493
+ if self.mesh.assume_quads:
494
+ path_candidates = 2 * path_candidates
495
+ elif self.mesh.assume_quads:
496
+ path_candidates -= path_candidates % 2
497
+
405
498
  return _compute_paths(
406
499
  self.mesh,
407
500
  from_vertices,
408
501
  to_vertices,
409
502
  path_candidates,
410
503
  parallel=parallel,
411
- **kwargs,
504
+ epsilon=epsilon,
505
+ hit_tol=hit_tol,
506
+ min_len=min_len,
412
507
  ).reshape(*tx_batch, *rx_batch, path_candidates.shape[0])
413
508
 
414
509
  def plot(
@@ -43,7 +43,7 @@ def sorted_array2(array: Shaped[Array, "m n"]) -> Shaped[Array, "m n"]:
43
43
  ... )
44
44
  >>>
45
45
  >>> arr = jnp.arange(10).reshape(5, 2)
46
- >>> key = jax.random.PRNGKey(1234)
46
+ >>> key = jax.random.key(1234)
47
47
  >>> (
48
48
  ... key1,
49
49
  ... key2,
@@ -160,7 +160,9 @@ def minimize(
160
160
  >>> # You can also change the optimizer and the number of steps
161
161
  >>> import optax
162
162
  >>> optimizer = optax.noisy_sgd(learning_rate=0.003)
163
- >>> x, y = minimize(f, jnp.zeros(5), args=(4.0,), steps=10000, optimizer=optimizer)
163
+ >>> x, y = minimize(
164
+ ... f, jnp.zeros(5), args=(4.0,), steps=10000, optimizer=optimizer
165
+ ... )
164
166
  >>> chex.assert_trees_all_close(x, 4.0 * jnp.ones(5), rtol=1e-2)
165
167
  >>> chex.assert_trees_all_close(y, 0.0, atol=1e-3)
166
168
 
@@ -173,7 +175,7 @@ def minimize(
173
175
  >>>
174
176
  >>> batch = (1, 2, 3)
175
177
  >>> n = 10
176
- >>> key = jax.random.PRNGKey(1234)
178
+ >>> key = jax.random.key(1234)
177
179
  >>> offset = jax.random.uniform(key, (*batch, n))
178
180
  >>>
179
181
  >>> def f(x, offset, scale=2.0):
@@ -233,17 +235,20 @@ def minimize(
233
235
  @jaxtyped(typechecker=typechecker)
234
236
  def sample_points_in_bounding_box(
235
237
  bounding_box: Float[Array, "2 3"],
236
- size: int | None = None,
238
+ shape: tuple[int, ...] | None = None,
237
239
  *,
238
240
  key: PRNGKeyArray,
239
- ) -> Float[Array, "size 3"] | Float[Array, "3"]:
241
+ ) -> (
242
+ Float[Array, "*shape 3"] | Float[Array, "3"]
243
+ ): # TODO: use symbolic expression to link to 'shape' parameter
240
244
  """
241
245
  Sample point(s) in a 3D bounding box.
242
246
 
243
247
  Args:
244
248
  bounding_box: The bounding box (min. and max. coordinates).
245
- size: The sample size or :data:`None`. If :data:`None`,
246
- the returned array is 1D. Otherwise, it is 2D.
249
+ shape: The sample shape or :data:`None`. If :data:`None`,
250
+ the returned array is 1D. Otherwise, the shape
251
+ of the returned array is ``(*shape, 3)``.
247
252
  key: The :func:`jax.random.PRNGKey` to be used.
248
253
 
249
254
  Returns:
@@ -253,9 +258,9 @@ def sample_points_in_bounding_box(
253
258
  amax = bounding_box[1, :]
254
259
  scale = amax - amin
255
260
 
256
- if size is None:
257
- r = jax.random.uniform(key, shape=(3,))
258
- return r * scale + amin
261
+ if shape is None:
262
+ shape = ()
263
+
264
+ r = jax.random.uniform(key, shape=(*shape, 3))
259
265
 
260
- r = jax.random.uniform(key, shape=(size, 3))
261
- return r * scale[None, :] + amin[None, :]
266
+ return r * scale + amin
File without changes
File without changes
File without changes
File without changes