Skip to content

Commit 86461cc

Browse files
committed
TST: test that lazy_xp_function can handle inherited methods
1 parent 01ac205 commit 86461cc

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_testing.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,37 @@ def test_lazy_xp_function_cython_ufuncs(xp: ModuleType, library: Backend):
321321
xp_assert_equal(cast(Array, erf(x)), xp.asarray([1.0, 1.0]))
322322

323323

324+
class A:
325+
def __init__(self, x):
326+
xp = array_namespace(x)
327+
self._xp = xp
328+
self.x = np.asarray(x)
329+
330+
def f(self, y):
331+
y = np.asarray(y)
332+
return self._xp.asarray(np.matmul(self.x, y))
333+
334+
def g(self, y, z):
335+
return self.f(y) + self.f(z)
336+
337+
338+
class B(A):
339+
def __init__(self, x):
340+
xp = array_namespace(x)
341+
self._xp = xp
342+
self.x = xp.asarray(x)
343+
344+
def f(self, y):
345+
return self._xp.matmul(self.x, y)
346+
347+
348+
lazy_xp_function((B, "g"))
349+
350+
def test_lazy_xp_function_class_inheritance(xp: ModuleType):
351+
assert hasattr(B.g, "_lazy_xp_function")
352+
assert not hasattr(A.g, "_lazy_xp_function")
353+
354+
324355
def dask_raises(x: Array) -> Array:
325356
def _raises(x: Array) -> Array:
326357
# Test that map_blocks doesn't eagerly call the function;

0 commit comments

Comments
 (0)