differt 0.7.0__tar.gz → 0.8.1__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.7.0 → differt-0.8.1}/PKG-INFO +4 -4
- {differt-0.7.0 → differt-0.8.1}/README.md +1 -1
- {differt-0.7.0 → differt-0.8.1}/pyproject.toml +2 -2
- {differt-0.7.0 → differt-0.8.1}/src/differt/em/_antenna.py +5 -3
- {differt-0.7.0 → differt-0.8.1}/src/differt/geometry/_paths.py +1 -1
- {differt-0.7.0 → differt-0.8.1}/src/differt/geometry/_triangle_mesh.py +186 -36
- {differt-0.7.0 → differt-0.8.1}/src/differt/geometry/_utils.py +10 -5
- {differt-0.7.0 → differt-0.8.1}/src/differt/plotting/__init__.py +2 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/plotting/_core.py +44 -20
- {differt-0.7.0 → differt-0.8.1}/src/differt/plotting/_utils.py +52 -41
- {differt-0.7.0 → differt-0.8.1}/src/differt/plugins/deepmimo.py +12 -2
- {differt-0.7.0 → differt-0.8.1}/src/differt/rt/_fermat.py +16 -12
- {differt-0.7.0 → differt-0.8.1}/src/differt/scene/_triangle_scene.py +10 -5
- {differt-0.7.0 → differt-0.8.1}/.gitignore +0 -0
- {differt-0.7.0 → differt-0.8.1}/LICENSE.md +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/__init__.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/_version.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/em/__init__.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/em/_constants.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/em/_fresnel.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/em/_interaction_type.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/em/_material.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/em/_utd.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/em/_utils.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/geometry/__init__.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/plugins/__init__.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/plugins/_deepmimo_types.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/py.typed +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/rt/__init__.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/rt/_image_method.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/rt/_utils.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/scene/__init__.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/scene/_sionna.py +0 -0
- {differt-0.7.0 → differt-0.8.1}/src/differt/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.1
|
|
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,8 +21,8 @@ Classifier: Programming Language :: Python :: Free Threading
|
|
|
21
21
|
Classifier: Topic :: Scientific/Engineering
|
|
22
22
|
Requires-Python: >=3.11
|
|
23
23
|
Requires-Dist: chex>=0.1.86
|
|
24
|
-
Requires-Dist: differt-core==0.
|
|
25
|
-
Requires-Dist: equinox>=0.13.
|
|
24
|
+
Requires-Dist: differt-core==0.8.1
|
|
25
|
+
Requires-Dist: equinox>=0.13.7
|
|
26
26
|
Requires-Dist: filelock>=3.15.4
|
|
27
27
|
Requires-Dist: fpt-jax==0.1.0
|
|
28
28
|
Requires-Dist: jax>=0.8.1
|
|
@@ -156,7 +156,7 @@ or:
|
|
|
156
156
|
author = {Eertmans, Jérome},
|
|
157
157
|
url = {https://github.com/jeertmans/DiffeRT},
|
|
158
158
|
license = {MIT},
|
|
159
|
-
version = {v0.
|
|
159
|
+
version = {v0.8.1}
|
|
160
160
|
}
|
|
161
161
|
```
|
|
162
162
|
|
|
@@ -645,11 +645,13 @@ class RadiationPattern(BaseAntenna):
|
|
|
645
645
|
|
|
646
646
|
r = self.center + distance * jnp.stack((x, y, z), axis=-1)
|
|
647
647
|
|
|
648
|
-
s = self.
|
|
648
|
+
s, p = self.polarization_vectors(r)
|
|
649
649
|
|
|
650
|
-
|
|
650
|
+
power = jnp.sum(s * s, axis=-1, keepdims=True) + jnp.sum(
|
|
651
|
+
p * p, axis=-1, keepdims=True
|
|
652
|
+
)
|
|
651
653
|
|
|
652
|
-
gain =
|
|
654
|
+
gain = power / power.max()
|
|
653
655
|
|
|
654
656
|
r *= gain
|
|
655
657
|
gain = jnp.squeeze(gain, axis=-1)
|
|
@@ -350,7 +350,7 @@ class Paths(eqx.Module, Generic[_M]):
|
|
|
350
350
|
|
|
351
351
|
if not _is_masked_paths(paths):
|
|
352
352
|
# ty is unable to infer that _M & ~Array implies None
|
|
353
|
-
return paths # type: ignore[invalid-return-type]
|
|
353
|
+
return paths # type: ignore[ty:invalid-return-type]
|
|
354
354
|
|
|
355
355
|
mask = paths.mask
|
|
356
356
|
if mask.dtype == jnp.bool_:
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import typing
|
|
2
|
-
from collections.abc import Callable, Iterator, Mapping
|
|
2
|
+
from collections.abc import Callable, Iterator, Mapping, Sequence
|
|
3
3
|
from dataclasses import replace
|
|
4
4
|
from typing import (
|
|
5
5
|
TYPE_CHECKING,
|
|
6
6
|
Any,
|
|
7
7
|
Generic,
|
|
8
8
|
Literal,
|
|
9
|
+
NotRequired,
|
|
9
10
|
TypedDict,
|
|
10
11
|
TypeVar,
|
|
12
|
+
Unpack,
|
|
11
13
|
overload,
|
|
12
14
|
)
|
|
13
15
|
|
|
@@ -28,18 +30,27 @@ else:
|
|
|
28
30
|
|
|
29
31
|
|
|
30
32
|
class _AtIndexingKwargs(TypedDict):
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
mode: NotRequired[Literal["promise_in_bounds", "clip", "drop", "fill"]]
|
|
34
|
+
wrap_negative_indices: NotRequired[bool]
|
|
35
|
+
indices_are_sorted: NotRequired[bool]
|
|
36
|
+
unique_indices: NotRequired[bool]
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
_AT_INDEXING_KWARGS: _AtIndexingKwargs = {
|
|
40
|
+
"wrap_negative_indices": False,
|
|
37
41
|
"indices_are_sorted": True,
|
|
38
42
|
"unique_indices": True,
|
|
39
|
-
"wrap_negative_indices": False,
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
|
|
46
|
+
class _GetIndexingKwargs(TypedDict):
|
|
47
|
+
mode: Literal["promise_in_bounds", "clip", "drop", "fill"]
|
|
48
|
+
wrap_negative_indices: NotRequired[bool]
|
|
49
|
+
fill_value: NotRequired[Any]
|
|
50
|
+
indices_are_sorted: NotRequired[bool]
|
|
51
|
+
unique_indices: NotRequired[bool]
|
|
52
|
+
|
|
53
|
+
|
|
43
54
|
@jax.jit
|
|
44
55
|
def triangles_contain_vertices_assuming_inside_same_plane(
|
|
45
56
|
triangle_vertices: Float[ArrayLike, "*#batch 3 3"],
|
|
@@ -102,7 +113,14 @@ def triangles_contain_vertices_assuming_inside_same_plane(
|
|
|
102
113
|
return all_pos | all_neg
|
|
103
114
|
|
|
104
115
|
|
|
105
|
-
_Index =
|
|
116
|
+
_Index = (
|
|
117
|
+
slice
|
|
118
|
+
| Int[ArrayLike, ""]
|
|
119
|
+
| Int[Array, " n"]
|
|
120
|
+
| Bool[Array, " num_triangles"]
|
|
121
|
+
| Sequence[int]
|
|
122
|
+
| Sequence[bool]
|
|
123
|
+
)
|
|
106
124
|
_T = TypeVar("_T", bound="TriangleMesh")
|
|
107
125
|
|
|
108
126
|
|
|
@@ -127,19 +145,40 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
|
|
|
127
145
|
__slots__ = ("index", "mesh")
|
|
128
146
|
|
|
129
147
|
def __init__(self, mesh: _T, index: _Index) -> None:
|
|
148
|
+
if not isinstance(index, slice):
|
|
149
|
+
index_array = jnp.asarray(index)
|
|
150
|
+
if index_array.ndim > 1:
|
|
151
|
+
msg = f"Index must be at most one-dimensional, got array with shape {index_array.shape}."
|
|
152
|
+
raise ValueError(msg)
|
|
130
153
|
self.mesh = mesh
|
|
131
154
|
self.index = index
|
|
132
155
|
|
|
133
156
|
def __repr__(self) -> str:
|
|
134
157
|
return f"_TriangleMeshVerticesUpdateRef({self.mesh!r}, {self.index!r})"
|
|
135
158
|
|
|
136
|
-
def _triangles_index(self, **kwargs:
|
|
159
|
+
def _triangles_index(self, **kwargs: Unpack[_GetIndexingKwargs]) -> _Index:
|
|
137
160
|
index = self.mesh.triangles.at[self.index, :].get(**kwargs).reshape(-1)
|
|
138
161
|
return jnp.unique(
|
|
139
162
|
index, size=len(index), fill_value=self.mesh.vertices.shape[0]
|
|
140
163
|
)
|
|
141
164
|
|
|
142
|
-
def
|
|
165
|
+
def get(
|
|
166
|
+
self, **kwargs: Unpack[_GetIndexingKwargs]
|
|
167
|
+
) -> Float[ArrayLike, "num_indexed_triangles 3"]:
|
|
168
|
+
# get() is allowed to return duplicates, so we do not use _triangles_index()
|
|
169
|
+
index = self.mesh.triangles.at[self.index, :].get(**kwargs).reshape(-1)
|
|
170
|
+
return self.mesh.vertices.at[index, :].get(wrap_negative_indices=False)
|
|
171
|
+
|
|
172
|
+
def set(
|
|
173
|
+
self,
|
|
174
|
+
values: (
|
|
175
|
+
Float[ArrayLike, "3"]
|
|
176
|
+
| Float[ArrayLike, "1"]
|
|
177
|
+
| Float[ArrayLike, ""]
|
|
178
|
+
| Sequence[float]
|
|
179
|
+
),
|
|
180
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
181
|
+
) -> _T:
|
|
143
182
|
index = self._triangles_index(**kwargs)
|
|
144
183
|
return eqx.tree_at(
|
|
145
184
|
lambda m: m.vertices,
|
|
@@ -147,35 +186,50 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
|
|
|
147
186
|
self.mesh.vertices.at[index, :].set(values, **_AT_INDEXING_KWARGS),
|
|
148
187
|
)
|
|
149
188
|
|
|
150
|
-
def
|
|
151
|
-
# get() is allowed to return duplicates, so we do not use _triangles_index()
|
|
152
|
-
index = self.mesh.triangles.at[self.index, :].get(**kwargs).reshape(-1)
|
|
153
|
-
return self.mesh.vertices.at[index, :].get(wrap_negative_indices=False)
|
|
154
|
-
|
|
155
|
-
def apply(
|
|
189
|
+
def add(
|
|
156
190
|
self,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
Float[
|
|
160
|
-
|
|
161
|
-
|
|
191
|
+
values: (
|
|
192
|
+
Float[ArrayLike, "3"]
|
|
193
|
+
| Float[ArrayLike, "1"]
|
|
194
|
+
| Float[ArrayLike, ""]
|
|
195
|
+
| Sequence[float]
|
|
196
|
+
),
|
|
197
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
162
198
|
) -> _T:
|
|
163
199
|
index = self._triangles_index(**kwargs)
|
|
164
200
|
return eqx.tree_at(
|
|
165
201
|
lambda m: m.vertices,
|
|
166
202
|
self.mesh,
|
|
167
|
-
self.mesh.vertices.at[index, :].
|
|
203
|
+
self.mesh.vertices.at[index, :].add(values, **_AT_INDEXING_KWARGS),
|
|
168
204
|
)
|
|
169
205
|
|
|
170
|
-
def
|
|
206
|
+
def sub(
|
|
207
|
+
self,
|
|
208
|
+
values: (
|
|
209
|
+
Float[ArrayLike, "3"]
|
|
210
|
+
| Float[ArrayLike, "1"]
|
|
211
|
+
| Float[ArrayLike, ""]
|
|
212
|
+
| Sequence[float]
|
|
213
|
+
),
|
|
214
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
215
|
+
) -> _T:
|
|
171
216
|
index = self._triangles_index(**kwargs)
|
|
172
217
|
return eqx.tree_at(
|
|
173
218
|
lambda m: m.vertices,
|
|
174
219
|
self.mesh,
|
|
175
|
-
self.mesh.vertices.at[index, :].
|
|
220
|
+
self.mesh.vertices.at[index, :].subtract(values, **_AT_INDEXING_KWARGS),
|
|
176
221
|
)
|
|
177
222
|
|
|
178
|
-
def mul(
|
|
223
|
+
def mul(
|
|
224
|
+
self,
|
|
225
|
+
values: (
|
|
226
|
+
Float[ArrayLike, "3"]
|
|
227
|
+
| Float[ArrayLike, "1"]
|
|
228
|
+
| Float[ArrayLike, ""]
|
|
229
|
+
| Sequence[float]
|
|
230
|
+
),
|
|
231
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
232
|
+
) -> _T:
|
|
179
233
|
index = self._triangles_index(**kwargs)
|
|
180
234
|
return eqx.tree_at(
|
|
181
235
|
lambda m: m.vertices,
|
|
@@ -183,6 +237,89 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
|
|
|
183
237
|
self.mesh.vertices.at[index, :].mul(values, **_AT_INDEXING_KWARGS),
|
|
184
238
|
)
|
|
185
239
|
|
|
240
|
+
def div(
|
|
241
|
+
self,
|
|
242
|
+
values: (
|
|
243
|
+
Float[ArrayLike, "3"]
|
|
244
|
+
| Float[ArrayLike, "1"]
|
|
245
|
+
| Float[ArrayLike, ""]
|
|
246
|
+
| Sequence[float]
|
|
247
|
+
),
|
|
248
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
249
|
+
) -> _T:
|
|
250
|
+
index = self._triangles_index(**kwargs)
|
|
251
|
+
return eqx.tree_at(
|
|
252
|
+
lambda m: m.vertices,
|
|
253
|
+
self.mesh,
|
|
254
|
+
self.mesh.vertices.at[index, :].divide(values, **_AT_INDEXING_KWARGS),
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
def pow(
|
|
258
|
+
self,
|
|
259
|
+
values: (
|
|
260
|
+
Float[ArrayLike, "3"]
|
|
261
|
+
| Float[ArrayLike, "1"]
|
|
262
|
+
| Float[ArrayLike, ""]
|
|
263
|
+
| Sequence[float]
|
|
264
|
+
),
|
|
265
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
266
|
+
) -> _T:
|
|
267
|
+
index = self._triangles_index(**kwargs)
|
|
268
|
+
return eqx.tree_at(
|
|
269
|
+
lambda m: m.vertices,
|
|
270
|
+
self.mesh,
|
|
271
|
+
self.mesh.vertices.at[index, :].power(values, **_AT_INDEXING_KWARGS),
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
def min(
|
|
275
|
+
self,
|
|
276
|
+
values: (
|
|
277
|
+
Float[ArrayLike, "3"]
|
|
278
|
+
| Float[ArrayLike, "1"]
|
|
279
|
+
| Float[ArrayLike, ""]
|
|
280
|
+
| Sequence[float]
|
|
281
|
+
),
|
|
282
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
283
|
+
) -> _T:
|
|
284
|
+
index = self._triangles_index(**kwargs)
|
|
285
|
+
return eqx.tree_at(
|
|
286
|
+
lambda m: m.vertices,
|
|
287
|
+
self.mesh,
|
|
288
|
+
self.mesh.vertices.at[index, :].min(values, **_AT_INDEXING_KWARGS),
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
def max(
|
|
292
|
+
self,
|
|
293
|
+
values: (
|
|
294
|
+
Float[ArrayLike, "3"]
|
|
295
|
+
| Float[ArrayLike, "1"]
|
|
296
|
+
| Float[ArrayLike, ""]
|
|
297
|
+
| Sequence[float]
|
|
298
|
+
),
|
|
299
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
300
|
+
) -> _T:
|
|
301
|
+
index = self._triangles_index(**kwargs)
|
|
302
|
+
return eqx.tree_at(
|
|
303
|
+
lambda m: m.vertices,
|
|
304
|
+
self.mesh,
|
|
305
|
+
self.mesh.vertices.at[index, :].max(values, **_AT_INDEXING_KWARGS),
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
def apply(
|
|
309
|
+
self,
|
|
310
|
+
func: Callable[
|
|
311
|
+
[Float[ArrayLike, "num_indexed_triangles 3"]],
|
|
312
|
+
Float[Array, "num_indexed_triangles 3"],
|
|
313
|
+
],
|
|
314
|
+
**kwargs: Unpack[_GetIndexingKwargs],
|
|
315
|
+
) -> _T:
|
|
316
|
+
index = self._triangles_index(**kwargs)
|
|
317
|
+
return eqx.tree_at(
|
|
318
|
+
lambda m: m.vertices,
|
|
319
|
+
self.mesh,
|
|
320
|
+
self.mesh.vertices.at[index, :].apply(func, **_AT_INDEXING_KWARGS),
|
|
321
|
+
)
|
|
322
|
+
|
|
186
323
|
|
|
187
324
|
class TriangleMesh(eqx.Module):
|
|
188
325
|
"""A simple geometry made of triangles."""
|
|
@@ -509,15 +646,20 @@ class TriangleMesh(eqx.Module):
|
|
|
509
646
|
"""
|
|
510
647
|
# Using self.triangle_vertices is important because, e.g., as a result of using
|
|
511
648
|
# __getitem__, some vertices in 'self.vertices' may no longer be used by this mesh.
|
|
512
|
-
vertices = self.triangle_vertices
|
|
513
|
-
where =
|
|
649
|
+
vertices = self.triangle_vertices
|
|
650
|
+
where = self.mask[:, None] if self.mask is not None else None
|
|
514
651
|
return jnp.vstack(
|
|
515
652
|
(
|
|
516
|
-
jnp.min(vertices, axis=0, initial=+jnp.inf, where=where),
|
|
517
|
-
jnp.max(vertices, axis=0, initial=-jnp.inf, where=where),
|
|
653
|
+
jnp.min(vertices, axis=(0, 1), initial=+jnp.inf, where=where),
|
|
654
|
+
jnp.max(vertices, axis=(0, 1), initial=-jnp.inf, where=where),
|
|
518
655
|
),
|
|
519
656
|
)
|
|
520
657
|
|
|
658
|
+
if TYPE_CHECKING:
|
|
659
|
+
|
|
660
|
+
@property
|
|
661
|
+
def at(self) -> _TriangleMeshVerticesUpdateHelper[Self]: ...
|
|
662
|
+
|
|
521
663
|
@property
|
|
522
664
|
def at(self): # noqa: ANN202
|
|
523
665
|
"""
|
|
@@ -529,17 +671,25 @@ class TriangleMesh(eqx.Module):
|
|
|
529
671
|
|
|
530
672
|
In particular, the following methods are available:
|
|
531
673
|
|
|
674
|
+
- ``get(**kwargs)``: Get the vertices of selected triangles;
|
|
532
675
|
- ``set(values, **kwargs)``: Set the vertices of selected triangles to some values;
|
|
533
|
-
- ``apply(func, **kwargs)``: Apply a function to the vertices of selected triangles;
|
|
534
676
|
- ``add(values, **kwargs)``: Add some values to the vertices of selected triangles;
|
|
677
|
+
- ``sub(values, **kwargs)``: Subtract some values from the vertices of selected triangles;
|
|
535
678
|
- ``mul(values, **kwargs)``: Multiply the vertices of selected triangles by some values;
|
|
536
|
-
- ``
|
|
679
|
+
- ``div(values, **kwargs)``: Divide the vertices of selected triangles by some values;
|
|
680
|
+
- ``pow(values, **kwargs)``: Raise the vertices of selected triangles to some power;
|
|
681
|
+
- ``min(values, **kwargs)``: Take the element-wise minimum with the vertices of selected triangles;
|
|
682
|
+
- ``max(values, **kwargs)``: Take the element-wise maximum with the vertices of selected triangles;
|
|
683
|
+
- ``apply(func, **kwargs)``: Apply a function to the vertices of selected triangles.
|
|
537
684
|
|
|
538
685
|
E.g., ``mesh.at[0:2].add([1.0, 2.0, 3.0])`` will translate the first two triangles.
|
|
539
686
|
|
|
540
|
-
Each method
|
|
541
|
-
|
|
542
|
-
|
|
687
|
+
Each method accepts the same keyword arguments as the corresponding ``get`` method of
|
|
688
|
+
:attr:`jax.numpy.ndarray.at`.
|
|
689
|
+
These keyword arguments control how triangle indices are resolved internally.
|
|
690
|
+
|
|
691
|
+
Because the vertices of a triangle mesh may be shared
|
|
692
|
+
between multiple triangles, this method prevents updating the same vertex multiple times
|
|
543
693
|
by ignoring duplicate vertex indices. As a result, providing duplicate triangle indices
|
|
544
694
|
will not result in duplicate updates.
|
|
545
695
|
|
|
@@ -1574,8 +1724,8 @@ class TriangleMesh(eqx.Module):
|
|
|
1574
1724
|
if sample_objects:
|
|
1575
1725
|
indices = jnp.arange(self.num_triangles)
|
|
1576
1726
|
indices_inside_bounds = (
|
|
1577
|
-
self.object_bounds[:, 0] <= indices[:, None] # type: ignore[
|
|
1578
|
-
) & (indices[:, None] < self.object_bounds[:, 1]) # type: ignore[
|
|
1727
|
+
self.object_bounds[:, 0] <= indices[:, None] # type: ignore[ty:not-subscriptable]
|
|
1728
|
+
) & (indices[:, None] < self.object_bounds[:, 1]) # type: ignore[ty:not-subscriptable]
|
|
1579
1729
|
triangle_indices = indices_inside_bounds.argmax(
|
|
1580
1730
|
axis=1
|
|
1581
1731
|
) # Exactly one bound should be true for each triangle
|
|
@@ -1607,7 +1757,7 @@ class TriangleMesh(eqx.Module):
|
|
|
1607
1757
|
|
|
1608
1758
|
if sample_objects:
|
|
1609
1759
|
indices = jnp.concatenate([
|
|
1610
|
-
jnp.arange(self.object_bounds[i, 0], self.object_bounds[i, 1]) # type: ignore[
|
|
1760
|
+
jnp.arange(self.object_bounds[i, 0], self.object_bounds[i, 1]) # type: ignore[ty:not-subscriptable]
|
|
1611
1761
|
for i in indices
|
|
1612
1762
|
])
|
|
1613
1763
|
if self.assume_quads:
|
|
@@ -1690,7 +1840,7 @@ class TriangleMesh(eqx.Module):
|
|
|
1690
1840
|
it is discarded.
|
|
1691
1841
|
|
|
1692
1842
|
.. warning::
|
|
1693
|
-
|
|
1843
|
+
|
|
1694
1844
|
Not implemented yet.
|
|
1695
1845
|
|
|
1696
1846
|
Setting this to :data:`True` has no effect if :attr:`object_bounds`
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import typing
|
|
2
|
+
from typing import TYPE_CHECKING, Literal, no_type_check, overload
|
|
2
3
|
|
|
3
4
|
import equinox as eqx
|
|
4
5
|
import jax
|
|
@@ -450,15 +451,15 @@ def assemble_paths(
|
|
|
450
451
|
|
|
451
452
|
# NOTE: Jaxtyping does not match the correct shape for `intermediate_vertices` and will match
|
|
452
453
|
# `Float[ArrayLike, "*#batch 3"]` instead of `Float[ArrayLike, "*#batch num_inter_vertices 3"]`.
|
|
453
|
-
# This is why we
|
|
454
|
-
#
|
|
455
|
-
|
|
454
|
+
# This is why we need to disable type checking here. However, the `no_type_check` decorator also
|
|
455
|
+
# suppresses `typing.get_type_hints()`, which is used by Sphinx to extract type annotations for
|
|
456
|
+
# documentation. To work around this, we use `no_type_check` when not generating documentation.
|
|
456
457
|
def assemble_paths(
|
|
457
458
|
from_vertices: Float[ArrayLike, "*#batch 3"],
|
|
458
459
|
intermediate_vertices: Float[ArrayLike, "*#batch num_inter_vertices 3"]
|
|
459
460
|
| Float[ArrayLike, "*#batch 3"],
|
|
460
461
|
to_vertices: Float[ArrayLike, "*#batch 3"] | None = None,
|
|
461
|
-
) -> Float[Array, "*batch
|
|
462
|
+
) -> Float[Array, "*batch num_vertices+2 3"] | Float[Array, "*batch 2 3"]:
|
|
462
463
|
"""
|
|
463
464
|
Assemble paths vertices by concatenating start-, intermediate, and end-vertices.
|
|
464
465
|
|
|
@@ -507,6 +508,10 @@ def assemble_paths(
|
|
|
507
508
|
)
|
|
508
509
|
|
|
509
510
|
|
|
511
|
+
if not TYPE_CHECKING and not hasattr(typing, "GENERATING_DOCS"):
|
|
512
|
+
assemble_paths = no_type_check(assemble_paths)
|
|
513
|
+
|
|
514
|
+
|
|
510
515
|
@jax.jit
|
|
511
516
|
def min_distance_between_cells(
|
|
512
517
|
cell_vertices: Float[ArrayLike, "*batch 3"],
|
|
@@ -99,6 +99,7 @@ __all__ = (
|
|
|
99
99
|
"process_plotly_kwargs",
|
|
100
100
|
"process_vispy_kwargs",
|
|
101
101
|
"reuse",
|
|
102
|
+
"set_backend",
|
|
102
103
|
"set_defaults",
|
|
103
104
|
"update_defaults",
|
|
104
105
|
"use",
|
|
@@ -123,6 +124,7 @@ from ._utils import (
|
|
|
123
124
|
process_plotly_kwargs,
|
|
124
125
|
process_vispy_kwargs,
|
|
125
126
|
reuse,
|
|
127
|
+
set_backend,
|
|
126
128
|
set_defaults,
|
|
127
129
|
update_defaults,
|
|
128
130
|
use,
|
|
@@ -35,7 +35,7 @@ def draw_mesh(
|
|
|
35
35
|
vertices: Real[ArrayLike, "num_vertices 3"],
|
|
36
36
|
triangles: Int[ArrayLike, "num_triangles 3"],
|
|
37
37
|
**kwargs: Any,
|
|
38
|
-
) -> Canvas | MplFigure | Figure:
|
|
38
|
+
) -> Canvas | MplFigure | Figure:
|
|
39
39
|
"""
|
|
40
40
|
Plot a 3D mesh made of triangles.
|
|
41
41
|
|
|
@@ -86,6 +86,7 @@ def draw_mesh(
|
|
|
86
86
|
>>> fig # doctest: +SKIP
|
|
87
87
|
|
|
88
88
|
"""
|
|
89
|
+
raise NotImplementedError
|
|
89
90
|
|
|
90
91
|
|
|
91
92
|
@draw_mesh.register("vispy")
|
|
@@ -98,14 +99,14 @@ def _(
|
|
|
98
99
|
|
|
99
100
|
canvas, view = process_vispy_kwargs(kwargs)
|
|
100
101
|
|
|
101
|
-
if vertices.size == 0 or triangles.size == 0: # type: ignore[reportAttributeAccessIssue] # pragma: no cover
|
|
102
|
-
return canvas
|
|
103
|
-
|
|
104
102
|
kwargs.setdefault("shading", "flat")
|
|
105
103
|
|
|
106
104
|
vertices = np.asarray(vertices)
|
|
107
105
|
triangles = np.asarray(triangles)
|
|
108
106
|
|
|
107
|
+
if vertices.size == 0 or triangles.size == 0:
|
|
108
|
+
return canvas
|
|
109
|
+
|
|
109
110
|
view.add(Mesh(vertices=vertices, faces=triangles, **kwargs))
|
|
110
111
|
view.camera.set_range()
|
|
111
112
|
|
|
@@ -136,6 +137,20 @@ def _(
|
|
|
136
137
|
**kwargs: Any,
|
|
137
138
|
) -> Figure:
|
|
138
139
|
fig = process_plotly_kwargs(kwargs)
|
|
140
|
+
kwargs.setdefault("flatshading", True)
|
|
141
|
+
kwargs.setdefault(
|
|
142
|
+
"lighting",
|
|
143
|
+
{
|
|
144
|
+
"ambient": 0.5,
|
|
145
|
+
"diffuse": 0.9,
|
|
146
|
+
"fresnel": 0.1,
|
|
147
|
+
"specular": 0.9,
|
|
148
|
+
"roughness": 0.5,
|
|
149
|
+
"facenormalsepsilon": 1e-15,
|
|
150
|
+
"vertexnormalsepsilon": 1e-15,
|
|
151
|
+
},
|
|
152
|
+
)
|
|
153
|
+
kwargs.setdefault("lightposition", {"x": 100000, "y": 100000, "z": 100000})
|
|
139
154
|
|
|
140
155
|
if (
|
|
141
156
|
face_colors := kwargs.pop("face_colors", None)
|
|
@@ -152,7 +167,7 @@ def _(
|
|
|
152
167
|
def draw_paths(
|
|
153
168
|
paths: Real[ArrayLike, "*batch path_length 3"],
|
|
154
169
|
**kwargs: Any,
|
|
155
|
-
) -> Canvas | MplFigure | Figure:
|
|
170
|
+
) -> Canvas | MplFigure | Figure:
|
|
156
171
|
"""
|
|
157
172
|
Plot a batch of paths of the same length.
|
|
158
173
|
|
|
@@ -194,6 +209,7 @@ def draw_paths(
|
|
|
194
209
|
... )
|
|
195
210
|
>>> fig # doctest: +SKIP
|
|
196
211
|
"""
|
|
212
|
+
raise NotImplementedError
|
|
197
213
|
|
|
198
214
|
|
|
199
215
|
@draw_paths.register("vispy")
|
|
@@ -262,7 +278,7 @@ def draw_rays(
|
|
|
262
278
|
*,
|
|
263
279
|
ratio: Float[ArrayLike, ""] = 0.1,
|
|
264
280
|
**kwargs: Any,
|
|
265
|
-
) -> Canvas | MplFigure | Figure:
|
|
281
|
+
) -> Canvas | MplFigure | Figure:
|
|
266
282
|
"""
|
|
267
283
|
Plot a batch of rays.
|
|
268
284
|
|
|
@@ -344,6 +360,7 @@ def draw_rays(
|
|
|
344
360
|
... )
|
|
345
361
|
>>> fig # doctest: +SKIP
|
|
346
362
|
"""
|
|
363
|
+
raise NotImplementedError
|
|
347
364
|
|
|
348
365
|
|
|
349
366
|
@draw_rays.register("vispy")
|
|
@@ -358,14 +375,14 @@ def _(
|
|
|
358
375
|
|
|
359
376
|
canvas, view = process_vispy_kwargs(kwargs)
|
|
360
377
|
|
|
361
|
-
if ray_origins.size == 0 or ray_directions.size == 0: # type: ignore[reportAttributeAccessIssue] # pragma: no cover
|
|
362
|
-
return canvas
|
|
363
|
-
|
|
364
378
|
kwargs.setdefault("width", 3.0)
|
|
365
379
|
kwargs.setdefault("arrow_size", 6.0)
|
|
366
380
|
|
|
367
381
|
ray_origins = np.asarray(ray_origins).reshape(-1, 3)
|
|
368
382
|
ray_directions = np.asarray(ray_directions).reshape(-1, 3)
|
|
383
|
+
|
|
384
|
+
if ray_origins.size == 0 or ray_directions.size == 0:
|
|
385
|
+
return canvas
|
|
369
386
|
ratio = np.asarray(ratio)
|
|
370
387
|
body_ends = ray_origins + (1 - ratio) * ray_directions
|
|
371
388
|
|
|
@@ -393,7 +410,7 @@ def _(
|
|
|
393
410
|
) -> MplFigure:
|
|
394
411
|
fig, ax = process_matplotlib_kwargs(kwargs)
|
|
395
412
|
|
|
396
|
-
kwargs.setdefault("arrow_length_ratio", float(ratio))
|
|
413
|
+
kwargs.setdefault("arrow_length_ratio", float(np.asarray(ratio)))
|
|
397
414
|
|
|
398
415
|
ray_origins = np.asarray(ray_origins).reshape(-1, 3)
|
|
399
416
|
ray_directions = np.asarray(ray_directions).reshape(-1, 3)
|
|
@@ -466,7 +483,7 @@ def draw_markers(
|
|
|
466
483
|
labels: Sequence[str] | None = None,
|
|
467
484
|
text_kwargs: Mapping[str, Any] | None = None,
|
|
468
485
|
**kwargs: Any,
|
|
469
|
-
) -> Canvas | MplFigure | Figure:
|
|
486
|
+
) -> Canvas | MplFigure | Figure:
|
|
470
487
|
"""
|
|
471
488
|
Plot markers and, optionally, their label.
|
|
472
489
|
|
|
@@ -507,6 +524,7 @@ def draw_markers(
|
|
|
507
524
|
>>> fig = draw_markers(markers, labels, backend="plotly")
|
|
508
525
|
>>> fig # doctest: +SKIP
|
|
509
526
|
"""
|
|
527
|
+
raise NotImplementedError
|
|
510
528
|
|
|
511
529
|
|
|
512
530
|
@draw_markers.register("vispy")
|
|
@@ -520,13 +538,16 @@ def _(
|
|
|
520
538
|
|
|
521
539
|
canvas, view = process_vispy_kwargs(kwargs)
|
|
522
540
|
|
|
523
|
-
if markers.size == 0: # type: ignore[reportAttributeAccessIssue] # pragma: no cover
|
|
524
|
-
return canvas
|
|
525
|
-
|
|
526
541
|
kwargs.setdefault("size", 1)
|
|
527
542
|
kwargs.setdefault("edge_width_rel", 0.05)
|
|
528
543
|
kwargs.setdefault("scaling", "scene")
|
|
529
|
-
markers = np.asarray(markers)
|
|
544
|
+
markers = np.asarray(markers)
|
|
545
|
+
|
|
546
|
+
if markers.size == 0:
|
|
547
|
+
return canvas
|
|
548
|
+
|
|
549
|
+
markers = markers.reshape(-1, 3)
|
|
550
|
+
|
|
530
551
|
view.add(Markers(pos=markers, **kwargs))
|
|
531
552
|
|
|
532
553
|
if labels:
|
|
@@ -599,7 +620,7 @@ def draw_image(
|
|
|
599
620
|
y: Real[ArrayLike, " rows"] | Real[ArrayLike, "rows cols 3"] | None = None,
|
|
600
621
|
z0: float = 0.0,
|
|
601
622
|
**kwargs: Any,
|
|
602
|
-
) -> Canvas | MplFigure | Figure:
|
|
623
|
+
) -> Canvas | MplFigure | Figure:
|
|
603
624
|
"""
|
|
604
625
|
Plot a 2D image on a 3D canvas, at a fixed z-coordinate.
|
|
605
626
|
|
|
@@ -650,6 +671,7 @@ def draw_image(
|
|
|
650
671
|
>>> fig2 # doctest: +SKIP
|
|
651
672
|
|
|
652
673
|
"""
|
|
674
|
+
raise NotImplementedError
|
|
653
675
|
|
|
654
676
|
|
|
655
677
|
@draw_image.register("vispy")
|
|
@@ -758,7 +780,7 @@ def draw_contour(
|
|
|
758
780
|
levels: int | Real[ArrayLike, " num_levels"] | None = None,
|
|
759
781
|
fill: bool = False,
|
|
760
782
|
**kwargs: Any,
|
|
761
|
-
) -> Canvas | MplFigure | Figure:
|
|
783
|
+
) -> Canvas | MplFigure | Figure:
|
|
762
784
|
"""
|
|
763
785
|
Plot a 2D contour on a 3D canvas, at a fixed z-coordinate.
|
|
764
786
|
|
|
@@ -809,6 +831,7 @@ def draw_contour(
|
|
|
809
831
|
>>> fig2 # doctest: +SKIP
|
|
810
832
|
|
|
811
833
|
"""
|
|
834
|
+
raise NotImplementedError
|
|
812
835
|
|
|
813
836
|
|
|
814
837
|
@draw_contour.register("vispy")
|
|
@@ -895,7 +918,7 @@ def _(
|
|
|
895
918
|
|
|
896
919
|
y = np.arange(m) if y is None else np.asarray(y)
|
|
897
920
|
|
|
898
|
-
if not
|
|
921
|
+
if levels is not None and not np.isscalar(levels):
|
|
899
922
|
levels = np.asarray(levels)
|
|
900
923
|
|
|
901
924
|
if fill:
|
|
@@ -926,7 +949,7 @@ def _(
|
|
|
926
949
|
if isinstance(levels, int):
|
|
927
950
|
kwargs.setdefault("autocontour", True)
|
|
928
951
|
kwargs.setdefault("ncontours", levels)
|
|
929
|
-
elif
|
|
952
|
+
elif levels is not None and not np.isscalar(levels):
|
|
930
953
|
levels = np.asarray(levels)
|
|
931
954
|
msg = (
|
|
932
955
|
"Plotly does not support arbitrary level values, but only linearly spaced levels. "
|
|
@@ -959,7 +982,7 @@ def draw_surface(
|
|
|
959
982
|
z: Real[ArrayLike, "rows cols"],
|
|
960
983
|
colors: Real[ArrayLike, "rows cols"] | Real[ArrayLike, "rows cols 3"] | None = None,
|
|
961
984
|
**kwargs: Any,
|
|
962
|
-
) -> Canvas | MplFigure | Figure:
|
|
985
|
+
) -> Canvas | MplFigure | Figure:
|
|
963
986
|
"""
|
|
964
987
|
Plot a 3D surface.
|
|
965
988
|
|
|
@@ -1009,6 +1032,7 @@ def draw_surface(
|
|
|
1009
1032
|
>>> fig2 # doctest: +SKIP
|
|
1010
1033
|
|
|
1011
1034
|
"""
|
|
1035
|
+
raise NotImplementedError
|
|
1012
1036
|
|
|
1013
1037
|
|
|
1014
1038
|
@draw_surface.register("vispy")
|
|
@@ -14,6 +14,7 @@ from typing import (
|
|
|
14
14
|
ParamSpec,
|
|
15
15
|
Protocol,
|
|
16
16
|
TypeVar,
|
|
17
|
+
cast,
|
|
17
18
|
get_args,
|
|
18
19
|
no_type_check,
|
|
19
20
|
runtime_checkable,
|
|
@@ -76,7 +77,7 @@ config = _Config()
|
|
|
76
77
|
"""Mutable config object with mutability of default values guarded by a lock."""
|
|
77
78
|
|
|
78
79
|
|
|
79
|
-
def get_backend(backend:
|
|
80
|
+
def get_backend(backend: str | None = None) -> BackendName:
|
|
80
81
|
"""
|
|
81
82
|
Return the name of the backend to use.
|
|
82
83
|
|
|
@@ -113,10 +114,11 @@ def get_backend(backend: LiteralString | None = None) -> BackendName:
|
|
|
113
114
|
if importlib.util.find_spec(backend) is None:
|
|
114
115
|
msg = f"Could not find backend '{backend}', did you install it?"
|
|
115
116
|
raise ImportError(msg)
|
|
116
|
-
|
|
117
|
+
|
|
118
|
+
return cast("BackendName", backend)
|
|
117
119
|
|
|
118
120
|
|
|
119
|
-
def set_defaults(backend:
|
|
121
|
+
def set_defaults(backend: str | None = None, **kwargs: Any) -> BackendName:
|
|
120
122
|
"""
|
|
121
123
|
Set default backend and keyword arguments for future plotting utilities.
|
|
122
124
|
|
|
@@ -184,7 +186,30 @@ def set_defaults(backend: LiteralString | None = None, **kwargs: Any) -> Backend
|
|
|
184
186
|
return backend
|
|
185
187
|
|
|
186
188
|
|
|
187
|
-
def
|
|
189
|
+
def set_backend(backend: str) -> None:
|
|
190
|
+
"""
|
|
191
|
+
Set default backend for future plotting utilities.
|
|
192
|
+
|
|
193
|
+
Args:
|
|
194
|
+
backend: The name of the backend to be passed to
|
|
195
|
+
:func:`get_backend`.
|
|
196
|
+
|
|
197
|
+
Examples:
|
|
198
|
+
The following example shows how to set the default plotting backend.
|
|
199
|
+
|
|
200
|
+
>>> import differt.plotting as dplt
|
|
201
|
+
>>>
|
|
202
|
+
>>> dplt.set_backend("matplotlib") # We can change the default backend
|
|
203
|
+
>>> dplt.get_backend() # So that now it defaults to 'matplotlib'
|
|
204
|
+
'matplotlib'
|
|
205
|
+
>>> dplt.set_backend("vispy") # Reset to 'vispy'
|
|
206
|
+
>>> dplt.get_backend()
|
|
207
|
+
'vispy'
|
|
208
|
+
"""
|
|
209
|
+
set_defaults(backend=backend)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def update_defaults(backend: str | None = None, **kwargs: Any) -> BackendName:
|
|
188
213
|
"""
|
|
189
214
|
Update default backend and keyword arguments for future plotting utilities.
|
|
190
215
|
|
|
@@ -209,7 +234,7 @@ def update_defaults(backend: LiteralString | None = None, **kwargs: Any) -> Back
|
|
|
209
234
|
|
|
210
235
|
|
|
211
236
|
@contextmanager
|
|
212
|
-
def use(backend:
|
|
237
|
+
def use(backend: str | None = None, **kwargs: Any) -> Iterator[BackendName]:
|
|
213
238
|
"""
|
|
214
239
|
Create a context manager that updates plotting defaults and returns the current default backend.
|
|
215
240
|
|
|
@@ -265,10 +290,7 @@ def use(backend: LiteralString | None = None, **kwargs: Any) -> Iterator[Backend
|
|
|
265
290
|
kwargs = {**config.defaults.kwargs, **kwargs}
|
|
266
291
|
|
|
267
292
|
with config.with_defaults(backend=backend, kwargs=kwargs):
|
|
268
|
-
|
|
269
|
-
yield backend
|
|
270
|
-
finally:
|
|
271
|
-
pass
|
|
293
|
+
yield backend
|
|
272
294
|
|
|
273
295
|
|
|
274
296
|
@runtime_checkable
|
|
@@ -282,11 +304,11 @@ class _Dispatcher(Protocol[P, T]):
|
|
|
282
304
|
) -> T: ...
|
|
283
305
|
def register(
|
|
284
306
|
self,
|
|
285
|
-
backend:
|
|
307
|
+
backend: str,
|
|
286
308
|
) -> Callable[[Callable[P, T]], Callable[P, T]]: ...
|
|
287
309
|
|
|
288
310
|
|
|
289
|
-
def dispatch(fun: Callable[P,
|
|
311
|
+
def dispatch(fun: Callable[P, T]) -> _Dispatcher[P, T]:
|
|
290
312
|
"""
|
|
291
313
|
Transform a function into a backend dispatcher for plot functions.
|
|
292
314
|
|
|
@@ -353,10 +375,10 @@ def dispatch(fun: Callable[P, PlotOutput]) -> _Dispatcher[P, T]:
|
|
|
353
375
|
Traceback (most recent call last):
|
|
354
376
|
ValueError: Unsupported backend 'numpy', allowed values are: ...
|
|
355
377
|
"""
|
|
356
|
-
registry: dict[str, Callable[P,
|
|
378
|
+
registry: dict[str, Callable[P, T]] = {}
|
|
357
379
|
|
|
358
380
|
def register(
|
|
359
|
-
backend:
|
|
381
|
+
backend: str,
|
|
360
382
|
) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
|
361
383
|
"""
|
|
362
384
|
Return a wrapper that will call the decorated function for the specified backend.
|
|
@@ -411,37 +433,26 @@ def dispatch(fun: Callable[P, PlotOutput]) -> _Dispatcher[P, T]:
|
|
|
411
433
|
*args: P.args,
|
|
412
434
|
**kwargs: P.kwargs,
|
|
413
435
|
) -> T:
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
Returns:
|
|
422
|
-
The result of the call.
|
|
423
|
-
"""
|
|
424
|
-
# We cannot currently add keyword argument to the signature,
|
|
425
|
-
# at least Pyright will not allow that,
|
|
426
|
-
# see: https://github.com/microsoft/pyright/issues/5844.
|
|
427
|
-
#
|
|
428
|
-
# The motivation is detailed in P612:
|
|
429
|
-
# https://peps.python.org/pep-0612/#concatenating-keyword-parameters.
|
|
430
|
-
backend_opt: LiteralString | None = kwargs.pop("backend", None) # type: ignore[reportArgumentType]
|
|
436
|
+
# We cannot add keyword argument to the signature, because ParamSpec does not
|
|
437
|
+
# allow parameters between
|
|
438
|
+
# *args: P.args and **kwargs: P.kwargs.
|
|
439
|
+
backend_opt = kwargs.pop("backend", None)
|
|
440
|
+
if backend_opt is not None and not isinstance(backend_opt, str):
|
|
441
|
+
msg = "Argument 'backend' must be a string."
|
|
442
|
+
raise TypeError(msg)
|
|
431
443
|
backend = get_backend(backend_opt)
|
|
432
444
|
|
|
433
445
|
try:
|
|
434
|
-
return registry[backend](*args, **kwargs)
|
|
446
|
+
return registry[backend](*args, **kwargs)
|
|
435
447
|
except KeyError:
|
|
436
448
|
msg = f"No backend implementation for '{backend}'"
|
|
437
449
|
raise NotImplementedError(
|
|
438
450
|
msg,
|
|
439
451
|
) from None
|
|
440
452
|
|
|
441
|
-
wrapper.register = register # type: ignore[
|
|
442
|
-
wrapper.registry = types.MappingProxyType(registry) # type: ignore[
|
|
443
|
-
|
|
444
|
-
return wrapper # type: ignore[reportReportType]
|
|
453
|
+
wrapper.register = register # type: ignore[ty:unresolved-attribute]
|
|
454
|
+
wrapper.registry = types.MappingProxyType(registry) # type: ignore[ty:unresolved-attribute]
|
|
455
|
+
return wrapper # type: ignore[ty:invalid-return-type]
|
|
445
456
|
|
|
446
457
|
|
|
447
458
|
def view_from_canvas(canvas: Canvas) -> ViewBox:
|
|
@@ -459,11 +470,12 @@ def view_from_canvas(canvas: Canvas) -> ViewBox:
|
|
|
459
470
|
Returns:
|
|
460
471
|
The view on which contents are displayed.
|
|
461
472
|
"""
|
|
473
|
+
from vispy.scene.cameras.turntable import TurntableCamera # noqa: PLC0415
|
|
462
474
|
from vispy.scene.widgets.viewbox import ViewBox # noqa: PLC0415
|
|
463
475
|
|
|
464
476
|
def default_view() -> ViewBox:
|
|
465
477
|
view = canvas.central_widget.add_view()
|
|
466
|
-
view.camera =
|
|
478
|
+
view.camera = TurntableCamera()
|
|
467
479
|
view.camera.depth_value = 1e3
|
|
468
480
|
return view
|
|
469
481
|
|
|
@@ -612,7 +624,9 @@ def process_plotly_kwargs(
|
|
|
612
624
|
for key, value in config.defaults.kwargs.items():
|
|
613
625
|
kwargs.setdefault(key, value)
|
|
614
626
|
|
|
615
|
-
|
|
627
|
+
fig = kwargs.pop("figure", None) or go.Figure()
|
|
628
|
+
fig.update_scenes(aspectmode="data")
|
|
629
|
+
return fig
|
|
616
630
|
|
|
617
631
|
|
|
618
632
|
def process_kwargs(
|
|
@@ -704,7 +718,4 @@ def reuse(
|
|
|
704
718
|
with config.with_defaults(
|
|
705
719
|
backend=backend, kwargs={**config.defaults.kwargs, **kwargs}
|
|
706
720
|
):
|
|
707
|
-
|
|
708
|
-
yield canvas_or_fig
|
|
709
|
-
finally:
|
|
710
|
-
pass
|
|
721
|
+
yield canvas_or_fig
|
|
@@ -4,7 +4,7 @@ __all__ = ("DeepMIMO", "export")
|
|
|
4
4
|
|
|
5
5
|
from collections.abc import Iterable, Iterator, Mapping
|
|
6
6
|
from dataclasses import KW_ONLY, asdict
|
|
7
|
-
from typing import Any, Generic, Literal, TypeGuard
|
|
7
|
+
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeGuard
|
|
8
8
|
|
|
9
9
|
import equinox as eqx
|
|
10
10
|
import jax
|
|
@@ -33,6 +33,16 @@ from differt.utils import safe_divide
|
|
|
33
33
|
|
|
34
34
|
from ._deepmimo_types import ArrayType
|
|
35
35
|
|
|
36
|
+
if TYPE_CHECKING:
|
|
37
|
+
try:
|
|
38
|
+
import sionna.rt
|
|
39
|
+
except ImportError:
|
|
40
|
+
SionnaPaths = Any
|
|
41
|
+
else:
|
|
42
|
+
SionnaPaths = sionna.rt.Paths
|
|
43
|
+
else:
|
|
44
|
+
SionnaPaths = Any
|
|
45
|
+
|
|
36
46
|
|
|
37
47
|
def _pad_and_concat(
|
|
38
48
|
left: Shaped[Array, "num_tx num_rx num_paths_left num_interactions_left ..."],
|
|
@@ -146,7 +156,7 @@ class DeepMIMO(eqx.Module, Generic[ArrayType]):
|
|
|
146
156
|
|
|
147
157
|
def _sort(
|
|
148
158
|
self,
|
|
149
|
-
paths:
|
|
159
|
+
paths: SionnaPaths,
|
|
150
160
|
) -> "DeepMIMO[Array]":
|
|
151
161
|
"""Utility function to sort the DeepMIMO based on :class:`sionna.rt.Paths`' vertices.""" # noqa: DOC201, DOC501
|
|
152
162
|
if _is_jax_dtype(self):
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any
|
|
1
|
+
from typing import Any, no_type_check
|
|
2
2
|
|
|
3
3
|
import equinox as eqx
|
|
4
4
|
import fpt_jax
|
|
@@ -169,17 +169,21 @@ def fermat_path_on_linear_objects(
|
|
|
169
169
|
return jnp.broadcast_to(object_origins, (*batch, num_objects, 3)).astype(dtype)
|
|
170
170
|
|
|
171
171
|
# Needed until https://github.com/jax-ml/jax/issues/34697 is resolved
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
172
|
+
@no_type_check
|
|
173
|
+
def _call_fpt_jax() -> Array:
|
|
174
|
+
return fpt_jax.trace_rays(
|
|
175
|
+
from_vertices,
|
|
176
|
+
to_vertices,
|
|
177
|
+
object_origins,
|
|
178
|
+
object_vectors,
|
|
179
|
+
num_iters=steps,
|
|
180
|
+
unroll=unroll,
|
|
181
|
+
num_iters_linesearch=linesearch_steps,
|
|
182
|
+
unroll_linesearch=unroll_linesearch,
|
|
183
|
+
implicit_diff=implicit_diff,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
return _call_fpt_jax()
|
|
183
187
|
|
|
184
188
|
|
|
185
189
|
@eqx.filter_jit
|
|
@@ -2,7 +2,7 @@ import math
|
|
|
2
2
|
import typing
|
|
3
3
|
import warnings
|
|
4
4
|
from collections.abc import Iterator, Mapping
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Literal, overload
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Literal, cast, overload
|
|
6
6
|
|
|
7
7
|
import equinox as eqx
|
|
8
8
|
import jax
|
|
@@ -1270,15 +1270,18 @@ class TriangleScene(eqx.Module):
|
|
|
1270
1270
|
to = from_ + 1
|
|
1271
1271
|
|
|
1272
1272
|
if chunk_size:
|
|
1273
|
+
# Type checker not able to infer that order is not None in this branch, even with the previous checks, so we need to cast it
|
|
1274
|
+
order = cast("int", order)
|
|
1275
|
+
|
|
1273
1276
|
path_candidates_iter = graph.all_paths_array_chunks(
|
|
1274
1277
|
from_=from_,
|
|
1275
1278
|
to=to,
|
|
1276
|
-
depth=order + 2,
|
|
1279
|
+
depth=order + 2,
|
|
1277
1280
|
include_from_and_to=False,
|
|
1278
1281
|
chunk_size=chunk_size,
|
|
1279
1282
|
)
|
|
1280
1283
|
it = (
|
|
1281
|
-
_compute_paths( # type: ignore[no-matching-overload]
|
|
1284
|
+
_compute_paths( # type: ignore[ty:no-matching-overload]
|
|
1282
1285
|
self.mesh,
|
|
1283
1286
|
tx_vertices,
|
|
1284
1287
|
rx_vertices,
|
|
@@ -1301,11 +1304,13 @@ class TriangleScene(eqx.Module):
|
|
|
1301
1304
|
return it
|
|
1302
1305
|
|
|
1303
1306
|
if path_candidates is None:
|
|
1307
|
+
# Type checker not able to infer that order is not None in this branch, even with the previous checks, so we need to cast it
|
|
1308
|
+
order = cast("int", order)
|
|
1304
1309
|
path_candidates = jnp.asarray(
|
|
1305
1310
|
graph.all_paths_array(
|
|
1306
1311
|
from_=from_,
|
|
1307
1312
|
to=to,
|
|
1308
|
-
depth=order + 2, #
|
|
1313
|
+
depth=order + 2, # order not narrowed in this branch
|
|
1309
1314
|
include_from_and_to=False,
|
|
1310
1315
|
),
|
|
1311
1316
|
dtype=int,
|
|
@@ -1318,7 +1323,7 @@ class TriangleScene(eqx.Module):
|
|
|
1318
1323
|
if self.mesh.assume_quads:
|
|
1319
1324
|
path_candidates -= path_candidates % 2
|
|
1320
1325
|
|
|
1321
|
-
return _compute_paths( # type: ignore[no-matching-overload]
|
|
1326
|
+
return _compute_paths( # type: ignore[ty:no-matching-overload]
|
|
1322
1327
|
self.mesh,
|
|
1323
1328
|
tx_vertices,
|
|
1324
1329
|
rx_vertices,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|