question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

isclose behavior on non-finite complex values seems incorrect

See original GitHub issue

For example:

np.isclose(complex(float('inf'), 0), complex(float('inf'), 0))
: False

np.isclose(complex(1, float('inf')), complex(1, float('nan')), equal_nan=True)
: True

In the first case it seems like the same number should be close to itself, and in the latter case I think the numbers should not be close since NaN is not close to anything.

Python’s cmath.isclose behavior appears to demand that complex numbers containing -inf or inf must be identical to be close. It does not support equal_nan so complex numbers containing NaN are never close to other complex numbers. If equal_nan is True I would expect NaNs to act like infinities and require the numbers be identical to be “close.”

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
anirudh2290commented, Jun 4, 2020

np.isclose(np.array([1 + 2.j]), np.array([2 + 1.j]))

I assume you forgot to replace some number with inf here? The issue is about inf/nan, and I don’t see anything wrong here with the given code snippet.

😄 sorry, my bad.

yes for inf it looks like it will be a breaking change, though i find the following behavior inconsistent in numpy:

>>> np.isclose(np.inf, np.inf)
True
>>> np.isclose(np.inf + 1.j, np.inf + 1.j)
False
0reactions
sebergcommented, Jun 4, 2020

Oh, I had forgotten after all this discussion that the original issue post already mentioned cmath and this behaviour. We need to decide what we think is best, and then open a bpo and maybe document the differences. I personally think the python behaviour with partial complex inf may just be an oversight (although python is in slightly different situations about giving warnings)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Covert Modality in Non-Finite Contexts - ScholarlyCommons
This dissertation investigates the distribution and interpretation of covert modality. Three environments where covert modality appears are analyzed. These ...
Read more >
Why does math.isclose() fail to detect minor differences ...
The above code was run with Python 3.5.2. UPDATE 1: It seems that a similar behavior occurs when using very large float values:...
Read more >
Introduction, split-Infl, etc. The enterprise (reminder)
And, if Agr is transparent (French), no problem, move away. What about the French restriction on nonfinite lexical verb movement to I? Pollock's...
Read more >
Zero-inflated model: non-finite value supplied by optim [closed]
The model with quarter as predictor looks like this: cr_f1c = formula(cr ~ depth + habtype2 + quarter + hurseason + year +...
Read more >
Eigenvalues and eigenvectors - MATLAB eig
Generalized eigenvalue problem input matrix, specified as a square matrix of real or complex values. B must be the same size as A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found