pyhs3.normalization.substitute_variable¶
- pyhs3.normalization.substitute_variable(output, variable, replacement)[source]¶
Return
outputwithvariablereplaced byreplacement.Only the nodes that depend on
variableare rebuilt, each through itsOp’smake_nodeso that its output type is inferred again from the new inputs; every other node is reused as it is.This differs from PyTensor’s two built-in substitutions:
graph_replacerebuilds only the dependent nodes too, but keeps their original output types. Replacing an observable of unknown length(?,)by a(1,)bound therefore leaves an axis typed as unknown that holds length 1, which PyTensor refuses to broadcast at runtime (https://github.com/scipp-atlas/pyhs3/issues/346).clone_replace(..., rebuild_strict=False)infers the types again but copies the whole graph, including the nodes that never depended onvariable, so an antiderivative evaluated at two bounds carries two copies of its parameter-only parts.
- Parameters:
- Return type:
- Returns:
The substituted expression, or
outputitself if it does not depend onvariable.