-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support value promotion (implicit Constant
)
#25
Comments
A considerable fraction of this use case overlaps with operator overloading. It is also important to remember that this only applies to An important difference with respect to operator overloading is that constructor functions of the |
I would be happy with a non-coercing implementation of this for a start, if only a nice type hint were possible. |
Maybe this sphinx feature fits the bill? It seems to be used in other projects for this very purpose. E.g. https://github.com/google/jax/blob/main/docs/conf.py#L293-L297 |
Indeed I think we can fix this in Sphinx - it would also be nice to find something for IDEs/checkers, although: I think I would like to avoid impairing user experience but making our signatures almost unreadable if they don't have the right IDE. The two main workarounds I had in mind don't (really) work - NewType doesn't work on Union types (since you can't subclass from them), and TypeVar would require having a separate one for every argument there (and it would also not work for variadics). I'll try and look into this further as it would also fix the existing issue of messy |
This is a feature idea that comes up in alternative libraries. It would be useful to be able to express things like
op.add(x, 1)
or evenop.reshape(x, [-1, 2])
without the need for excess baggage likeop.const
or evenop.constant
.This raises the following questions:
Constant
operator or something else?npt.ArrayLike
(everythingnumpy
takes),npt.NDArray
/np.number
(explicit typing only), or maybe just Python types?op.add(x, 1)
, should1
just becomeint64
, or be coerced to whateverx
is? Shouldop.add(x, 1.0)
have1.0
befloat32
orfloat64
(related: Should spox.opset.ai.onnx.vXX.const default to float64 for float input? #24). It is technically possible to implement the coercion with schema info in most cases.I think it's useful to think about these as value promotion could be important for usability long-term.
The text was updated successfully, but these errors were encountered: