code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def integrate_kde(self, other):
"""Integrate the product of two Gaussian KDE distributions."""
if other.d != self.d:
raise ValueError("KDEs are not the same dimensionality")
chol = linalg.cho_factor(self.covariance + other.covariance)
norm = jnp.sqrt(2 * np.pi)**self.d * jnp.prod(jnp.diag(chol[0]... | Integrate the product of two Gaussian KDE distributions. | integrate_kde | python | jax-ml/jax | jax/_src/scipy/stats/kde.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/kde.py | Apache-2.0 |
def resample(self, key, shape=()):
r"""Randomly sample a dataset from the estimated pdf
Args:
key: a PRNG key used as the random key.
shape: optional, a tuple of nonnegative integers specifying the result
batch shape; that is, the prefix of the result shape excluding the last
axis.
... | Randomly sample a dataset from the estimated pdf
Args:
key: a PRNG key used as the random key.
shape: optional, a tuple of nonnegative integers specifying the result
batch shape; that is, the prefix of the result shape excluding the last
axis.
Returns:
The resampled dataset a... | resample | python | jax-ml/jax | jax/_src/scipy/stats/kde.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/kde.py | Apache-2.0 |
def integrate_box(self, low_bounds, high_bounds, maxpts=None):
"""This method is not implemented in the JAX interface."""
del low_bounds, high_bounds, maxpts
raise NotImplementedError(
"only 1D box integrations are supported; use `integrate_box_1d`") | This method is not implemented in the JAX interface. | integrate_box | python | jax-ml/jax | jax/_src/scipy/stats/kde.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/kde.py | Apache-2.0 |
def logpdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Laplace log probability distribution function.
JAX implementation of :obj:`scipy.stats.laplace` ``logpdf``.
The Laplace probability distribution function is given by
.. math::
f(x) = \frac{1}{2} e^{-|x|}
Args:
x: ar... | Laplace log probability distribution function.
JAX implementation of :obj:`scipy.stats.laplace` ``logpdf``.
The Laplace probability distribution function is given by
.. math::
f(x) = \frac{1}{2} e^{-|x|}
Args:
x: arraylike, value at which to evaluate the PDF
loc: arraylike, distribution offset... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/laplace.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/laplace.py | Apache-2.0 |
def cdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Laplace cumulative distribution function.
JAX implementation of :obj:`scipy.stats.laplace` ``cdf``.
The cdf is defined as
.. math::
f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y
where :math:`f_{pdf}` is the pro... | Laplace cumulative distribution function.
JAX implementation of :obj:`scipy.stats.laplace` ``cdf``.
The cdf is defined as
.. math::
f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y
where :math:`f_{pdf}` is the probability density function,
:func:`jax.scipy.stats.laplace.pdf`.
Args:
x... | cdf | python | jax-ml/jax | jax/_src/scipy/stats/laplace.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/laplace.py | Apache-2.0 |
def logpdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Logistic log probability distribution function.
JAX implementation of :obj:`scipy.stats.logistic` ``logpdf``.
The logistic probability distribution function is given by
.. math::
f(x) = \frac{e^{-x}}{(1 + e^{-x})^2}
Arg... | Logistic log probability distribution function.
JAX implementation of :obj:`scipy.stats.logistic` ``logpdf``.
The logistic probability distribution function is given by
.. math::
f(x) = \frac{e^{-x}}{(1 + e^{-x})^2}
Args:
x: arraylike, value at which to evaluate the PDF
a: arraylike, distribut... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/logistic.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/logistic.py | Apache-2.0 |
def ppf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
"""Logistic distribution percent point function.
JAX implementation of :obj:`scipy.stats.logistic` ``ppf``.
The percent point function is defined as the inverse of the
cumulative distribution function, :func:`jax.scipy.stats.logistic.cd... | Logistic distribution percent point function.
JAX implementation of :obj:`scipy.stats.logistic` ``ppf``.
The percent point function is defined as the inverse of the
cumulative distribution function, :func:`jax.scipy.stats.logistic.cdf`.
Args:
x: arraylike, value at which to evaluate the PPF
loc: arra... | ppf | python | jax-ml/jax | jax/_src/scipy/stats/logistic.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/logistic.py | Apache-2.0 |
def sf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
"""Logistic distribution survival function.
JAX implementation of :obj:`scipy.stats.logistic` ``sf``
The survival function is defined as
.. math::
f_{sf}(x, k) = 1 - f_{cdf}(x, k)
where :math:`f_{cdf}(x, k)` is the cumulative d... | Logistic distribution survival function.
JAX implementation of :obj:`scipy.stats.logistic` ``sf``
The survival function is defined as
.. math::
f_{sf}(x, k) = 1 - f_{cdf}(x, k)
where :math:`f_{cdf}(x, k)` is the cumulative distribution function,
:func:`jax.scipy.stats.logistic.cdf`.
Args:
x: ... | sf | python | jax-ml/jax | jax/_src/scipy/stats/logistic.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/logistic.py | Apache-2.0 |
def isf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
"""Logistic distribution inverse survival function.
JAX implementation of :obj:`scipy.stats.logistic` ``isf``.
Returns the inverse of the survival function,
:func:`jax.scipy.stats.logistic.sf`.
Args:
x: arraylike, value at which ... | Logistic distribution inverse survival function.
JAX implementation of :obj:`scipy.stats.logistic` ``isf``.
Returns the inverse of the survival function,
:func:`jax.scipy.stats.logistic.sf`.
Args:
x: arraylike, value at which to evaluate the ISF
loc: arraylike, distribution offset parameter
scale... | isf | python | jax-ml/jax | jax/_src/scipy/stats/logistic.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/logistic.py | Apache-2.0 |
def cdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Logistic cumulative distribution function.
JAX implementation of :obj:`scipy.stats.logistic` ``cdf``.
The cdf is defined as
.. math::
f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y
where :math:`f_{pdf}` is the p... | Logistic cumulative distribution function.
JAX implementation of :obj:`scipy.stats.logistic` ``cdf``.
The cdf is defined as
.. math::
f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y
where :math:`f_{pdf}` is the probability density function,
:func:`jax.scipy.stats.logistic.pdf`.
Args:
... | cdf | python | jax-ml/jax | jax/_src/scipy/stats/logistic.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/logistic.py | Apache-2.0 |
def logpmf(x: ArrayLike, n: ArrayLike, p: ArrayLike) -> Array:
r"""Multinomial log probability mass function.
JAX implementation of :obj:`scipy.stats.multinomial` ``logpdf``.
The multinomial probability distribution is given by
.. math::
f(x, n, p) = n! \prod_{i=1}^k \frac{p_i^{x_i}}{x_i!}
with :mat... | Multinomial log probability mass function.
JAX implementation of :obj:`scipy.stats.multinomial` ``logpdf``.
The multinomial probability distribution is given by
.. math::
f(x, n, p) = n! \prod_{i=1}^k \frac{p_i^{x_i}}{x_i!}
with :math:`n = \sum_i x_i`.
Args:
x: arraylike, value at which to eval... | logpmf | python | jax-ml/jax | jax/_src/scipy/stats/multinomial.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/multinomial.py | Apache-2.0 |
def logpdf(x: ArrayLike, mean: ArrayLike, cov: ArrayLike, allow_singular: None = None) -> ArrayLike:
r"""Multivariate normal log probability distribution function.
JAX implementation of :obj:`scipy.stats.multivariate_normal` ``logpdf``.
The multivariate normal PDF is defined as
.. math::
f(x) = \frac{1... | Multivariate normal log probability distribution function.
JAX implementation of :obj:`scipy.stats.multivariate_normal` ``logpdf``.
The multivariate normal PDF is defined as
.. math::
f(x) = \frac{1}{(2\pi)^k\det\Sigma}\exp\left(-\frac{(x-\mu)^T\Sigma^{-1}(x-\mu)}{2} \right)
where :math:`\mu` is the `... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/multivariate_normal.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/multivariate_normal.py | Apache-2.0 |
def logpmf(k: ArrayLike, n: ArrayLike, p: ArrayLike, loc: ArrayLike = 0) -> Array:
r"""Negative-binomial log probability mass function.
JAX implementation of :obj:`scipy.stats.nbinom` ``logpmf``.
The negative-binomial probability mass function is given by
.. math::
f(k) = {{k+n-1} \choose {n-1}}p^n(1-p... | Negative-binomial log probability mass function.
JAX implementation of :obj:`scipy.stats.nbinom` ``logpmf``.
The negative-binomial probability mass function is given by
.. math::
f(k) = {{k+n-1} \choose {n-1}}p^n(1-p)^k
for :math:`k \ge 0` and :math:`0 \le p \le 1`.
Args:
k: arraylike, value at... | logpmf | python | jax-ml/jax | jax/_src/scipy/stats/nbinom.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/nbinom.py | Apache-2.0 |
def logpdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Normal log probability distribution function.
JAX implementation of :obj:`scipy.stats.norm` ``logpdf``.
The normal distribution pdf is given by
.. math::
f(x) = \frac{1}{\sqrt{2\pi}}e^{-x^2/2}
Args:
x: arraylike, va... | Normal log probability distribution function.
JAX implementation of :obj:`scipy.stats.norm` ``logpdf``.
The normal distribution pdf is given by
.. math::
f(x) = \frac{1}{\sqrt{2\pi}}e^{-x^2/2}
Args:
x: arraylike, value at which to evaluate the PDF
loc: arraylike, distribution offset parameter
... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/norm.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/norm.py | Apache-2.0 |
def cdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Normal cumulative distribution function.
JAX implementation of :obj:`scipy.stats.norm` ``cdf``.
The cdf is defined as
.. math::
f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y
where :math:`f_{pdf}` is the probabi... | Normal cumulative distribution function.
JAX implementation of :obj:`scipy.stats.norm` ``cdf``.
The cdf is defined as
.. math::
f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y
where :math:`f_{pdf}` is the probability density function,
:func:`jax.scipy.stats.norm.pdf`.
Args:
x: array... | cdf | python | jax-ml/jax | jax/_src/scipy/stats/norm.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/norm.py | Apache-2.0 |
def logcdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Normal log cumulative distribution function.
JAX implementation of :obj:`scipy.stats.norm` ``logcdf``.
The cdf is defined as
.. math::
f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y
where :math:`f_{pdf}` is t... | Normal log cumulative distribution function.
JAX implementation of :obj:`scipy.stats.norm` ``logcdf``.
The cdf is defined as
.. math::
f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y
where :math:`f_{pdf}` is the probability density function,
:func:`jax.scipy.stats.norm.pdf`.
Args:
x... | logcdf | python | jax-ml/jax | jax/_src/scipy/stats/norm.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/norm.py | Apache-2.0 |
def logsf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
"""Normal distribution log survival function.
JAX implementation of :obj:`scipy.stats.norm` ``logsf``.
The survival function is defined as
.. math::
f_{sf}(x) = 1 - f_{cdf}(x)
where :math:`f_{cdf}(x)` is the cumulative distr... | Normal distribution log survival function.
JAX implementation of :obj:`scipy.stats.norm` ``logsf``.
The survival function is defined as
.. math::
f_{sf}(x) = 1 - f_{cdf}(x)
where :math:`f_{cdf}(x)` is the cumulative distribution function,
:func:`jax.scipy.stats.norm.cdf`.
Args:
x: arraylike, ... | logsf | python | jax-ml/jax | jax/_src/scipy/stats/norm.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/norm.py | Apache-2.0 |
def sf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
"""Normal distribution survival function.
JAX implementation of :obj:`scipy.stats.norm` ``sf``.
The survival function is defined as
.. math::
f_{sf}(x) = 1 - f_{cdf}(x)
where :math:`f_{cdf}(x)` is the cumulative distribution fu... | Normal distribution survival function.
JAX implementation of :obj:`scipy.stats.norm` ``sf``.
The survival function is defined as
.. math::
f_{sf}(x) = 1 - f_{cdf}(x)
where :math:`f_{cdf}(x)` is the cumulative distribution function,
:func:`jax.scipy.stats.norm.cdf`.
Args:
x: arraylike, value a... | sf | python | jax-ml/jax | jax/_src/scipy/stats/norm.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/norm.py | Apache-2.0 |
def logpdf(x: ArrayLike, b: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Pareto log probability distribution function.
JAX implementation of :obj:`scipy.stats.pareto` ``logpdf``.
The Pareto probability density function is given by
.. math::
f(x, b) = \begin{cases}
bx^{-(b+1... | Pareto log probability distribution function.
JAX implementation of :obj:`scipy.stats.pareto` ``logpdf``.
The Pareto probability density function is given by
.. math::
f(x, b) = \begin{cases}
bx^{-(b+1)} & x \ge 1\\
0 & x < 1
\end{cases}
and is defined for :math:`b > 0`.
Args:
... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/pareto.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/pareto.py | Apache-2.0 |
def logpmf(k: ArrayLike, mu: ArrayLike, loc: ArrayLike = 0) -> Array:
r"""Poisson log probability mass function.
JAX implementation of :obj:`scipy.stats.poisson` ``logpmf``.
The Poisson probability mass function is given by
.. math::
f(k) = e^{-\mu}\frac{\mu^k}{k!}
and is defined for :math:`k \ge 0`... | Poisson log probability mass function.
JAX implementation of :obj:`scipy.stats.poisson` ``logpmf``.
The Poisson probability mass function is given by
.. math::
f(k) = e^{-\mu}\frac{\mu^k}{k!}
and is defined for :math:`k \ge 0` and :math:`\mu \ge 0`.
Args:
k: arraylike, value at which to evaluat... | logpmf | python | jax-ml/jax | jax/_src/scipy/stats/poisson.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/poisson.py | Apache-2.0 |
def cdf(k: ArrayLike, mu: ArrayLike, loc: ArrayLike = 0) -> Array:
r"""Poisson cumulative distribution function.
JAX implementation of :obj:`scipy.stats.poisson` ``cdf``.
The cumulative distribution function is defined as:
.. math::
f_{cdf}(k, p) = \sum_{i=0}^k f_{pmf}(k, p)
where :math:`f_{pmf}(k, ... | Poisson cumulative distribution function.
JAX implementation of :obj:`scipy.stats.poisson` ``cdf``.
The cumulative distribution function is defined as:
.. math::
f_{cdf}(k, p) = \sum_{i=0}^k f_{pmf}(k, p)
where :math:`f_{pmf}(k, p)` is the probability mass function
:func:`jax.scipy.stats.poisson.pmf... | cdf | python | jax-ml/jax | jax/_src/scipy/stats/poisson.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/poisson.py | Apache-2.0 |
def logpdf(x: ArrayLike, df: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Student's T log probability distribution function.
JAX implementation of :obj:`scipy.stats.t` ``logpdf``.
The Student's T probability distribution function is given by
.. math::
f(x, \nu) = \frac{\Gamma((\nu... | Student's T log probability distribution function.
JAX implementation of :obj:`scipy.stats.t` ``logpdf``.
The Student's T probability distribution function is given by
.. math::
f(x, \nu) = \frac{\Gamma((\nu + 1)/2)}{\sqrt{\pi\nu}\Gamma(\nu/2)}(1 + x^2/\nu)^{(\nu+1)/2}
Where :math:`\Gamma` is the :fun... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/t.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/t.py | Apache-2.0 |
def logpdf(x, a, b, loc=0, scale=1):
r"""Truncated normal log probability distribution function.
JAX implementation of :obj:`scipy.stats.truncnorm` ``logpdf``.
The truncated normal probability distribution is given by
.. math::
f(x, a, b) = \begin{cases}
\frac{1}{\sqrt{2\pi}}e^{-x^2/2} & a \le x... | Truncated normal log probability distribution function.
JAX implementation of :obj:`scipy.stats.truncnorm` ``logpdf``.
The truncated normal probability distribution is given by
.. math::
f(x, a, b) = \begin{cases}
\frac{1}{\sqrt{2\pi}}e^{-x^2/2} & a \le x \le b \\
0 & \mathrm{otherwise}
... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/truncnorm.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/truncnorm.py | Apache-2.0 |
def logsf(x, a, b, loc=0, scale=1):
"""Truncated normal distribution log survival function.
JAX implementation of :obj:`scipy.stats.truncnorm` ``logsf``
The survival function is defined as
.. math::
f_{sf}(x) = 1 - f_{cdf}(x)
where :math:`f_{cdf}(x)` is the cumulative distribution function,
:func:... | Truncated normal distribution log survival function.
JAX implementation of :obj:`scipy.stats.truncnorm` ``logsf``
The survival function is defined as
.. math::
f_{sf}(x) = 1 - f_{cdf}(x)
where :math:`f_{cdf}(x)` is the cumulative distribution function,
:func:`jax.scipy.stats.truncnorm.cdf`.
Args:... | logsf | python | jax-ml/jax | jax/_src/scipy/stats/truncnorm.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/truncnorm.py | Apache-2.0 |
def logcdf(x, a, b, loc=0, scale=1):
r"""Truncated normal log cumulative distribution function.
JAX implementation of :obj:`scipy.stats.truncnorm` ``logcdf``.
The cdf is defined as
.. math::
f_{cdf} = \int_{-\infty}^x f_{pdf}(y) \mathrm{d}y
where here :math:`f_{pdf}` is the probability distribution ... | Truncated normal log cumulative distribution function.
JAX implementation of :obj:`scipy.stats.truncnorm` ``logcdf``.
The cdf is defined as
.. math::
f_{cdf} = \int_{-\infty}^x f_{pdf}(y) \mathrm{d}y
where here :math:`f_{pdf}` is the probability distribution function,
:func:`jax.scipy.stats.truncnor... | logcdf | python | jax-ml/jax | jax/_src/scipy/stats/truncnorm.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/truncnorm.py | Apache-2.0 |
def logpdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Uniform log probability distribution function.
JAX implementation of :obj:`scipy.stats.uniform` ``logpdf``.
The uniform distribution pdf is given by
.. math::
f(x) = \begin{cases}
1 & 0 \le x \le 1 \\
0 & \ma... | Uniform log probability distribution function.
JAX implementation of :obj:`scipy.stats.uniform` ``logpdf``.
The uniform distribution pdf is given by
.. math::
f(x) = \begin{cases}
1 & 0 \le x \le 1 \\
0 & \mathrm{otherwise}
\end{cases}
Args:
x: arraylike, value at which to evalu... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/uniform.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/uniform.py | Apache-2.0 |
def cdf(x: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
r"""Uniform cumulative distribution function.
JAX implementation of :obj:`scipy.stats.uniform` ``cdf``.
The cdf is defined as
.. math::
f_{cdf} = \int_{-\infty}^x f_{pdf}(y) \mathrm{d}y
where here :math:`f_{pdf}` is the probab... | Uniform cumulative distribution function.
JAX implementation of :obj:`scipy.stats.uniform` ``cdf``.
The cdf is defined as
.. math::
f_{cdf} = \int_{-\infty}^x f_{pdf}(y) \mathrm{d}y
where here :math:`f_{pdf}` is the probability distribution function,
:func:`jax.scipy.stats.uniform.pdf`.
Args:
... | cdf | python | jax-ml/jax | jax/_src/scipy/stats/uniform.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/uniform.py | Apache-2.0 |
def ppf(q: ArrayLike, loc: ArrayLike = 0, scale: ArrayLike = 1) -> Array:
"""Uniform distribution percent point function.
JAX implementation of :obj:`scipy.stats.uniform` ``ppf``.
The percent point function is defined as the inverse of the
cumulative distribution function, :func:`jax.scipy.stats.uniform.cdf`.... | Uniform distribution percent point function.
JAX implementation of :obj:`scipy.stats.uniform` ``ppf``.
The percent point function is defined as the inverse of the
cumulative distribution function, :func:`jax.scipy.stats.uniform.cdf`.
Args:
q: arraylike, value at which to evaluate the PPF
loc: arrayli... | ppf | python | jax-ml/jax | jax/_src/scipy/stats/uniform.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/uniform.py | Apache-2.0 |
def logpdf(x: ArrayLike, kappa: ArrayLike) -> Array:
r"""von Mises log probability distribution function.
JAX implementation of :obj:`scipy.stats.vonmises` ``logpdf``.
The von Mises probability distribution function is given by
.. math::
f(x, \kappa) = \frac{1}{2\pi I_0(\kappa)}e^{\kappa\cos x}
Wher... | von Mises log probability distribution function.
JAX implementation of :obj:`scipy.stats.vonmises` ``logpdf``.
The von Mises probability distribution function is given by
.. math::
f(x, \kappa) = \frac{1}{2\pi I_0(\kappa)}e^{\kappa\cos x}
Where :math:`I_0` is the modified Bessel function :func:`~jax.s... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/vonmises.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/vonmises.py | Apache-2.0 |
def logpdf(x: ArrayLike, c: ArrayLike) -> Array:
r"""Wrapped Cauchy log probability distribution function.
JAX implementation of :obj:`scipy.stats.wrapcauchy` ``logpdf``.
The wrapped Cauchy probability distribution function is given by
.. math::
f(x, c) = \frac{1-c^2}{2\pi(1+c^2-2c\cos x)}
for :math... | Wrapped Cauchy log probability distribution function.
JAX implementation of :obj:`scipy.stats.wrapcauchy` ``logpdf``.
The wrapped Cauchy probability distribution function is given by
.. math::
f(x, c) = \frac{1-c^2}{2\pi(1+c^2-2c\cos x)}
for :math:`0<c<1`, and where normalization is on the domain :mat... | logpdf | python | jax-ml/jax | jax/_src/scipy/stats/wrapcauchy.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/wrapcauchy.py | Apache-2.0 |
def mode(a: ArrayLike, axis: int | None = 0, nan_policy: str = "propagate", keepdims: bool = False) -> ModeResult:
"""Compute the mode (most common value) along an axis of an array.
JAX implementation of :func:`scipy.stats.mode`.
Args:
a: arraylike
axis: int, default=0. Axis along which to compute the m... | Compute the mode (most common value) along an axis of an array.
JAX implementation of :func:`scipy.stats.mode`.
Args:
a: arraylike
axis: int, default=0. Axis along which to compute the mode.
nan_policy: str. JAX only supports ``"propagate"``.
keepdims: bool, default=False. If true, reduced axes ar... | mode | python | jax-ml/jax | jax/_src/scipy/stats/_core.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/_core.py | Apache-2.0 |
def _mode_helper(x: jax.Array) -> tuple[jax.Array, jax.Array]:
"""Helper function to return mode and count of a given array."""
if x.size == 0:
return (jnp.array(jnp.nan, dtype=dtypes.canonicalize_dtype(jnp.float_)),
jnp.array(0, dtype=dtypes.canonicalize_dtype(jnp.float_)))
else:
... | Helper function to return mode and count of a given array. | _mode_helper | python | jax-ml/jax | jax/_src/scipy/stats/_core.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/_core.py | Apache-2.0 |
def rankdata(
a: ArrayLike,
method: str = "average",
*,
axis: int | None = None,
nan_policy: str = "propagate",
) -> Array:
"""Compute the rank of data along an array axis.
JAX implementation of :func:`scipy.stats.rankdata`.
Ranks begin at 1, and the *method* argument controls how ties are handled.
... | Compute the rank of data along an array axis.
JAX implementation of :func:`scipy.stats.rankdata`.
Ranks begin at 1, and the *method* argument controls how ties are handled.
Args:
a: arraylike
method: str, default="average". Supported methods are
``("average", "min", "max", "dense", "ordinal")``
... | rankdata | python | jax-ml/jax | jax/_src/scipy/stats/_core.py | https://github.com/jax-ml/jax/blob/master/jax/_src/scipy/stats/_core.py | Apache-2.0 |
def discharge_state(jaxpr: core.Jaxpr, consts: Sequence[Any], * ,
should_discharge: bool | Sequence[bool] = True
) -> tuple[core.Jaxpr, list[Any]]:
"""Converts a jaxpr that takes in `Ref`s into one that doesn't."""
if isinstance(should_discharge, bool):
should_discharge =... | Converts a jaxpr that takes in `Ref`s into one that doesn't. | discharge_state | python | jax-ml/jax | jax/_src/state/discharge.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/discharge.py | Apache-2.0 |
def _is_trivial_indexer(indexer: indexing.NDIndexer):
"""Returns whether the indexer selects the entire shape."""
for s, idx in zip(indexer.shape, indexer.indices):
if not isinstance(idx, indexing.Slice):
return False
if idx.is_dynamic_start or idx.is_dynamic_size:
return False
if idx.start ... | Returns whether the indexer selects the entire shape. | _is_trivial_indexer | python | jax-ml/jax | jax/_src/state/discharge.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/discharge.py | Apache-2.0 |
def dslice(
start: int | Array | None,
size: int | Array | None = None,
stride: int | None = None,
) -> slice | Slice:
"""Constructs a ``Slice`` from a start index and a size.
The semantics of ``dslice`` mirror those of the builtin ``slice`` type:
* ``dslice(None)`` is ``:``
* ``dslice(j)`` is ``:... | Constructs a ``Slice`` from a start index and a size.
The semantics of ``dslice`` mirror those of the builtin ``slice`` type:
* ``dslice(None)`` is ``:``
* ``dslice(j)`` is ``:j``
* ``dslice(i, j)`` is ``i:i+j``
* ``dslice(i, j, stride)`` is ``i:i+j:stride``
| dslice | python | jax-ml/jax | jax/_src/state/indexing.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/indexing.py | Apache-2.0 |
def ref_get(
ref_or_view: Any, idx: Indexer | tuple[Indexer, ...] | None = None
) -> Array:
"""Reads a value from a `Ref`, a.k.a. value <- ref[idx]."""
ref, transforms = get_ref_and_transforms(ref_or_view, idx, "ref_get")
flat_transforms, tree = tree_util.tree_flatten(transforms)
return get_p.bind(ref, *fla... | Reads a value from a `Ref`, a.k.a. value <- ref[idx]. | ref_get | python | jax-ml/jax | jax/_src/state/primitives.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/primitives.py | Apache-2.0 |
def ref_swap(
ref_or_view: AbstractRef | TransformedRef,
idx: Indexer | tuple[Indexer, ...] | None,
value: Array,
_function_name: str = "ref_swap",
) -> Array:
"""Sets a `Ref`'s value and returns the original value."""
if hasattr(ref_or_view, 'dtype'):
value = _maybe_implicit_cast(ref_or_view.dt... | Sets a `Ref`'s value and returns the original value. | ref_swap | python | jax-ml/jax | jax/_src/state/primitives.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/primitives.py | Apache-2.0 |
def ref_set(
ref_or_view: AbstractRef | TransformedRef,
idx: Indexer | tuple[Indexer, ...] | None,
value: Array,
) -> None:
"""Sets a `Ref`'s value, a.k.a. ref[idx] <- value."""
ref_swap(ref_or_view, idx, value, _function_name="ref_set") | Sets a `Ref`'s value, a.k.a. ref[idx] <- value. | ref_set | python | jax-ml/jax | jax/_src/state/primitives.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/primitives.py | Apache-2.0 |
def ref_addupdate(
ref_or_view: AbstractRef,
idx: Indexer | tuple[Indexer, ...] | None,
x: Array,
) -> None:
"""Mutates a ref with an additive update i.e. `ref[idx] += x`."""
ref, transforms = get_ref_and_transforms(ref_or_view, idx, "ref_addupdate")
flat_transforms, tree = tree_util.tree_flatten(tran... | Mutates a ref with an additive update i.e. `ref[idx] += x`. | ref_addupdate | python | jax-ml/jax | jax/_src/state/primitives.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/primitives.py | Apache-2.0 |
def _batch_indexer(
indexer: indexing.NDIndexer,
dims,
axis_size: int,
ref_shape: tuple[int, ...],
ref_dim: int | batching.NotMapped,
idx_is_batched: bool,
) -> indexing.NDIndexer:
"""Converts a batched indexer into an unbatched one.
This function handles the complexity of `vmap`-style batc... | Converts a batched indexer into an unbatched one.
This function handles the complexity of `vmap`-style batching where either the
`ref` being indexed, the indexer, or both may have batched dimensions. The
goal is to produce a new indexer that acts as if applied in a batched context,
but without actual batching,... | _batch_indexer | python | jax-ml/jax | jax/_src/state/primitives.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/primitives.py | Apache-2.0 |
def transform_shape(
self, shape: tuple[int | Array, ...] | None
) -> tuple[int | Array, ...] | None:
"""Transform the shape.
Can return None if the input shape is not known, but must return a concrete
result when the input shape is known.
"""
return shape | Transform the shape.
Can return None if the input shape is not known, but must return a concrete
result when the input shape is known.
| transform_shape | python | jax-ml/jax | jax/_src/state/types.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/types.py | Apache-2.0 |
def transform_dtype(
self, dtype: DTypeLike | None
) -> DTypeLike | None:
"""Transform the dtype.
Can return None if the input dtype is not known, but must return a concrete
result when the input dtype is known.
"""
return dtype | Transform the dtype.
Can return None if the input dtype is not known, but must return a concrete
result when the input dtype is known.
| transform_dtype | python | jax-ml/jax | jax/_src/state/types.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/types.py | Apache-2.0 |
def hoist_consts_to_refs(
jaxpr: core.Jaxpr,
*,
index: int = 0,
make_abstract_ref: Callable[[core.AbstractValue], AbstractRef] = lambda aval: AbstractRef(aval)
) -> core.Jaxpr:
"""Hoists the constants in the given jaxpr into invars.
Args:
jaxpr: The jaxpr.
index: The index where the invars ... | Hoists the constants in the given jaxpr into invars.
Args:
jaxpr: The jaxpr.
index: The index where the invars for the constants should be inserted.
By default, the new invars are inserted *before* any existing invars.
make_abstract_ref: a callable to construct an AbstractRef, or subtype
ther... | hoist_consts_to_refs | python | jax-ml/jax | jax/_src/state/utils.py | https://github.com/jax-ml/jax/blob/master/jax/_src/state/utils.py | Apache-2.0 |
def algdiv(a, b):
"""
Compute ``log(gamma(a))/log(gamma(a + b))`` when ``b >= 8``.
Derived from scipy's implementation of `algdiv`_.
This differs from the scipy implementation in that it assumes a <= b
because recomputing ``a, b = jnp.minimum(a, b), jnp.maximum(a, b)`` might
be expensive and t... |
Compute ``log(gamma(a))/log(gamma(a + b))`` when ``b >= 8``.
Derived from scipy's implementation of `algdiv`_.
This differs from the scipy implementation in that it assumes a <= b
because recomputing ``a, b = jnp.minimum(a, b), jnp.maximum(a, b)`` might
be expensive and this is only called by ``b... | algdiv | python | jax-ml/jax | jax/_src/third_party/scipy/betaln.py | https://github.com/jax-ml/jax/blob/master/jax/_src/third_party/scipy/betaln.py | Apache-2.0 |
def betaln(a: ArrayLike, b: ArrayLike) -> Array:
"""Compute the log of the beta function.
Derived from scipy's implementation of `betaln`_.
This implementation does not handle all branches of the scipy implementation, but is still much more accurate
than just doing lgamma(a) + lgamma(b) - lgamma(a + b... | Compute the log of the beta function.
Derived from scipy's implementation of `betaln`_.
This implementation does not handle all branches of the scipy implementation, but is still much more accurate
than just doing lgamma(a) + lgamma(b) - lgamma(a + b) when inputs are large (> 1M or so).
.. _betaln:
... | betaln | python | jax-ml/jax | jax/_src/third_party/scipy/betaln.py | https://github.com/jax-ml/jax/blob/master/jax/_src/third_party/scipy/betaln.py | Apache-2.0 |
def funm(A: ArrayLike, func: Callable[[Array], Array],
disp: bool = True) -> Array | tuple[Array, Array]:
"""Evaluate a matrix-valued function
JAX implementation of :func:`scipy.linalg.funm`.
Args:
A: array of shape ``(N, N)`` for which the function is to be computed.
func: Callable object that... | Evaluate a matrix-valued function
JAX implementation of :func:`scipy.linalg.funm`.
Args:
A: array of shape ``(N, N)`` for which the function is to be computed.
func: Callable object that takes a scalar argument and returns a scalar result.
Represents the function to be evaluated over the eigenvalues... | funm | python | jax-ml/jax | jax/_src/third_party/scipy/linalg.py | https://github.com/jax-ml/jax/blob/master/jax/_src/third_party/scipy/linalg.py | Apache-2.0 |
def _triage_segments(window: ArrayLike | str | tuple[Any, ...], nperseg: int | None,
input_length: int, dtype: DTypeLike) -> tuple[Array, int]:
"""
Parses window and nperseg arguments for spectrogram and _spectral_helper.
This is a helper function, not meant to be called externally.
Args:
... |
Parses window and nperseg arguments for spectrogram and _spectral_helper.
This is a helper function, not meant to be called externally.
Args:
window : string, tuple, or ndarray
If window is specified by a string or tuple and nperseg is not
specified, nperseg is set to the default of 256 and retu... | _triage_segments | python | jax-ml/jax | jax/_src/third_party/scipy/signal_helper.py | https://github.com/jax-ml/jax/blob/master/jax/_src/third_party/scipy/signal_helper.py | Apache-2.0 |
def _median_bias(n: int) -> Array:
"""
Returns the bias of the median of a set of periodograms relative to
the mean. See Appendix B from [1]_ for details.
Args:
n : int
Numbers of periodograms being averaged.
Returns:
bias : float
Calculated bias.
References:
.. [1] B. Allen, W.G. An... |
Returns the bias of the median of a set of periodograms relative to
the mean. See Appendix B from [1]_ for details.
Args:
n : int
Numbers of periodograms being averaged.
Returns:
bias : float
Calculated bias.
References:
.. [1] B. Allen, W.G. Anderson, P.R. Brady, D.A. Brown, J.D.E. C... | _median_bias | python | jax-ml/jax | jax/_src/third_party/scipy/signal_helper.py | https://github.com/jax-ml/jax/blob/master/jax/_src/third_party/scipy/signal_helper.py | Apache-2.0 |
def sincospisquaredhalf(
x: Array,
) -> tuple[Array, Array]:
"""
Accurate evaluation of sin(pi * x**2 / 2) and cos(pi * x**2 / 2).
As based on the sinpi and cospi functions from SciPy, see:
- https://github.com/scipy/scipy/blob/v1.14.0/scipy/special/special/cephes/trig.h
"""
x = jnp.abs(x)
# define s =... |
Accurate evaluation of sin(pi * x**2 / 2) and cos(pi * x**2 / 2).
As based on the sinpi and cospi functions from SciPy, see:
- https://github.com/scipy/scipy/blob/v1.14.0/scipy/special/special/cephes/trig.h
| sincospisquaredhalf | python | jax-ml/jax | jax/_src/third_party/scipy/special.py | https://github.com/jax-ml/jax/blob/master/jax/_src/third_party/scipy/special.py | Apache-2.0 |
def fresnel(x: ArrayLike) -> tuple[Array, Array]:
r"""The Fresnel integrals
JAX implementation of :obj:`scipy.special.fresnel`.
The Fresnel integrals are defined as
.. math::
S(x) &= \int_0^x \sin(\pi t^2 /2) dt \\
C(x) &= \int_0^x \cos(\pi t^2 /2) dt.
Args:
x: arraylike, real-valued.
... | The Fresnel integrals
JAX implementation of :obj:`scipy.special.fresnel`.
The Fresnel integrals are defined as
.. math::
S(x) &= \int_0^x \sin(\pi t^2 /2) dt \\
C(x) &= \int_0^x \cos(\pi t^2 /2) dt.
Args:
x: arraylike, real-valued.
Returns:
Arrays containing the values of the Fresn... | fresnel | python | jax-ml/jax | jax/_src/third_party/scipy/special.py | https://github.com/jax-ml/jax/blob/master/jax/_src/third_party/scipy/special.py | Apache-2.0 |
def prepare_lapack_call(fn_base, dtype):
"""Initializes the LAPACK library and returns the LAPACK target name."""
_lapack.initialize()
return build_lapack_fn_target(fn_base, dtype) | Initializes the LAPACK library and returns the LAPACK target name. | prepare_lapack_call | python | jax-ml/jax | jaxlib/lapack.py | https://github.com/jax-ml/jax/blob/master/jaxlib/lapack.py | Apache-2.0 |
def build_lapack_fn_target(fn_base: str, dtype) -> str:
"""Builds the target name for a LAPACK function custom call."""
try:
prefix = (
LAPACK_DTYPE_PREFIX.get(dtype, None) or LAPACK_DTYPE_PREFIX[dtype.type]
)
return f"lapack_{prefix}{fn_base}"
except KeyError as err:
raise NotImplementedE... | Builds the target name for a LAPACK function custom call. | build_lapack_fn_target | python | jax-ml/jax | jaxlib/lapack.py | https://github.com/jax-ml/jax/blob/master/jaxlib/lapack.py | Apache-2.0 |
def import_from_plugin(
plugin_name: str, submodule_name: str, *, check_version: bool = True
) -> ModuleType | None:
"""Import a submodule from a known plugin with version checking.
Args:
plugin_name: The name of the plugin. The supported values are "cuda" or
"rocm".
submodule_name: The name of t... | Import a submodule from a known plugin with version checking.
Args:
plugin_name: The name of the plugin. The supported values are "cuda" or
"rocm".
submodule_name: The name of the submodule to import, e.g. "_triton".
check_version: Whether to check that the plugin version is compatible with
t... | import_from_plugin | python | jax-ml/jax | jaxlib/plugin_support.py | https://github.com/jax-ml/jax/blob/master/jaxlib/plugin_support.py | Apache-2.0 |
def make_c_api_client(
plugin_name: str,
options: _NameValueMapping | None = None,
distributed_client: _xla.DistributedRuntimeClient | None = None,
):
"""Creates a PJRT C API client for a PJRT plugin.
It is required that load_pjrt_plugin_dynamically is called once with the same
plugin_name before thi... | Creates a PJRT C API client for a PJRT plugin.
It is required that load_pjrt_plugin_dynamically is called once with the same
plugin_name before this method is called.
Args:
plugin_name: the name of the PJRT plugin.
options: extra platform-specific options.
distributed_client: distributed client.
... | make_c_api_client | python | jax-ml/jax | jaxlib/xla_client.py | https://github.com/jax-ml/jax/blob/master/jaxlib/xla_client.py | Apache-2.0 |
def generate_pjrt_gpu_plugin_options() -> _NameValueMapping:
"""Generates the PjRt GPU plugin options.
Returns:
A dictionary of plugin options.
"""
options = {}
options['platform_name'] = 'cuda'
allocator = os.getenv('XLA_PYTHON_CLIENT_ALLOCATOR', 'default').lower()
memory_fraction = os.getenv('XLA_... | Generates the PjRt GPU plugin options.
Returns:
A dictionary of plugin options.
| generate_pjrt_gpu_plugin_options | python | jax-ml/jax | jaxlib/xla_client.py | https://github.com/jax-ml/jax/blob/master/jaxlib/xla_client.py | Apache-2.0 |
def register_custom_call_target(
name: str,
fn: Any,
platform: str = 'cpu',
api_version: int = 0,
traits: CustomCallTargetTraits = CustomCallTargetTraits.DEFAULT,
) -> None:
"""Registers a custom call target.
Args:
name: bytes containing the name of the function.
fn: a PyCapsule object ... | Registers a custom call target.
Args:
name: bytes containing the name of the function.
fn: a PyCapsule object containing the function pointer.
platform: the target platform.
api_version: the XLA FFI version to use. Supported versions are: 0 for the
untyped FFI and 1 for the typed FFI.
trait... | register_custom_call_target | python | jax-ml/jax | jaxlib/xla_client.py | https://github.com/jax-ml/jax/blob/master/jaxlib/xla_client.py | Apache-2.0 |
def register_custom_call_handler(
platform: str, handler: CustomCallHandler
) -> None:
"""Registers a custom handler and use it to register existing custom calls.
If a custom call handler for the platform already exist, calling this method
is a no-op and it will not register a new handler.
Args:
platf... | Registers a custom handler and use it to register existing custom calls.
If a custom call handler for the platform already exist, calling this method
is a no-op and it will not register a new handler.
Args:
platform: the target platform.
handler: the function to register a custom call.
| register_custom_call_handler | python | jax-ml/jax | jaxlib/xla_client.py | https://github.com/jax-ml/jax/blob/master/jaxlib/xla_client.py | Apache-2.0 |
def register_custom_type_id(
type_name: str,
type_id: Any,
platform: str = 'cpu',
) -> None:
"""Register a custom type id for use with the FFI.
Args:
type_name: a unique name for the type.
type_id: a PyCapsule object containing a pointer to the ``ffi::TypeId``.
platform: the target platform... | Register a custom type id for use with the FFI.
Args:
type_name: a unique name for the type.
type_id: a PyCapsule object containing a pointer to the ``ffi::TypeId``.
platform: the target platform.
| register_custom_type_id | python | jax-ml/jax | jaxlib/xla_client.py | https://github.com/jax-ml/jax/blob/master/jaxlib/xla_client.py | Apache-2.0 |
def register_custom_type_id_handler(
platform: str, handler: CustomTypeIdHandler
) -> None:
"""Register a custom type id handler and use it to register existing type ids.
If a custom type id handler for the platform already exist, calling this
method is a no-op and it will not register a new handler.
Args... | Register a custom type id handler and use it to register existing type ids.
If a custom type id handler for the platform already exist, calling this
method is a no-op and it will not register a new handler.
Args:
platform: the target platform.
handler: the function to register a custom type id.
| register_custom_type_id_handler | python | jax-ml/jax | jaxlib/xla_client.py | https://github.com/jax-ml/jax/blob/master/jaxlib/xla_client.py | Apache-2.0 |
def tracebacks(enabled=True):
"""Context manager that enables or disables traceback collection."""
saved = Traceback.enabled
Traceback.enabled = enabled
try:
yield
finally:
Traceback.enabled = saved | Context manager that enables or disables traceback collection. | tracebacks | python | jax-ml/jax | jaxlib/xla_client.py | https://github.com/jax-ml/jax/blob/master/jaxlib/xla_client.py | Apache-2.0 |
def prepare_wheel_cuda(
wheel_sources_path: pathlib.Path, *, cpu, cuda_version, wheel_sources
):
"""Assembles a source tree for the cuda kernel wheel in `wheel_sources_path`."""
source_file_prefix = build_utils.get_source_file_prefix(wheel_sources)
wheel_sources_map = build_utils.create_wheel_sources_map(
... | Assembles a source tree for the cuda kernel wheel in `wheel_sources_path`. | prepare_wheel_cuda | python | jax-ml/jax | jaxlib/tools/build_gpu_kernels_wheel.py | https://github.com/jax-ml/jax/blob/master/jaxlib/tools/build_gpu_kernels_wheel.py | Apache-2.0 |
def prepare_wheel_rocm(
wheel_sources_path: pathlib.Path, *, cpu, rocm_version, wheel_sources
):
"""Assembles a source tree for the rocm kernel wheel in `wheel_sources_path`."""
source_file_prefix = build_utils.get_source_file_prefix(wheel_sources)
wheel_sources_map = build_utils.create_wheel_sources_map(
... | Assembles a source tree for the rocm kernel wheel in `wheel_sources_path`. | prepare_wheel_rocm | python | jax-ml/jax | jaxlib/tools/build_gpu_kernels_wheel.py | https://github.com/jax-ml/jax/blob/master/jaxlib/tools/build_gpu_kernels_wheel.py | Apache-2.0 |
def prepare_cuda_plugin_wheel(
wheel_sources_path: pathlib.Path, *, cpu, cuda_version, wheel_sources
):
"""Assembles a source tree for the wheel in `wheel_sources_path`"""
source_file_prefix = build_utils.get_source_file_prefix(wheel_sources)
wheel_sources_map = build_utils.create_wheel_sources_map(
whe... | Assembles a source tree for the wheel in `wheel_sources_path` | prepare_cuda_plugin_wheel | python | jax-ml/jax | jaxlib/tools/build_gpu_plugin_wheel.py | https://github.com/jax-ml/jax/blob/master/jaxlib/tools/build_gpu_plugin_wheel.py | Apache-2.0 |
def prepare_rocm_plugin_wheel(
wheel_sources_path: pathlib.Path, *, cpu, rocm_version, wheel_sources
):
"""Assembles a source tree for the ROCm wheel in `wheel_sources_path`."""
source_file_prefix = build_utils.get_source_file_prefix(wheel_sources)
wheel_sources_map = build_utils.create_wheel_sources_map(
... | Assembles a source tree for the ROCm wheel in `wheel_sources_path`. | prepare_rocm_plugin_wheel | python | jax-ml/jax | jaxlib/tools/build_gpu_plugin_wheel.py | https://github.com/jax-ml/jax/blob/master/jaxlib/tools/build_gpu_plugin_wheel.py | Apache-2.0 |
def create_wheel_sources_map(wheel_sources, root_packages):
"""Returns a map of paths relative to the root package to the full paths."""
wheel_sources_map = {}
if not wheel_sources:
return wheel_sources_map
for source in wheel_sources:
for package in root_packages:
if source.startswith("{}/".forma... | Returns a map of paths relative to the root package to the full paths. | create_wheel_sources_map | python | jax-ml/jax | jaxlib/tools/build_utils.py | https://github.com/jax-ml/jax/blob/master/jaxlib/tools/build_utils.py | Apache-2.0 |
def verify_mac_libraries_dont_reference_chkstack(
runfiles=None, wheel_sources_map=None
):
"""Verifies that _jax.so doesn't depend on ____chkstk_darwin.
We don't entirely know why this happens, but in some build environments
we seem to target the wrong Mac OS version.
https://github.com/jax-ml/jax/issues/3... | Verifies that _jax.so doesn't depend on ____chkstk_darwin.
We don't entirely know why this happens, but in some build environments
we seem to target the wrong Mac OS version.
https://github.com/jax-ml/jax/issues/3867
This check makes sure we don't release wheels that have this dependency.
| verify_mac_libraries_dont_reference_chkstack | python | jax-ml/jax | jaxlib/tools/build_wheel.py | https://github.com/jax-ml/jax/blob/master/jaxlib/tools/build_wheel.py | Apache-2.0 |
def prepare_wheel(wheel_sources_path: pathlib.Path, *, cpu, wheel_sources):
"""Assembles a source tree for the wheel in `wheel_sources_path`."""
source_file_prefix = build_utils.get_source_file_prefix(wheel_sources)
# The wheel sources provided by the transitive rules might have different path
# prefixes, so we... | Assembles a source tree for the wheel in `wheel_sources_path`. | prepare_wheel | python | jax-ml/jax | jaxlib/tools/build_wheel.py | https://github.com/jax-ml/jax/blob/master/jaxlib/tools/build_wheel.py | Apache-2.0 |
def _version_check(name: str,
get_version,
get_build_version,
scale_for_comparison: int = 1,
min_supported_version: int = 0):
"""Checks the runtime CUDA component version against the JAX one.
Args:
name: Of the CUDA compo... | Checks the runtime CUDA component version against the JAX one.
Args:
name: Of the CUDA component.
get_version: A function to get the local runtime version of the component.
get_build_version: A function to get the build version of the component.
scale_for_comparison: For rounding down a ver... | _version_check | python | jax-ml/jax | jax_plugins/cuda/__init__.py | https://github.com/jax-ml/jax/blob/master/jax_plugins/cuda/__init__.py | Apache-2.0 |
def compute_recall(result_neighbors, ground_truth_neighbors) -> float:
"""Computes the recall of an approximate nearest neighbor search.
Args:
result_neighbors: int32 numpy array of the shape [num_queries,
neighbors_per_query] where the values are the indices of the dataset.
ground_truth_neighbors: i... | Computes the recall of an approximate nearest neighbor search.
Args:
result_neighbors: int32 numpy array of the shape [num_queries,
neighbors_per_query] where the values are the indices of the dataset.
ground_truth_neighbors: int32 numpy array of with shape [num_queries,
ground_truth_neighbors_pe... | compute_recall | python | jax-ml/jax | tests/ann_test.py | https://github.com/jax-ml/jax/blob/master/tests/ann_test.py | Apache-2.0 |
def test_jvp_jit_cached(self):
"""Bug in caching in presence of JVP and JIT."""
def func(x):
def inner(y):
return y * x
# Must have two calls to the inner jit (the second one hits the cache)
res1 = api.jit(inner)(4.)
res2 = api.jit(inner)(5.)
return res1 + res2
self.... | Bug in caching in presence of JVP and JIT. | test_jvp_jit_cached | python | jax-ml/jax | tests/api_test.py | https://github.com/jax-ml/jax/blob/master/tests/api_test.py | Apache-2.0 |
def call_kernel_3d(
kernel,
grid: tuple[int, int],
*args
):
"""Calls a kernel over a 3D grid and concatenates results to a single array."""
depth, rows, cols = grid
return jnp.concatenate([
jnp.concatenate([
jnp.concatenate([
jnp.array(kernel((i, j, k), *args))
... | Calls a kernel over a 3D grid and concatenates results to a single array. | call_kernel_3d | python | jax-ml/jax | tests/blocked_sampler_test.py | https://github.com/jax-ml/jax/blob/master/tests/blocked_sampler_test.py | Apache-2.0 |
def testUpperOnes(self, shape, dtype):
"""A test with a (mildly) ill-conditioned matrix."""
if dtype is jnp.float64 and not config.enable_x64.value:
self.skipTest("Test disabled for x32 mode")
r_upper = jnp.triu(jnp.ones(shape)).astype(dtype)
w = jnp.arange(1, shape[0] + 1).astype(dtype)
new_m... | A test with a (mildly) ill-conditioned matrix. | testUpperOnes | python | jax-ml/jax | tests/cholesky_update_test.py | https://github.com/jax-ml/jax/blob/master/tests/cholesky_update_test.py | Apache-2.0 |
def test_custom_linear_solve_pytree(self):
"""Test custom linear solve with inputs and outputs that are pytrees."""
def unrolled_matvec(mat, x):
"""Apply a Python list of lists of scalars to a list of scalars."""
result = []
for i in range(len(mat)):
v = 0
for j in range(len(x... | Test custom linear solve with inputs and outputs that are pytrees. | test_custom_linear_solve_pytree | python | jax-ml/jax | tests/custom_linear_solve_test.py | https://github.com/jax-ml/jax/blob/master/tests/custom_linear_solve_test.py | Apache-2.0 |
def unrolled_matvec(mat, x):
"""Apply a Python list of lists of scalars to a list of scalars."""
result = []
for i in range(len(mat)):
v = 0
for j in range(len(x)):
if mat[i][j] is not None:
v += mat[i][j] * x[j]
result.append(v)
return result | Apply a Python list of lists of scalars to a list of scalars. | unrolled_matvec | python | jax-ml/jax | tests/custom_linear_solve_test.py | https://github.com/jax-ml/jax/blob/master/tests/custom_linear_solve_test.py | Apache-2.0 |
def unrolled_substitution_solve(matvec, b, lower_tri):
"""Solve a triangular unrolled system with fwd/back substitution."""
zero = jnp.zeros(())
one = jnp.ones(())
x = [zero for _ in b]
ordering = range(len(b)) if lower_tri else range(len(b) - 1, -1, -1)
for i in ordering:
re... | Solve a triangular unrolled system with fwd/back substitution. | unrolled_substitution_solve | python | jax-ml/jax | tests/custom_linear_solve_test.py | https://github.com/jax-ml/jax/blob/master/tests/custom_linear_solve_test.py | Apache-2.0 |
def _get_output_set(output, num_lines):
"""Return a set of strings where each string is num_lines."""
output = output().strip().split("\n")
return {
"\n".join(output[i : i + num_lines])
for i in range(0, len(output), num_lines)
} | Return a set of strings where each string is num_lines. | _get_output_set | python | jax-ml/jax | tests/debugging_primitives_test.py | https://github.com/jax-ml/jax/blob/master/tests/debugging_primitives_test.py | Apache-2.0 |
def _collect_jaxprs(jaxpr: core.Jaxpr,
acc: list[core.Jaxpr] | None = None) -> list[core.Jaxpr]:
"""Collect all Jaxprs in a depth-first order."""
if acc is None: acc = []
acc.append(jaxpr)
for e in jaxpr.eqns:
# Take first the block mapping Jaxprs
if e.primitive.name == "pallas_call"... | Collect all Jaxprs in a depth-first order. | _collect_jaxprs | python | jax-ml/jax | tests/debug_info_test.py | https://github.com/jax-ml/jax/blob/master/tests/debug_info_test.py | Apache-2.0 |
def _check_tracers_and_jaxprs(self, traceable: Any,
*args,
expected_jaxpr_debug_infos: list[str | re.Pattern],
tracer_spy: TracerSpy | None = None,
expected_tracer_debug_infos: list[str | re.P... | Checks the expected debug info in all jaxprs, in spied tracers, and StableHLO.
`traceable` will be traced as `traceable.trace(*args, **kwargs)` if it has
a `trace` method (for jit), or will be called as `traceable(*args, **kwargs)`
otherwise (for eager). We collect all the nested Jaxprs, either from
th... | _check_tracers_and_jaxprs | python | jax-ml/jax | tests/debug_info_test.py | https://github.com/jax-ml/jax/blob/master/tests/debug_info_test.py | Apache-2.0 |
def testObservedPromotionTable(self):
"""Test that the weak & strong dtype promotion table does not change over time."""
# Note: * here refers to weakly-typed values
typecodes = \
['b1','u1','u2','u4','u8','i1','i2','i4','i8','bf','f2','f4','f8','c4','c8','i*','f*','c*']
if config.enable_x64.val... | Test that the weak & strong dtype promotion table does not change over time. | testObservedPromotionTable | python | jax-ml/jax | tests/dtypes_test.py | https://github.com/jax-ml/jax/blob/master/tests/dtypes_test.py | Apache-2.0 |
def testBinaryPromotionJitInvariance(self, xtype, ytype, xfun, yfun):
"""Test jit invariance of simple binary promotion rules with and without weak types."""
f = lambda x, y: xfun(x) + yfun(y)
args_maker = lambda: [xtype(1), ytype(1)]
self._CompileAndCheck(f, args_maker, check_dtypes=True) | Test jit invariance of simple binary promotion rules with and without weak types. | testBinaryPromotionJitInvariance | python | jax-ml/jax | tests/dtypes_test.py | https://github.com/jax-ml/jax/blob/master/tests/dtypes_test.py | Apache-2.0 |
def test_custom_call_coverage(self):
"""Tests that the back compat tests cover all the targets declared stable."""
targets_to_cover = set(_export._CUSTOM_CALL_TARGETS_GUARANTEED_STABLE)
cpu_ffi_testdatas = [
cpu_cholesky_lapack_potrf.data_2024_05_31,
cpu_qr_lapack_geqrf.data_2025_04_02,
... | Tests that the back compat tests cover all the targets declared stable. | test_custom_call_coverage | python | jax-ml/jax | tests/export_back_compat_test.py | https://github.com/jax-ml/jax/blob/master/tests/export_back_compat_test.py | Apache-2.0 |
def get_exported(fun: Callable, vjp_order=0,
**export_kwargs) -> Callable[[...], export.Exported]:
"""Like export.export but with serialization + deserialization."""
def serde_exported(*fun_args, **fun_kwargs):
exp = export.export(fun, **export_kwargs)(*fun_args, **fun_kwargs)
if CAN_SERIAL... | Like export.export but with serialization + deserialization. | get_exported | python | jax-ml/jax | tests/export_test.py | https://github.com/jax-ml/jax/blob/master/tests/export_test.py | Apache-2.0 |
def _create_array_cycle():
"""Creates a reference cycle of two jax.Arrays."""
n1 = jnp.ones((2, 2))
n2 = jnp.zeros((2, 2))
n1.next = n2
n2.next = n1
return weakref.ref(n1) | Creates a reference cycle of two jax.Arrays. | _create_array_cycle | python | jax-ml/jax | tests/garbage_collection_guard_test.py | https://github.com/jax-ml/jax/blob/master/tests/garbage_collection_guard_test.py | Apache-2.0 |
def testWhileTypeErrors(self):
"""Test typing error messages for while."""
tuple_treedef = jax.tree.structure((1., 1.))
leaf_treedef = jax.tree.structure(0.)
with self.assertRaisesRegex(
TypeError,
re.escape(f"cond_fun must return a boolean scalar, but got pytree {tuple_treedef}.")):
... | Test typing error messages for while. | testWhileTypeErrors | python | jax-ml/jax | tests/lax_control_flow_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_control_flow_test.py | Apache-2.0 |
def test_fori_loop_supports_unrolling(self):
"""Test that we can unroll static fori_loops."""
body = lambda i, c: c + 1
init = jnp.float32(10)
result = lax.fori_loop(np.int16(0), 10, body, init,
unroll=3)
self.assertEqual(result, init + 10)
result = lax.fori_loop(0, ... | Test that we can unroll static fori_loops. | test_fori_loop_supports_unrolling | python | jax-ml/jax | tests/lax_control_flow_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_control_flow_test.py | Apache-2.0 |
def test_fori_loop_with_dynamic_indices_cannot_unroll(self):
"""Test that we can't unroll dynamic fori_loops."""
body = lambda i, c: c + 1
init = jnp.float32(10)
@jax.jit
def f(upper):
return lax.fori_loop(np.int16(0), upper, body, init,
unroll=3)
with self.ass... | Test that we can't unroll dynamic fori_loops. | test_fori_loop_with_dynamic_indices_cannot_unroll | python | jax-ml/jax | tests/lax_control_flow_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_control_flow_test.py | Apache-2.0 |
def test_fori_loop_returns_init_with_nonpositive_length(
self, jit, upper, unroll
):
"""Test that `length <= 0` behaves like Python `range`."""
fori_loop_with_static_upper_and_lower = partial(
lax.fori_loop, 0, upper, lambda i, c: c + 1, unroll=unroll
)
if jit:
fori_loop_with_stati... | Test that `length <= 0` behaves like Python `range`. | test_fori_loop_returns_init_with_nonpositive_length | python | jax-ml/jax | tests/lax_control_flow_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_control_flow_test.py | Apache-2.0 |
def testCondTypeErrors(self):
"""Test typing error messages for cond."""
with self.assertRaisesRegex(TypeError,
re.escape("Pred type must be either boolean or number, got <function")):
lax.cond(lambda x: True, lambda top: 2., lambda fop: 3., 1.)
with self.assertRaisesRegex(TypeError,
... | Test typing error messages for cond. | testCondTypeErrors | python | jax-ml/jax | tests/lax_control_flow_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_control_flow_test.py | Apache-2.0 |
def testSwitchErrors(self):
"""Test typing error messages for switch."""
with self.assertRaisesRegex(TypeError,
re.escape("Index type must be an integer, got <function")):
lax.switch(lambda x: True, [lambda _: 2., lambda _: 3.], 1.)
with self.assertRaisesRegex(TypeError,
re.escape("Ind... | Test typing error messages for switch. | testSwitchErrors | python | jax-ml/jax | tests/lax_control_flow_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_control_flow_test.py | Apache-2.0 |
def testNonScalarRepeats(self, fixed_size):
'''
Following numpy test suite from `test_repeat` at
https://github.com/numpy/numpy/blob/main/numpy/core/tests/test_multiarray.py
'''
tol = 1e-5
def test_single(m, args_maker, repeats, axis):
lax_ans = jnp.repeat(m, repeats, axis)
numpy_an... |
Following numpy test suite from `test_repeat` at
https://github.com/numpy/numpy/blob/main/numpy/core/tests/test_multiarray.py
| testNonScalarRepeats | python | jax-ml/jax | tests/lax_metal_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_metal_test.py | Apache-2.0 |
def testIssue2330(self):
'''
Make sure return value of jnp.concatenate is a jax.ndarray and is side-effect save
'''
def attempt_sideeffect(x):
x = [x]
x = jnp.concatenate(x)
x -= 1.
return x
np_input = np.ones(1)
jnp_input = jnp.ones(1)
expected_np_input_after_call =... |
Make sure return value of jnp.concatenate is a jax.ndarray and is side-effect save
| testIssue2330 | python | jax-ml/jax | tests/lax_metal_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_metal_test.py | Apache-2.0 |
def args_maker():
"""Test the set of inputs np.geomspace is well-defined on."""
start, stop = self._GetArgsMaker(rng,
[start_shape, stop_shape],
[dtype, dtype])()
# np.geomspace can't handle differently ranked tensors
# w. negative ... | Test the set of inputs np.geomspace is well-defined on. | args_maker | python | jax-ml/jax | tests/lax_metal_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_metal_test.py | Apache-2.0 |
def arrays_with_overlapping_values(rng, shapes, dtypes, unique=False, overlap=0.5) -> list[jax.Array]:
"""Generate multiple arrays with some overlapping values.
This is useful for tests of set-like operations.
"""
assert 0 <= overlap <= 1
sizes = [math.prod(jtu._dims_of_shape(shape)) for shape in shapes]
t... | Generate multiple arrays with some overlapping values.
This is useful for tests of set-like operations.
| arrays_with_overlapping_values | python | jax-ml/jax | tests/lax_numpy_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_numpy_test.py | Apache-2.0 |
def testWrappedSignaturesMatch(self):
"""Test that jax.numpy function signatures match numpy."""
# NumPy functions explicitly not implemented in JAX:
skip = {'array2string',
'asanyarray',
'asarray_chkfinite',
'ascontiguousarray',
'asfortranarray',
... | Test that jax.numpy function signatures match numpy. | testWrappedSignaturesMatch | python | jax-ml/jax | tests/lax_numpy_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_numpy_test.py | Apache-2.0 |
def _all_numpy_ufuncs() -> Iterator[str]:
"""Generate the names of all ufuncs in the top-level numpy namespace."""
for name in dir(np):
f = getattr(np, name)
if isinstance(f, np.ufunc) and name not in UNIMPLEMENTED_UFUNCS:
yield name | Generate the names of all ufuncs in the top-level numpy namespace. | _all_numpy_ufuncs | python | jax-ml/jax | tests/lax_numpy_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_numpy_test.py | Apache-2.0 |
def _dtypes_for_ufunc(name: str) -> Iterator[tuple[str, ...]]:
"""Generate valid dtypes of inputs to the given numpy ufunc."""
func = getattr(np, name)
for arg_dtypes in itertools.product(_available_numpy_dtypes, repeat=func.nin):
args = (np.ones(1, dtype=dtype) for dtype in arg_dtypes)
try:
with jt... | Generate valid dtypes of inputs to the given numpy ufunc. | _dtypes_for_ufunc | python | jax-ml/jax | tests/lax_numpy_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_numpy_test.py | Apache-2.0 |
def _fetch_preconditioner(self, preconditioner, A, rng=None):
"""
Returns one of various preconditioning matrices depending on the identifier
`preconditioner' and the input matrix A whose inverse it supposedly
approximates.
"""
if preconditioner == 'identity':
M = np.eye(A.shape[0], dtype=... |
Returns one of various preconditioning matrices depending on the identifier
`preconditioner' and the input matrix A whose inverse it supposedly
approximates.
| _fetch_preconditioner | python | jax-ml/jax | tests/lax_scipy_sparse_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_scipy_sparse_test.py | Apache-2.0 |
def test_gmres_arnoldi_step(self, shape, dtype, preconditioner):
"""
The Arnoldi decomposition within GMRES is correct.
"""
if not config.enable_x64.value:
raise unittest.SkipTest("requires x64 mode")
rng = jtu.rand_default(self.rng())
A = rng(shape, dtype)
M = self._fetch_preconditio... |
The Arnoldi decomposition within GMRES is correct.
| test_gmres_arnoldi_step | python | jax-ml/jax | tests/lax_scipy_sparse_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_scipy_sparse_test.py | Apache-2.0 |
def testIssue13267(self):
"""Tests betaln(x, 1) across wide range of x."""
xs = jnp.geomspace(1, 1e30, 1000)
primals_out, tangents_out = jax.jvp(lsp_special.betaln, primals=[xs, 1.0], tangents=[jnp.ones_like(xs), 0.0])
# Check that betaln(x, 1) = -log(x).
# Betaln is still not perfect for small valu... | Tests betaln(x, 1) across wide range of x. | testIssue13267 | python | jax-ml/jax | tests/lax_scipy_test.py | https://github.com/jax-ml/jax/blob/master/tests/lax_scipy_test.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.