Type signatures for standardized functions
See original GitHub issueI think standardized functions should include signatures that are at least in principle compatible with static type checking tools such as mypy, ideally treating dtype and shape as an implicit part of array types. This would eventually allow for static checking of code using these array APIs, which would using these APIs much safer.
This would entail standardizing a number of implementation details beyond those in the current draft specs, e.g.,
- Python types: this is very basic, but we should specify exactly which Python types are valid for various arguments, e.g.,
axis
must use a Pythonint
ortuple[int, ...]
. - array types: are operations on an array of some type required to return an array of the same type? Or merely another array (of any type) that also satisfies the standard array API (whatever we eventually define that to be)?
- array shapes: do we require implementing the full version of NumPy broadcasting? Or do we define behavior in simpler cases, e.g., where all shapes match? It might also make sense to only require a more explicit subset of broadcasting behavior, without automatic rank promotion.
- array dtypes: do we include dtype promotion like what NumPy uses? Or do we only define operations on a predefined set of “safe” dtypes, e.g.,
add(float64, float64) -> float64
? One argument against codifying dtype promotion is that the details of dtype promotion are rather tricky, and NumPy’s rules are unsuitable for accelerators (JAX and PyTorch implement incompatible semantics). On the other hand, requiring explicit dtype casting (like in TensorFlow) is rather annoying for users (maybe less of a problem for library code).
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:20 (20 by maintainers)
Top Results From Across the Web
Type signature - Wikipedia
A type signature includes the number, types, and order of the arguments contained by a function.
Read more >Function Type Signatures in Javascript - HackerNoon
Type Signatures are based on Hindley-Milner Type system as a standard type system which is also followed by ML-influenced languages, including ...
Read more >Signature (functions) - MDN Web Docs Glossary: Definitions of ...
A function signature (or type signature, or method signature) defines input and output of functions or methods. A signature can include:.
Read more >Function type signatures | Flux 0.x Documentation
Use type signatures to identify data types expected by function parameters and to understand a function's expected output. Function type signature structure.
Read more >Typyfying function signatures - Question - Scala Users
Is there a way to give function signatures a type with a name? ... Above solution has the advantage over standard functions (i.e....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
actually no, I’m not sure that’s 100% correct. I think the static typing in https://github.com/data-apis/array-api/issues/13#issuecomment-668903281 is useful for array libraries that are happy to do coercion to their own internal array type (numpy would do that), and the right thing to do for consumer libraries that want to support multiple array types. But array libraries should also be free to do:
rather than typing everything as an
Array
Protocol.I think it’s totally reasonable to say that we’ll copy NumPy for broadcasting. There are other ways to catch broadcasting errors (e.g., type checking, at least in principle).