Open eb8680 opened 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.
The changes proposed in #304 and the incorrect code path for
logaddexp
uncovered in #306 suggest adding more structure to thefunsor.ops
module.Possible changes:
torch.Tensor
s, perhaps in the base definition ofops.Op
AssociativeOp
forargreduce
computations so that the backward op arguments infunsor.adjoint
methods can be removedCommutativeOp
orCommutativeAssociativeOp
class to distinguish between commutative and non-commutative monoidsSemiring
data structure for use byContraction
andnormalize
containing a sum and product op and (where applicable) their units and inverses instead of passing around separate opssum_op
andprod_op
and storing units and inverses globally