-
Notifications
You must be signed in to change notification settings - Fork 20
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
Replace domains -> types, .inputs+.output -> type hints #351
Comments
This definitely seems like the right way to go. Some design questions:
I was more thinking about making all |
@eb8680 great questions!
|
@eb8680 suggested this will be easier after #491 , e.g. we could add an ...
encoder = Encoder()
decoder = Decoder()
# Version 0. current state
encode = funsor.function(Reals[28, 28], (Reals[20], Reals[20]))(encoder)
decode = funsor.function(Reals[20], Reals[28, 28])(decoder)
# Version 1. replace Function with and Op
@UnaryOp.make
def encode(image):
return encoder(image)
@find_domain.register(encode)
def _(op, image):
return typing.Tuple[Reals[20], Reals[20]]
# Version 2. read signature from the nn.Module
encode = UnaryOp.make(encoder)
# ...find_domain.register
# Version 3. registers find_domain based on type annotations
@UnaryOp.make
def encode(image: Reals[28, 28]) -> typing.Tuple[Reals[20], Reals[20]]:
return encoder(image)
# Version 4. automatically determines arity
@ops.make(arity=1) # manually specify
@ops.make # assume arity = nargs
def encode(image: Reals[28, 28]) -> typing.Tuple[Reals[20], Reals[20]]:
return encoder(image) |
This issue proposes to replace funsor
Domain
objects with new subscripted types a la Python 3'styping
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:
Interface
Because the Python 3 typing library is moving and not natively inspectable, we should implement a minimal interface for inspection:
Bint[n]
,Reals[m,n]
isinstance(-, Domain)
(withDomain = type
)issubclass(-, -)
(by overriding__subclasscheck__
)typing.get_type_hints()
for funsorstyping.get_origin()
typing.get_args()
Tasks
Bint[n]
,Real
,Real[m,n]
, ...Bint
to nontrivial shape Support nontrivially shaped bint domains #322 and add anArray
supertype@function
,@of_type
to read type hints)reals()
andbint()
withReals[]
andBint[]
find_domain
Finitary
term for lazy op applicationLazyTuple
to a subclass ofFunsor
Unary
andBinary
for ops applied to funsorsFunction
withFinitary
(or mergeUnary
andBinary
intoFunction
as in the paper);and replace
@function
with a dynamicOp
factory.Array
domains (Support size variables in funsor.domains (dependent types) #214)find_domain()
and substitution..__annotations__
to all Ops and refactorfind_domain()
. We may be able to read many of these from gufunc signatures.to_funsor
to use either@function
or@symbolic
(requires first classTuple
s, memoization)?Funsor
types themselves to subtypes of CallableThe text was updated successfully, but these errors were encountered: