Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: special: add log_wright_bessel #20646

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 24 additions & 23 deletions scipy/special/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,30 @@
.. autosummary::
:toctree: generated/

jv -- Bessel function of the first kind of real order and \
complex argument.
jve -- Exponentially scaled Bessel function of order `v`.
yn -- Bessel function of the second kind of integer order and \
real argument.
yv -- Bessel function of the second kind of real order and \
complex argument.
yve -- Exponentially scaled Bessel function of the second kind \
of real order.
kn -- Modified Bessel function of the second kind of integer \
order `n`
kv -- Modified Bessel function of the second kind of real order \
`v`
kve -- Exponentially scaled modified Bessel function of the \
second kind.
iv -- Modified Bessel function of the first kind of real order.
ive -- Exponentially scaled modified Bessel function of the \
first kind.
hankel1 -- Hankel function of the first kind.
hankel1e -- Exponentially scaled Hankel function of the first kind.
hankel2 -- Hankel function of the second kind.
hankel2e -- Exponentially scaled Hankel function of the second kind.
wright_bessel -- Wright's generalized Bessel function.
jv -- Bessel function of the first kind of real order and \
complex argument.
jve -- Exponentially scaled Bessel function of order `v`.
yn -- Bessel function of the second kind of integer order and \
real argument.
yv -- Bessel function of the second kind of real order and \
complex argument.
yve -- Exponentially scaled Bessel function of the second kind \
of real order.
kn -- Modified Bessel function of the second kind of integer \
order `n`
kv -- Modified Bessel function of the second kind of real order \
`v`
kve -- Exponentially scaled modified Bessel function of the \
second kind.
iv -- Modified Bessel function of the first kind of real order.
ive -- Exponentially scaled modified Bessel function of the \
first kind.
hankel1 -- Hankel function of the first kind.
hankel1e -- Exponentially scaled Hankel function of the first kind.
hankel2 -- Hankel function of the second kind.
hankel2e -- Exponentially scaled Hankel function of the second kind.
wright_bessel -- Wright's generalized Bessel function.
log_wright_bessel -- Logarithm of Wright's generalized Bessel function.

The following function does not accept NumPy arrays (it is not a
universal function):
Expand Down
12 changes: 6 additions & 6 deletions scipy/special/_generate_pyx.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@
'hankel1e', 'hankel2', 'hankel2e', 'hyp2f1', 'it2i0k0', 'it2j0y0', 'it2struve0',
'itairy', 'iti0k0', 'itj0y0', 'itmodstruve0', 'itstruve0', 'iv', 'ive', 'jv',
'jve', 'kei', 'keip', 'kelvin', 'ker', 'kerp', 'kv', 'kve', 'log_expit',
'loggamma', 'logit', 'mathieu_a', 'mathieu_b', 'mathieu_cem', 'mathieu_modcem1',
'mathieu_modcem2', 'mathieu_modsem1', 'mathieu_modsem2', 'mathieu_sem',
'modfresnelm', 'modfresnelp', 'obl_ang1', 'obl_ang1_cv', 'obl_cv', 'obl_rad1',
'obl_rad1_cv', 'obl_rad2', 'obl_rad2_cv', 'pbdv', 'pbvv', 'pbwa', 'pro_ang1',
'pro_ang1_cv', 'pro_cv', 'pro_rad1', 'pro_rad1_cv', 'pro_rad2', 'pro_rad2_cv',
'psi', 'rgamma', 'sph_harm', 'wright_bessel', 'yv', 'yve', '_zeta'
'log_wright_bessel', 'loggamma', 'logit', 'mathieu_a', 'mathieu_b', 'mathieu_cem',
'mathieu_modcem1', 'mathieu_modcem2', 'mathieu_modsem1', 'mathieu_modsem2',
'mathieu_sem', 'modfresnelm', 'modfresnelp', 'obl_ang1', 'obl_ang1_cv', 'obl_cv',
'obl_rad1', 'obl_rad1_cv', 'obl_rad2', 'obl_rad2_cv', 'pbdv', 'pbvv', 'pbwa',
'pro_ang1', 'pro_ang1_cv', 'pro_cv', 'pro_rad1', 'pro_rad1_cv', 'pro_rad2',
'pro_rad2_cv', 'psi', 'rgamma', 'sph_harm', 'wright_bessel', 'yv', 'yve', '_zeta'
]

# -----------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions scipy/special/_special_ufuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ extern const char *lambertw_doc;
extern const char *logit_doc;
extern const char *loggamma_doc;
extern const char *log_expit_doc;
extern const char *log_wright_bessel_doc;
extern const char *mathieu_a_doc;
extern const char *mathieu_b_doc;
extern const char *mathieu_cem_doc;
Expand Down Expand Up @@ -480,6 +481,12 @@ PyMODINIT_FUNC PyInit__special_ufuncs() {
);
PyModule_AddObjectRef(_special_ufuncs, "log_expit", log_expit);

PyObject *log_wright_bessel = SpecFun_NewUFunc(
{static_cast<func_ddd_d_t>(special::log_wright_bessel), static_cast<func_fff_f_t>(special::log_wright_bessel)},
"log_wright_bessel", log_wright_bessel_doc
);
PyModule_AddObjectRef(_special_ufuncs, "log_wright_bessel", log_wright_bessel);

PyObject *logit = SpecFun_NewUFunc(
{static_cast<func_d_d_t>(special::logit), static_cast<func_f_f_t>(special::logit),
static_cast<func_g_g_t>(special::logit)},
Expand Down
39 changes: 39 additions & 0 deletions scipy/special/_special_ufuncs_docs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2754,6 +2754,43 @@ const char *log_expit_doc = R"(
lose all precision and return 0.
)";

const char *log_wright_bessel_doc = R"(
log_wright_bessel(a, b, x, out=None)

Natural logarithm of Wright's generalized Bessel function, see `wright_bessel`.
This function comes in handy in particular for large values of x.

Parameters
----------
a : array_like of float
a >= 0
b : array_like of float
b >= 0
x : array_like of float
x >= 0
out : ndarray, optional
Optional output array for the function results

Returns
-------
scalar or ndarray
Value of the logarithm of Wright's generalized Bessel function

Notes
-----
Due to the complexity of the function with its three parameters, only
non-negative arguments are implemented.

.. versionadded:: 1.14.0

Examples
--------
>>> from scipy.special import log_wright_bessel
>>> a, b, x = 1.5, 1.1, 2.5
>>> log_wright_bessel(a, b, x)
1.1947654935299217
)";

const char *mathieu_a_doc = R"(
mathieu_a(m, q, out=None)

Expand Down Expand Up @@ -3900,6 +3937,8 @@ const char *wright_bessel_doc = R"(
Due to the complexity of the function with its three parameters, only
non-negative arguments are implemented.

.. versionadded:: 1.7.0

References
----------
.. [1] Digital Library of Mathematical Functions, 10.46.
Expand Down
2 changes: 2 additions & 0 deletions scipy/special/_ufuncs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ __all__ = [
'log1p',
'log_expit',
'log_ndtr',
'log_wright_bessel',
'loggamma',
'logit',
'lpmv',
Expand Down Expand Up @@ -432,6 +433,7 @@ kve: np.ufunc
log1p: np.ufunc
log_expit: np.ufunc
log_ndtr: np.ufunc
log_wright_bessel: np.ufunc
loggamma: np.ufunc
logit: np.ufunc
lpmv: np.ufunc
Expand Down
1 change: 1 addition & 0 deletions scipy/special/cython_special.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,5 @@ cpdef Dd_number_t yv(double x0, Dd_number_t x1) noexcept nogil
cpdef Dd_number_t yve(double x0, Dd_number_t x1) noexcept nogil
cpdef double zetac(double x0) noexcept nogil
cpdef double wright_bessel(double x0, double x1, double x2) noexcept nogil
cpdef double log_wright_bessel(double x0, double x1, double x2) noexcept nogil
cpdef double ndtri_exp(double x0) noexcept nogil
9 changes: 9 additions & 0 deletions scipy/special/cython_special.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,10 @@ Available functions

double wright_bessel(double, double, double)

- :py:func:`~scipy.special.log_wright_bessel`::

double log_wright_bessel(double, double, double)

- :py:func:`~scipy.special.ndtri_exp`::

double ndtri_exp(double)
Expand Down Expand Up @@ -1261,6 +1265,7 @@ cdef extern from r"special_wrappers.h":
double _func_cephes_iv_wrap "cephes_iv_wrap"(double, double) nogil

npy_double special_wright_bessel(npy_double, npy_double, npy_double) nogil
npy_double special_log_wright_bessel(npy_double, npy_double, npy_double) nogil
double special_ellipk(double m) nogil

double cephes_besselpoly(double a, double lmbda, double nu) nogil
Expand Down Expand Up @@ -3508,6 +3513,10 @@ cpdef double wright_bessel(double x0, double x1, double x2) noexcept nogil:
"""See the documentation for scipy.special.wright_bessel"""
return special_wright_bessel(x0, x1, x2)

cpdef double log_wright_bessel(double x0, double x1, double x2) noexcept nogil:
"""See the documentation for scipy.special.log_wright_bessel"""
return special_log_wright_bessel(x0, x1, x2)

cpdef double ndtri_exp(double x0) noexcept nogil:
"""See the documentation for scipy.special.ndtri_exp"""
return _func_ndtri_exp(x0)
Expand Down