Skip to content

rewrites for exp/log combinations #1540

Answered by ricardoV94
OriolAbril asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not sure you would want such a rewrite, if anything you want to make more things on log scale, not less (see #177), for stability.

In your case if b is negative for example it helps keeping the exponential small, but making it power will facilitate underflow. In either case, in the final fused function you only iterate over the vector x once.

The performance will depend on your machine, but in mine the original one is roughly 2x faster than the proposed alternative (also allows smaller outputs before underflowing). Power with an arbitrary float is more expensive than repeated log and exp. It may change depending on the specific b.

import pytensor
import pytensor.tensor as pt
import numpy

Replies: 10 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by OriolAbril
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@OriolAbril
Comment options

OriolAbril Jul 14, 2025
Maintainer Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #1539 on July 14, 2025 15:23.