Skip to content

np.linalg.inv with occasional SEGFAULT on macOS #19532

@max3-2

Description

@max3-2

Reproducing code example:

This is hard to provide since it seems to depend on the input quite strongly. I try to describe my issue to pinpoint the direction for building a better MWE. FWIW, the included MWE does perform all the basic tasks , the input is however completely random (x) - in case of the true code it is a genetic algorithm that modifies a fixed input (x) by small tolerances to produce a set of many different x. The MWE however does not reproduce the error.
During a full optimization, there are easily 1e7 calls to np.linalg.inv. I would estimate that every third optimization fail, independent of convergence or progression.

"""
Segfault tester
"""
import numpy as np

while True:
    x = np.random.random((2, 17)) * 1000.  # set of 2D points
    x = np.vstack((x, np.ones((1, np.shape(x)[1])))). # make 'homogeneous'

    m = np.mean(x[:2], axis=1)
    x[0, :] -= m[0]
    x[1, :] -= m[1]

    avdst = np.mean(np.sqrt((x[0, :] ** 2 + x[1, :] ** 2)))
    scale = np.sqrt(2) / avdst

    x[0:2] *= scale

   # This matrix norms the points and adapts the scale
    Tx = np.array([[scale, 0, -scale*m[0]],
                   [0, scale, -scale*m[1]],
                   [0, 0, 1]])
 
   # THIS is where it crashes, the inverse is needed later on
    P = np.linalg.inv(Tx)

Due to the inv call, I added checks for singularity and np.isclose(np.linalg.det(Tx), 0.) to prevent issues to no avail.

Error message:

Fatal Python error: Segmentation fault

Current thread 0x000070000bf94000 (most recent call first):
  File "/usr/local/lib/python3.9/site-packages/numpy/linalg/linalg.py", line 545 in inv
  File "<__array_function__ internals>", line 5 in inv

Any following traceback just runs through my code and does not provide any more information.

NumPy/Python version information:

macOS 11. on an Intel machine! This will not occur on Windows - I have quite some ppl running the code without reporting the issue.

print(numpy.__version__, sys.version)
1.21.1 3.9.6 (default, Jun 29 2021, 05:25:02) 
[Clang 12.0.5 (clang-1205.0.22.9)]
>>> np.__config__.show()
blas_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
    runtime_library_dirs = ['/usr/local/lib']
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
    runtime_library_dirs = ['/usr/local/lib']
lapack_mkl_info:
  NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
    runtime_library_dirs = ['/usr/local/lib']
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
    runtime_library_dirs = ['/usr/local/lib']
Supported SIMD extensions in this NumPy install:
    baseline = SSE,SSE2,SSE3
    found = SSSE3,SSE41,POPCNT,SSE42,AVX,F16C,FMA3,AVX2
    not found = AVX512F,AVX512CD,AVX512_KNL,AVX512_SKX,AVX512_CLX,AVX512_CNL,AVX512_ICL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions