-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
This issue proposes to replace funsor Domain objects with new subscripted types a la Python 3's typing module.
The goal is to make Funsor more Pythonic and to make funsors act more like Python functions (but with support for pointwise operations). In particular many of our design questions about multiple inputs or outputs could be resolved by "following Python". A simple example of more-Pythonic syntax is:
# decorator syntax to read .inputs and .outputs from a type annotation
@to_funsor
def f(x: Real[3], y: Real[3,3], t: Real) -> Real:
...
# explicitly specify type as Callable[..., ...]
g = to_funsor(lambda x: x.sum(), Callable[[Real[3]], Real)
...
h = f + g # materialized view of lambda x, y, t: f(x, y, t) + g(x)Interface
Because the Python 3 typing library is moving and not natively inspectable, we should implement a minimal interface for inspection:
- Refactor domains to be types #352 creating domain types,
Bint[n],Reals[m,n] - Refactor domains to be types #352
isinstance(-, Domain)(withDomain = type) - Refactor domains to be types #352
issubclass(-, -)(by overriding__subclasscheck__) - Add minimal type annotation support to funsors #354
typing.get_type_hints()for funsors -
typing.get_origin() -
typing.get_args()
Tasks
- Refactor domains to be types #352 Refactor domains to be typing-compatible type objects:
Bint[n],Real,Real[m,n], ... - Unify Reals,Bint into Array #356 Generalize
Bintto nontrivial shape Support nontrivially shaped bint domains #322 and add anArraysupertype - Add minimal type annotation support to funsors #354 Update interfaces to make use of typing-compatible types (e.g. allow
@function,@of_typeto read type hints) - Replace bint -> Bint, reals -> Reals throughout codebase #357 Cleanup: replace all uses of
reals()andbint()withReals[]andBint[] - Unify op-caching metaclasses #421 Cleanup: unify op-caching metaclasses
- Break up type inference rules in find_domain into op-level patterns #422 Support dynamic op creation and registration in
find_domain - Add Finitary funsor for representing lazy op application #423 Add a
Finitaryterm for lazy op application - Add Tuple funsor #430 Promote
LazyTupleto a subclass ofFunsor - Add automatic registration of all unary and associative ops #431 Cleanup: automate invocation of
UnaryandBinaryfor ops applied to funsors - Replace
FunctionwithFinitary(or mergeUnaryandBinaryintoFunctionas in the paper);
and replace@functionwith a dynamicOpfactory. - Support limited (variables but no arithmetic) shape polymorphism in
Arraydomains (Support size variables in funsor.domains (dependent types) #214)This will require a unification algorithm in@function def matmul(x: Reals["i", "j"], y: Reals["j", "k"]) -> Reals["i", "k"]: return x @ y
find_domain()and substitution. - Add type
.__annotations__to all Ops and refactorfind_domain(). We may be able to read many of these from gufunc signatures. - Add a mypy test stage and ensure the Funsor codebase typechecks.
- Register
to_funsorto use either@functionor@symbolic(requires first classTuples, memoization)? - Possibly promote
Funsortypes themselves to subtypes of Callable
Reactions are currently unavailable