scipy: BUG: scipy.special.stdtri: calling with small `df` crashes kernel
Describe your issue.
For certain distributions in scipy.stats, for very low values of parameters, the kernel crashes.
With other distributions, such low values cause a warning or an exception, which is fine. But with some distributions it simply crashes. It should instead be handled correctly.
Note that all parameters being used are within the domain for that parameter, as shown in the code below.
I originally found this issue with the beta distribution. Before posting I wrote code which looked through all the other distributions to see if it could create a crash with them also. It only managed with the t distribution.
With all other distributions, funny values gives
- a warning like
RuntimeWarning: overflow encountered in [divide/double_scalars/_ncf_ppf/_nct_ppf]
,RuntimeWarning: invalid value encountered in [multiply/divide/add/subtract/double_scalars]
,RuntimeWarning: divide by zero encountered in [divide/log]
,RuntimeWarning: floating point number truncated to an integer
- or an error like
RuntimeError: Failed to converge after 100 iterations.
(forscipy.stats.genexpon(5e-324, 5e-324, 5e-324).ppf(.2)
andscipy.stats.studentized_range(2, 5e-10).ppf(.2)
).
Reproducing Code Example
import scipy.stats
print([shape_param.domain for shape_param in scipy.stats.t._shape_info()])
# [[5e-324, inf]]
print(scipy.stats.t(1e-10).ppf(.2))
# -1e+100
print(scipy.stats.t(1e-20).ppf(.2))
# 1e+100
print(scipy.stats.t(1e-30).ppf(.2))
# KERNEL CRASHES with message: `STOP SMALL, X, BIG not monotone in INVR`
import scipy.stats
print([shape_param.domain for shape_param in scipy.stats.beta._shape_info()])
# [[5e-324, inf], [5e-324, inf]]
print(scipy.stats.beta(a=1e-308, b=5).ppf(.2))
# 0.0
print(scipy.stats.beta(a=1e-309, b=5).ppf(.2))
# OverflowError: Error in function boost::math::tgamma<d>(d): Overflow Error
# (raises error, but kernel doesn't crash)
print(scipy.stats.beta(a=1e-323, b=5).ppf(.2))
# KERNEL CRASHES with message: `Assertion failed: *p_derivative >= 0, file ..\..\scipy\_lib\boost/boost/math/special_functions/beta.hpp, line 739`
Error message
# after print(scipy.stats.t(1e-30).ppf(.2))
STOP SMALL, X, BIG not monotone in INVR
# after print(scipy.stats.beta(a=1e-323, b=5).ppf(.2))
Assertion failed: *p_derivative >= 0, file ..\..\scipy\_lib\boost/boost/math/special_functions/beta.hpp, line 739
SciPy/NumPy/Python version and system information
1.10.1 1.23.1 sys.version_info(major=3, minor=9, micro=4, releaselevel='final', serial=0)
Build Dependencies:
blas:
detection method: pkgconfig
found: true
include directory: c:/opt/openblas/if_32/64/include
lib directory: c:/opt/openblas/if_32/64/lib
name: openblas
openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= PRESCOTT MAX_THREADS=4
pc file directory: c:/opt/openblas/if_32/64/lib/pkgconfig
version: 0.3.18
lapack:
detection method: pkgconfig
found: true
include directory: c:/opt/openblas/if_32/64/include
lib directory: c:/opt/openblas/if_32/64/lib
name: openblas
openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= PRESCOTT MAX_THREADS=4
pc file directory: c:/opt/openblas/if_32/64/lib/pkgconfig
version: 0.3.18
Compilers:
c:
commands: cc
linker: ld.bfd
name: gcc
version: 10.3.0
c++:
commands: c++
linker: ld.bfd
name: gcc
version: 10.3.0
cython:
commands: cython
linker: cython
name: cython
version: 0.29.33
fortran:
commands: gfortran
linker: ld.bfd
name: gcc
version: 10.3.0
pythran:
include directory: C:\Users\runneradmin\AppData\Local\Temp\pip-build-env-u63ta2f1\overlay\Lib\site-packages\pythran
version: 0.12.1
Machine Information:
build:
cpu: x86_64
endian: little
family: x86_64
system: windows
cross-compiled: false
host:
cpu: x86_64
endian: little
family: x86_64
system: windows
Python Information:
path: C:\Users\runneradmin\AppData\Local\Temp\cibw-run-a1px0t3e\cp39-win_amd64\build\venv\Scripts\python.exe
version: '3.9'
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 21 (12 by maintainers)
After #19560 merged on main, I’m getting
Hence at least the
t
part is resolved in the coming v.1.13.