Add decorator for slice_copy
-import os
import sys
import pytest
import unittest
import functools
-os.environ['CUPY_EXPERIMENTAL_SLICE_COPY'] = str(1)
-
import numpy
import cupy
@@ -110,6 +107,20 @@ def numpy_fallback_array_allclose(name='xp', rtol=1e-07):
return decorator
+def enable_slice_copy(func):
+ """
+ Decorator that enables CUPY_EXPERIMENTAL_SLICE_COPY.
+ And then restores it to previous state.
+ """
+ def decorator(*args, **kwargs):
+ old = cupy.util.ENABLE_SLICE_COPY
+ cupy.util.ENABLE_SLICE_COPY = True
+ func(*args, **kwargs)
+ cupy.util.ENABLE_SLICE_COPY = old
+
+ return decorator
+
+
@testing.gpu
class TestFallbackMode(unittest.TestCase):
@@ -643,6 +654,7 @@ class TestArrayVariants(unittest.TestCase):
return x
# changes in base ndarray should be reflected in MaskedArray
+ @enable_slice_copy
@numpy_fallback_array_equal()
def test_ma_func_inverse(self, xp):
x = xp.array([1, 2, 3, 4])
