@opt.register_stabilize
@gof.local_optimizer([tensor.mul])
def local_sigm_times_exp(node):
 if (node.op != tensor.mul):
  return None
 mul_tree = parse_mul_tree(node.outputs[0])
 did_something = perform_sigm_times_exp(mul_tree)
 if (not did_something):
  return None
 mul_tree = simplify_mul(mul_tree)
 out = compute_mul(mul_tree)
 copy_stack_trace(node.outputs[0], out)
 return [out]

@ opt . register_stabilize @ gof . local_optimizer ( [ tensor . mul ] ) def local_sigm_times_exp ( node ) : if ( node . op != tensor . mul ) : return None mul_tree = parse_mul_tree ( node . outputs [ 0 ] ) did_something = perform_sigm_times_exp ( mul_tree ) if ( not did_something ) : return None mul_tree = simplify_mul ( mul_tree ) out = compute_mul ( mul_tree ) copy_stack_trace ( node . outputs [ 0 ] , out ) return [ out ]
exp(x) * sigm -> sigm(x) exp * sigm(x) -> sigm todo: add stack traces to the intermediate variables .