Typing (type hinting) in Haiku?
See original GitHub issueHey all!
I like using mypy as a smell test for my code and I was wondering if Haiku (and to a larger extent, Jax) has (well supported) built in typing? I tried doing
import jax.np as jnp
type(jnp.ones([3]))
I found Type Hints but it seems to only be a subset of supported ops. Does the team have any recommendations?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Type hints cheat sheet - mypy 0.991 documentation
Type hints cheat sheet#. This document is a quick cheat sheet showing how to use type annotations for various common types in Python....
Read more >dm-haiku/transform.py at main - GitHub
import types. from typing import Any, Callable, List, Mapping, NamedTuple, Optional, Tuple, TypeVar, Union. from haiku._src import analytics. from haiku.
Read more >PEP 484 – Type Hints - Python Enhancement Proposals
This PEP aims to provide a standard syntax for type annotations, opening up Python code to easier static analysis and refactoring, potential runtime...
Read more >What are the best practices in using Python type hinting? (e.g. ...
Originally Answered: What is the strongest argument against statically typed programming languages? I am strongly pro-static typing. If I were tasked to build ......
Read more >Python type hinting: how to tell X is a subclass for Foo?
According to PEP 484 (about Type Hints), there exists a hint for type of class objects, called Type[C]. And according to typing module's ......
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 Free
Top 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
We tend to use aliases internally. There is a mixture of people aliasing
jnp.ndarray
andchex.Array
.I know that JAX team have plans to make rng keys a distinct type (
PRNGKeyArray
) which is a super common thing users want to type hint (currentlyjax.random.PRNGKey
is a function not a type).I am not aware of a good way to type a function that accepts a PyTree of arrays in a way that will actually make the type checker do something useful.
You could look at https://github.com/deepmind/tensor_annotations if you want a more complete type annotation (e.g. with rank and axis names). The JAX team also have some thoughts on import time type checking in JAX. So far we have not adopted any of these solutions in our libraries, there is definitely some energy from users to improve the state of typing in JAX libraries, however for now there is not a canonical solution that pleases most.