MCPcopy Index your code
hub / github.com/numpy/numpy / test_outer_bad_subclass

Function test_outer_bad_subclass

numpy/_core/tests/test_umath.py:5085–5107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5083 assert actual.__class__.__name__ == 'foo'
5084
5085def test_outer_bad_subclass():
5086 class BadArr1(np.ndarray):
5087 def __array_finalize__(self, obj):
5088 # The outer call reshapes to 3 dims, try to do a bad reshape.
5089 if self.ndim == 3:
5090 self._set_shape(self.shape + (1,))
5091
5092 class BadArr2(np.ndarray):
5093 def __array_finalize__(self, obj):
5094 if isinstance(obj, BadArr2):
5095 # outer inserts 1-sized dims. In that case disturb them.
5096 if self.shape[-1] == 1:
5097 self._set_shape(self.shape[::-1])
5098
5099 for cls in [BadArr1, BadArr2]:
5100 arr = np.ones((2, 3)).view(cls)
5101 with pytest.raises(TypeError):
5102 # The first array gets reshaped (not the second one)
5103 np.add.outer(arr, [1, 2])
5104
5105 # This actually works, since we only see the reshaping error:
5106 arr = np.ones((2, 3)).view(cls)
5107 assert type(np.add.outer([1, 2], arr)) is cls
5108
5109def test_outer_exceeds_maxdims():
5110 deep = np.ones((1,) * 33)

Callers

nothing calls this directly

Calls 2

viewMethod · 0.45
outerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…