-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Please consider adding a NumpySlice type annotation, and exposing Shape, ShapeLike #16657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you elaborate on your use case for NumpySlice? For the most part, I would imagine that makes sense to use more specific types, rather than "everything supported by NumPy's indexing"
These are private and internal :).
|
Here's where I'm currently using slice: I use this method: def _col_slice(i: SliceLike) -> SliceLike:
return (slice(None), *i) here: xs = np.linspace(0.0, self.iterations * self.time_step, self.iterations, endpoint=False)
all_ys = np.asarray(getattr(self.trajectory, name))
for i in np.ndindex(all_ys.shape[1:]): # The first index of the trajectory is the time index. Draw one graph line for each combination of index values over the other indices.
ys = all_ys[self._col_slice(i)] # Slice out the data for this graph line.
axis.plot(xs, ys, label=str(i)) Here's another place: def index_into_component(
self,
component_index: int,
slice_into_matched_signals: SliceLike) -> SliceLike:
"""
Args:
component_index: The index of the component signals.
slice_into_matched_signals: A slice into the matched signals.
Returns:
The slice corresponding to “slice_into_matched_signals” into signals for component
“component_index”.
"""
assert (len(slice_into_matched_signals)
== len(self._matched_signal_shape))
retval = []
for s_i, ic_i in zip(self._non_integer_indices(component_index),
slice_into_matched_signals):
if s_i == np.newaxis:
continue
assert s_i == slice(None)
retval.append(ic_i)
return tuple(retval) As for def sum_tensors(tensors: Collection[Tensor],
shape: Optional[ShapeLike] = None) -> Tensor:
if not tensors:
return jnp.zeros(shape)
return reduce(add, tensors) |
While I can definitely see its usefulness, I feel that exposing such an annotation to the public namespace would be premature. |
@BvB93 Okay, that makes sense. Are typed |
As for as I'm aware there are no concrete plans yet for when proper dtype support will be implemented. |
Thank you, I will do that. |
My goal is yes. Part of the reason for merging the stubs early in the 1.20 release cycle was to get it ironed out. |
No promises, but I think I should have updates on this in the weeks time scale. |
That is awesome!! |
Uh oh!
There was an error while loading. Please reload this page.
I often use something like this:
but I guess this is more general?
Also, why aren't
_Shape
and_ShapeLike
exposed asShape
andShapeLike
? It would be nice to use those and the leading underscore makes them seem private and internal.The text was updated successfully, but these errors were encountered: