Skip to content

Implement more types of measurable elemwise transformations #6631

@ricardoV94

Description

@ricardoV94

We already have support for

  • add (and subtraction via addition)
  • mul (and division and neg via multiplication)
  • pow (inludes reciprocal, sqrt, sqr, etc...)
  • exp
  • log
  • abs

Other operations we could support

valid_scalar_types = (Exp, Log, Add, Mul, Pow, Abs)

Other operations we can support via rewrites to already supported forms

  • exp2, log2, log10
  • log1p
  • expm1
  • log1mexp
  • log1pexp (softplus)
  • sigmoid

Example of such rewrites:

@node_rewriter([neg])
def measurable_neg_to_product(fgraph, node):
"""Convert negation of `MeasurableVariable`s to product with `-1`."""
inp = node.inputs[0]
if not (inp.owner and isinstance(inp.owner.op, MeasurableVariable)):
return None
rv_map_feature: Optional[PreserveRVMappings] = getattr(fgraph, "preserve_rv_mappings", None)
if rv_map_feature is None:
return None # pragma: no cover
# Only apply this rewrite if the variable is unvalued
if inp in rv_map_feature.rv_values:
return None # pragma: no cover
return [pt.mul(inp, -1.0)]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions