pyro-ppl / funsor

Functional tensors for probabilistic programming
https://funsor.pyro.ai
Apache License 2.0
236 stars 20 forks source link

Strengthen algebraic organization of funsor.ops and related code #307

Open eb8680 opened 4 years ago

eb8680 commented 4 years ago

The changes proposed in #304 and the incorrect code path for logaddexp uncovered in #306 suggest adding more structure to the funsor.ops module.

Possible changes:

fritzo commented 4 years ago

op implementations are opaque to Funsor and are only invoked on ... data

I seems more natural to me to extend Python's builtin operator library by letting e.g. ops.add apply to funsors. That way we can use Python idiomatic syntax to describe both data and funsors. A simple fix for logaddexp is to add .__logaddexp__() method handling as in #306; we did the same thing for .__matmul__ in Python 2 before it was standardized in Python 3. Generally it seems natural to let ops strictly extend operator by (1) adding more structure (as proposed in this issue), and (2) adding more ops.