Skip to content
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

Support functions in tensor shapes. #2

Open
patrick-kidger opened this issue Apr 1, 2021 · 3 comments
Open

Support functions in tensor shapes. #2

patrick-kidger opened this issue Apr 1, 2021 · 3 comments

Comments

@patrick-kidger
Copy link
Owner

patrick-kidger commented Apr 1, 2021

e.g. cat(a: TensorType["x"], b: TensorType["y"]) -> TensorType["x + y"].
Given that torchtyping operates at runtime then arbitrary Python expressions should be possible. Essentially just call eval with the appropriate constants x, y etc. bound in. Ignore any errors, so that e.g. func(x: TensorType["x + y"]) remains valid, but if the expression evaluates then compare its result against the value inferred.

This should happen as an additional round of checking, at the end of the current _check_memo function.

@patrick-kidger patrick-kidger changed the title Support basic arithmetic in tensor shapes. Support functions in tensor shapes. Apr 1, 2021
@rsokl
Copy link

rsokl commented Apr 12, 2021

Hello! There is an active typing-sig mailing list, with a tensor typing meeting that you would probably be interested in.

These meeting have discussed things like doing tensor arithmetic, and have produced a PEP-in-progress (646) for variadic generics. This does not actually enable type arithmetic but does serve to lay foundation for it.

This repo may also be of interest to you. The main to contributor to the repo runs the tensor typing meeting ans is the author of the PEP.

@patrick-kidger
Copy link
Owner Author

Hello! Thanks for reaching out. The tensor typing meetings do sound interesting. I've now joined the typing-sig mailing list.

On the topic of tensor arithmetic, I remember it seeing discussed somewhere (I forget where exactly) that whenever it makes it in, type arithmetic would likely be restricted to simple arithmetic like +, -, max etc. One of the nice things about operating at runtime is that torchtyping could support arbitrary Python expressions; it's just a matter of calling eval with the right set of globals and locals.

@rsokl
Copy link

rsokl commented Apr 12, 2021

There are definitely advantages to torchtyping's approach! Just wanted to make sure you were looped in on these other conversations and efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants