| 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) |
no outgoing calls