question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type signatures for standardized functions

See original GitHub issue

I 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 Python int or tuple[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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
rgommerscommented, Aug 5, 2020

So I want the same static typing (whatever is returned is an array type that adheres to the spec)

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:

def arange(x: myTensor) ->  myTensor:
    ...

rather than typing everything as an Array Protocol.

2reactions
shoyercommented, Aug 4, 2020

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found