roualdes / bridgestan

BridgeStan provides efficient in-memory access through Python, Julia, and R to the methods of a Stan model.
https://roualdes.github.io/bridgestan
BSD 3-Clause "New" or "Revised" License
87 stars 12 forks source link

Remove unnecessary backward pass in log_density #165

Closed WardBrian closed 11 months ago

WardBrian commented 11 months ago

In bs_log_density, if you request dropping of constant terms, it is important we instantiate the model class' log_prob implementation with vars (doubles are considered constants, and therefore dropped).

However, it is not necessary to actually compute the backward pass on those vars, which is currently done in log_density when propto=True. This means the log density calculation is slower than it could be, which this PR fixes.