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.

assert_equal fails/crashes on empty arrays with large shape

See original GitHub issue
>>> a = np.array([], dtype=np.int64).reshape((6, 10, 6, 10, 0, 5, 1, 9, 10, 2, 6, 2, 6, 0, 10, 9, 5, 1, 5, 1, 10, 3))
>>> np.testing.assert_equal(a, a[()])
python(73392,0x113ae6dc0) malloc: can't allocate region
*** mach_vm_map(size=15746400002048) failed (error code=3)
python(73392,0x113ae6dc0) malloc: *** set a breakpoint in malloc_error_break to debug
python(73392,0x113ae6dc0) malloc: can't allocate region
*** mach_vm_map(size=15746400002048) failed (error code=3)
python(73392,0x113ae6dc0) malloc: *** set a breakpoint in malloc_error_break to debug
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/aaronmeurer/anaconda3/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 349, in assert_equal
    return assert_array_equal(actual, desired, err_msg, verbose)
  File "/Users/aaronmeurer/anaconda3/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 936, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/Users/aaronmeurer/anaconda3/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 770, in assert_array_compare
    flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan')
  File "/Users/aaronmeurer/anaconda3/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 746, in func_assert_same_pos
    raise AssertionError(msg)
AssertionError:
Arrays are not equal

x and y nan location mismatch:
 x: array([], shape=(6, 10, 6, 10, 0, 5, 1, 9, 10, 2, 6, 2, 6, 0, 10, 9, 5, 1, 5, 1, 10, 3),
      dtype=int64)
 y: array([], shape=(6, 10, 6, 10, 0, 5, 1, 9, 10, 2, 6, 2, 6, 0, 10, 9, 5, 1, 5, 1, 10, 3),
      dtype=int64)

I also sometimes get MemoryError from similar examples, for instance, with shape=[7, 2, 6, 10, 6, 10, 0, 5, 1, 9, 10, 2, 6, 2, 6, 0, 10, 9, 5, 1, 5, 1, 10, 3], and even np.all gives warnings from malloc.

>>> a = np.array([], dtype=np.int64).reshape([7, 2, 6, 10, 6, 10, 0, 5, 1, 9, 10, 2, 6, 2, 6, 0, 10, 9, 5, 1, 5, 1, 10, 3])
>>> np.all(a == a[()])
python(77502,0x10cb79dc0) malloc: can't allocate region
*** mach_vm_map(size=220449600000000) failed (error code=3)
python(77502,0x10cb79dc0) malloc: *** set a breakpoint in malloc_error_break to debug
python(77502,0x10cb79dc0) malloc: can't allocate region
*** mach_vm_map(size=220449600000000) failed (error code=3)
python(77502,0x10cb79dc0) malloc: *** set a breakpoint in malloc_error_break to debug
False
>>> np.testing.assert_equal(a, a[()])
python(77502,0x10cb79dc0) malloc: can't allocate region
*** mach_vm_map(size=220449600000000) failed (error code=3)
python(77502,0x10cb79dc0) malloc: *** set a breakpoint in malloc_error_break to debug
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/aaronmeurer/anaconda3/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 349, in assert_equal
    return assert_array_equal(actual, desired, err_msg, verbose)
  File "/Users/aaronmeurer/anaconda3/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 936, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/Users/aaronmeurer/anaconda3/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 770, in assert_array_compare
    flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan')
  File "/Users/aaronmeurer/anaconda3/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 728, in func_assert_same_pos
    x_id = func(x)
MemoryError: Unable to allocate 0 bytes for an array with shape (7, 2, 6, 10, 6, 10, 0, 5, 1, 9, 10, 2, 6, 2, 6, 0, 10, 9, 5, 1, 5, 1, 10, 3) and data type bool

Note:

>>> shape = [7, 2, 6, 10, 6, 10, 0, 5, 1, 9, 10, 2, 6, 2, 6, 0, 10, 9, 5, 1, 5, 1, 10, 3]
>>> np.prod([i for i in shape if i])
220449600000000

It isn’t clear to me if this is the sort of thing that should work. I would expect empty arrays to effectively ignore the nonzero entries in the shape except for broadcasting purposes. But maybe there are technical reasons why this cannot happen?

Numpy/Python version information:

>>> import sys, numpy; print(numpy.__version__, sys.version)
1.18.1 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 15:43:19)
[Clang 4.0.1 (tags/RELEASE_401/final)]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sebergcommented, Jun 8, 2022

Closing, on master numpy tries to allocate less memory so it passes. The main issue here (IMO) was always that we really should not ignore critical errors (or any errors), but gh-21222 tracks those better anyway. (I don’t care too much that about the above failing, but it should not return False silently.)

0reactions
mattipcommented, Mar 15, 2020

Changeset 3e8c2b00ee from gh-7463 no longer used the return value from _array_fill_strides, rather it uses the faulty calculation which skips 0 on line 957

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unittest equality of empty record arrays - python - Stack Overflow
I can only assume unittest.TestCase.assertEqual uses the __eq__ method, which in numpy.ndarray objects, does elementwise equality.
Read more >
JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
The following code prints invalid value in assertEquals() on solaris-sparc with -Xcomp option: public class T { static void assertEquals(Object exp, ...
Read more >
Does Unit-Tested Code Crash? A Case Study of Eclipse - arXiv
Drilling further in the association between code coverage and crashes, we examined the relationship between the covered meth- ods, methods of unit-tested ...
Read more >
Changelog — Python 3.11.1 documentation
gh-94329: Compile and run code with unpacking of extremely large sequences (1000s of elements). Such code failed to compile. It now compiles and...
Read more >
Reading 3: Testing
The space of possible test cases is generally too big to cover ... A real crash ... empty array, or empty set; the...
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