numpy / numpy/numpy

np.linalg.pinv() hangs for certain np.inf arrangements in the inversed matrix

Open
#7,461 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

component: numpy.linalg
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

If I try to do np.linalg.pinv() of a matrix that contains some np.infs, sometimes the function just hangs with 100% CPU usage, other times it returns something:

In [1]: import numpy as np
In [2]: x = np.array([[550.0, 1], [1, np.inf]])
In [3]: np.linalg.pinv(x)
Out[3]: 
array([[ 0.,  0.],
       [ 0.,  0.]])

In [4]: x = np.array([[np.inf, np.inf], [np.inf, np.inf]])
In [5]: np.linalg.pinv(x)
Out[5]: 
array([[ nan,  nan],
       [ nan,  nan]])

In [6]: x = np.array([[np.inf, np.inf], [550.0, 1]])
In [7]: np.linalg.pinv(x)
Out[7]: 
array([[ nan,  nan],
       [ nan,  nan]])

In [8]: x = np.array([[550.0, 1], [np.inf, np.inf]])
In [9]: np.linalg.pinv(x) # here it just hangs and I must kill it from outside
Killed

I think the correct behaviour should be to raise an exception or return nans or whatever, but definitely not hang.

My configuration:
Ubuntu 15.10

$ uname -srvmpio
Linux 4.2.0-34-generic #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

python version: 3.5.0+
numpy version: 1.10.4
installed via pip in a virtual environment, log of installation: pip-install-numpy.txt
gcc version: gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the np.linalg.pinv() entry point and reproduce the reported 2x2 matrices, especially the case that reaches 100% CPU usage. Check the existing linear-algebra tests for pseudoinverse behavior with non-finite values. Done means the reproducer returns or raises instead of hanging, with regression coverage for the problematic arrangement.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.