Is there any C++ API with same functionality as torch.distributions.Categorical?
I found torch::::multinomial that has same input parameters (const Tensor &self, int64_t num_samples, bool replacement = false, Generator *generator = nullptr), but it does not have sample or log_prob APIs.


1 Like

Bump this… It would be nice if someone can answer this question.

Hi, we don’t have c++ apis for distributions at this point. But we do plan to add distributions support in cpp in the future.


Hi @glaringlee,

Thank you for clarifying this.

Separately from this topic, but somewhat related, the implementation for torch.distributions.Normal appears to be here: In the sample() function, on line 63, there is a call to torch.normal(). I have not been able to find the implementation for it. Do you think you could provide a link to the file defining torch.normal()?

That’s a binding function which actually pointing to our c++ implementation, entry point is here:
The cpu implementation is here:
The gpu implementation is here:

1 Like

Hi @glaringlee,

Thank you very much, seeing the implementation was very useful for me.
Would you also be able to point me to the implementation of the .log_prob() implementation for the normal distribution?

I assumed it is computed as the logarithm of the probability density function. I would like to clarify if that’s the case.

Thank you for your help.

Hi @glaringlee,

Now that I remember, I had actually found the implementation for .log_prob() some time ago here.

Thank you!

Are now any of sample or log_prob APIs implemented?