MCPcopy Create free account
hub / github.com/numpy/numpy / test_custom_array_like

Method test_custom_array_like

numpy/core/tests/test_ufunc.py:1931–1960  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1929 signature=(_rational_tests.rational, int, None))
1930
1931 def test_custom_array_like(self):
1932
1933 class MyThing:
1934 __array_priority__ = 1000
1935
1936 rmul_count = 0
1937 getitem_count = 0
1938
1939 def __init__(self, shape):
1940 self.shape = shape
1941
1942 def __len__(self):
1943 return self.shape[0]
1944
1945 def __getitem__(self, i):
1946 MyThing.getitem_count += 1
1947 if not isinstance(i, tuple):
1948 i = (i,)
1949 if len(i) > self.ndim:
1950 raise IndexError("boo")
1951
1952 return MyThing(self.shape[len(i):])
1953
1954 def __rmul__(self, other):
1955 MyThing.rmul_count += 1
1956 return self
1957
1958 np.float64(5)*MyThing((3, 3))
1959 assert_(MyThing.rmul_count == 1, MyThing.rmul_count)
1960 assert_(MyThing.getitem_count <= 2, MyThing.getitem_count)
1961
1962 @pytest.mark.parametrize("a", (
1963 np.arange(10, dtype=int),

Callers

nothing calls this directly

Calls 2

assert_Function · 0.90
MyThingClass · 0.85

Tested by

no test coverage detected