# Are there C implementations of ExGaussian and Normal logcdf functions?

**URL:** <https://discourse.pymc.io/t/are-there-c-implementations-of-exgaussian-and-normal-logcdf-functions/6870>\
**Category:** Questions\
**Created:** [March 1, 2021, 11:12pm UTC](https://discourse.pymc.io/t/are-there-c-implementations-of-exgaussian-and-normal-logcdf-functions/6870 "2021-03-01T23:12:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jstanley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jstanley/32/3711_2.png) [@jstanley](https://discourse.pymc.io/u/jstanley)\
**Post date:** [March 1, 2021, 11:12pm UTC](https://discourse.pymc.io/t/are-there-c-implementations-of-exgaussian-and-normal-logcdf-functions/6870/1 "2021-03-01T23:12:39Z")

</div>

I am trying to use a custom model (i.e. defining a `logp` function for a custom pdf) in pymc3 that requires the logcdf of the `ExGaussian` and `Normal` distributions. I have written my own functions for them, using basic `theano` calls, however this results in lots of overflow (as discussed in another [recent thread](https://discourse.pymc.io/t/vi-fitting-of-custom-pdf-sporadically-producing-nan-parameter-values-which-terminate-fit/6845)).

Conversely, I am trying to use:  
`pm.ExGaussian.dist().logcdf()`  
`pm.Normal.dist().logcdf()`

However, these run very slowly and give me the following warning:

`WARNING (theano.tensor.opt): Optimization Warning: The Op erfcx does not provide a C implementation. As well as being potentially slow, this also disables loop fusion.`

Is there any C implementations of these logcdf functions that can be used with `pymc3`?

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [March 2, 2021, 8:27am UTC](https://discourse.pymc.io/t/are-there-c-implementations-of-exgaussian-and-normal-logcdf-functions/6870/2 "2021-03-02T08:27:37Z")

</div>

Not yet. For numerical stability reasons we are relying on the ercfx method, which currently does not have c support. We have an open issue here: [Add C implementation for I1e, I0e and erfcx Ops · Issue #267 · pymc-devs/aesara · GitHub](https://github.com/pymc-devs/aesara/issues/267)

---

<div class="post-metadata">

**Author:** ![jstanley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jstanley/32/3711_2.png) [@jstanley](https://discourse.pymc.io/u/jstanley)\
**Post date:** [March 2, 2021, 11:12pm UTC](https://discourse.pymc.io/t/are-there-c-implementations-of-exgaussian-and-normal-logcdf-functions/6870/3 "2021-03-02T23:12:15Z")

</div>

Great! Thanks for your work on getting the C implementation up and running.

---

<div class="post-metadata">

**Author:** ![jstanley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jstanley/32/3711_2.png) [@jstanley](https://discourse.pymc.io/u/jstanley)\
**Post date:** [June 2, 2021, 3:55pm UTC](https://discourse.pymc.io/t/are-there-c-implementations-of-exgaussian-and-normal-logcdf-functions/6870/4 "2021-06-02T15:55:58Z")

</div>

@ricardoV94 I wanted to check in about the status of the C implementation of the `erfcx` function. Has it been utilized in the `logcdf` functions of `ExGaussian` and if so, what versions of pymc3/aesara? I was trying to follow along in the GitHub Issue you linked but it wasn’t clear to me whether or not it had been resolved. Thanks for all the work you’re doing. It’s much appreciated!

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [June 2, 2021, 4:13pm UTC](https://discourse.pymc.io/t/are-there-c-implementations-of-exgaussian-and-normal-logcdf-functions/6870/5 "2021-06-02T16:13:13Z")

</div>

@jstanley I added the C code for erfcx, but it will only show up in the next version of pymc3 (V4) which will be using aesara. There is no stable version of pymc3 running with aesara just yet 😕

---

<div class="post-metadata">

**Author:** ![jstanley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jstanley/32/3711_2.png) [@jstanley](https://discourse.pymc.io/u/jstanley)\
**Post date:** [June 2, 2021, 6:11pm UTC](https://discourse.pymc.io/t/are-there-c-implementations-of-exgaussian-and-normal-logcdf-functions/6870/6 "2021-06-02T18:11:00Z")

</div>

Thanks for the update. I’ll be patient then.
