-
Notifications
You must be signed in to change notification settings - Fork 4
Use return annotation to wrap tensors into ndarrays/sequences of ndarrays #83
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
Conversation
Base is tracked via `self._tensor._base`. Use `a.get()._base is b.get()` instead of numpy's `a.base is b`.
…nd import from _detail
…eturn a value On failure, @ normalizer without arguments (default) raises, while @Normalizer(return_or_failure=value) return a specified `value`. This is useful, e.g. for @-normalizer def is_scalar(a: ArrayLike): .... Consider is_scalar(int): the argument cannot be converted to tensor, so the function returns False. But the actual failure is in the decorator, so cannot do try-except in the body of the function!
Two cases - just {tuple, list}[NDArrays] (list is e.g. meshgrid) - a variadic return of a single NDArray or a list/tuple (where, atleast_{1,2,3}d, unique) Note that in the latter case the choice of the return type depends purely on the number of input array_likes.
`_helpers.tuple_arrays_from` is now localized to the normalizer only
Optional arguments to the normalizer decorator turn out to be useful for quantile/percentile, which does non-standard things allowing zero-dim out arrays for size-out outputs etc.
2fe8a9a
to
35e647b
Compare
35e647b
to
bc9bd0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Numpy returns either a Tensor, or a list / tuple or Arrays. Now, why do we need the annotations if this information is readily available in the type of result
after executing the function? I think we should be able to post process everything simply based on that.
|
||
postprocessors = { | ||
NDArray: postprocess_ndarray, | ||
OutArray: postprocess_out, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I think we should be able to implement the out=
keyword generically. Let's catch-up on this today.
78b64c6
to
5fea60f
Compare
Annotate return values of wrapper functions to trigger generic postprocessing. No annotation mean no postprocessing of scalar returns;
-> NDArray
triggersndarray(tensor)
etc. There's again a need for a special annotation for functions which return either an array or a sequence of arrays (atleast_1d
,where
,unique
). Other than that, all looks straightforward.on top of gh-82, so it's the top of the stack based off gh-70.
NB: postprocessing currently invokes functions from
_helpers
. Those are straighforward to clean up/inline, once the rest of the "stack" is in.