Repository: chainer/chainer

Issue:
Remove deprecated cuda module functions
There are many deprecated functions in chainer.cuda module, which were originally used for unified interface for numpy and pycuda. They can be removed in v2.


Discussion:

Resolving patch:
diff --git a/chainer/cuda.py b/chainer/cuda.py
--- a/chainer/cuda.py
+++ b/chainer/cuda.py
@@ -62,15 +62,6 @@ class ndarray(object):
         _resolution_error = e
 
 
-def init(arg=None):
-    warnings.warn(
-        'chainer.cuda.init is deprecated. You need to call nothing to '
-        'initialize your environment. Call chainer.cuda.check_cuda_available '
-        'to check availability of CUDA.',
-        DeprecationWarning)
-    check_cuda_available()
-
-
 def check_cuda_available():
     """Checks if CUDA is available.
 
@@ -272,156 +263,6 @@ def to_cpu(array, stream=None):
             '\nActual type: {0}.'.format(type(array)))
 
 
-def empty(shape, dtype=numpy.float32):
-    """Creates an uninitialized :class:`cupy.ndarray` object.
-
-    Args:
-        shape (tuple of ints): The shape of array.
-        dtype (numpy.dtype): Element type.
-
-    Returns:
-        cupy.ndarray: Uninitialized GPU array allocated by the memory pool.
-
-    """
-    warnings.warn(
-        'chainer.cuda.empty is deprecated. Use cupy.empty instead.',
-        DeprecationWarning)
-    check_cuda_available()
-    return cupy.empty(shape, dtype)
-
-
-def full(shape, fill_value, dtype=numpy.float32, stream=None):
-    """Creates a constant-filled :class:`cupy.ndarray` object.
-
-    Args:
-        shape (tuple of ints): The shape of array.
-        fill_value: Constant to fill the array by.
-        dtype (numpy.dtype): Element type.
-        stream (cupy.cuda.Stream): CUDA stream.
-
-    Returns:
-        cupy.ndarray: Constant-filled GPU array allocated by the memory pool.
-
-    """
-    warnings.warn(
-        'chainer.cuda.full is deprecated. Use cupy.full instead.',
-        DeprecationWarning)
-    check_cuda_available()
-    assert stream is None
-    return cupy.full(shape, fill_value, dtype=dtype)
-
-
-def zeros(shape, dtype=numpy.float32, stream=None):
-    """Creates a zero-filled :class:`cupy.ndarray` object.
-
-    This function is equivalent to ``full(shape, 0, dtype, stream)``.
-
-    """
-    warnings.warn(
-        'chainer.cuda.zeros is deprecated. Use cupy.zeros instead.',
-        DeprecationWarning)
-    check_cuda_available()
-    assert stream is None
-    return cupy.zeros(shape, dtype=dtype)
-
-
-def ones(shape, dtype=numpy.float32, stream=None):
-    """Creates a zero-filled :class:`cupy.ndarray` object.
-
-    This function is equivalent to ``full(shape, 1, dtype, stream)``.
-
-    """
-    warnings.warn(
-        'chainer.cuda.ones is deprecated. Use cupy.ones instead.',
-        DeprecationWarning)
-    check_cuda_available()
-    assert stream is None
-    return cupy.ones(shape, dtype=dtype)
-
-
-def empty_like(array):
-    """Creates an uninitialized GPU array like the given one.
-
-    Args:
-        array (cupy.ndarray or numpy.ndarray): Base array.
-
-    Returns:
-        cupy.ndarray: GPU array of the same shape and dtype as `array`.
-
-    """
-    warnings.warn(
-        'chainer.cuda.empty_like is deprecated. Use cupy.empty_like instead.',
-        DeprecationWarning)
-    check_cuda_available()
-    if isinstance(array, cupy.ndarray):
-        return cupy.empty_like(array)
-    return cupy.empty(array.shape, dtype=array.dtype)
-
-
-def full_like(array, fill_value, stream=None):
-    """Creates a constant-filled :class:`cupy.ndarray` object like the given array.
-
-    Args:
-        array (cupy.ndarray or numpy.ndarray): Base array.
-        fill_value: Constant value to fill the array by.
-        stream (cupy.cuda.Stream): CUDA stream.
-
-    Returns:
-        cupy.ndarray: Constant-filled array.
-
-    """
-    warnings.warn(
-        'chainer.cuda.full_like is deprecated. Use cupy.full_like instead.',
-        DeprecationWarning)
-    check_cuda_available()
-    assert stream is None
-    if isinstance(array, cupy.ndarray):
-        return cupy.full_like(array, fill_value)
-    return cupy.full(array.shape, fill_value, dtype=array.dtype)
-
-
-def zeros_like(array, stream=None):
-    """Creates a zero-filled :class:`cupy.ndarray` object like the given array.
-
-    Args:
-        array (cupy.ndarray or numpy.ndarray): Base array.
-        stream (cupy.cuda.Stream): CUDA stream.
-
-    Returns:
-        cupy.ndarray: Zero-filled array.
-
-    """
-    warnings.warn(
-        'chainer.cuda.zeros_like is deprecated. Use cupy.zeros_like instead.',
-        DeprecationWarning)
-    check_cuda_available()
-    assert stream is None
-    if isinstance(array, cupy.ndarray):
-        return cupy.zeros_like(array)
-    return cupy.zeros(array.shape, dtype=array.dtype)
-
-
-def ones_like(array, stream=None):
-    """Creates a one-filled :class:`cupy.ndarray` object like the given array.
-
-    Args:
-        array (cupy.ndarray or numpy.ndarray): Base array.
-        stream (cupy.cuda.Stream): CUDA stream.
-
-    Returns:
-        cupy.ndarray: One-filled array.
-
-    """
-    warnings.warn(
-        'chainer.cuda.ones_like is deprecated. Use cupy.ones_like instead.',
-        DeprecationWarning)
-    check_cuda_available()
-    assert stream is None
-    if isinstance(array, cupy.ndarray):
-        return cupy.ones_like(array)
-    return cupy.ones(array.shape, dtype=array.dtype)
-
-
 def copy(array, out=None, out_device=None, stream=None):
     """Copies a :class:`cupy.ndarray` object using the default stream.
 


Test patch:
diff --git a/tests/chainer_tests/test_cuda.py b/tests/chainer_tests/test_cuda.py
--- a/tests/chainer_tests/test_cuda.py
+++ b/tests/chainer_tests/test_cuda.py
@@ -1,5 +1,4 @@
 import unittest
-import warnings
 
 import numpy
 
@@ -78,19 +77,6 @@ def test_get_array_module_for_cupy(self):
             cuda.get_array_module(chainer.Variable(cuda.cupy.array([]))),
             cuda.cupy)
 
-    def test_empy_unavailable(self):
-        if not cuda.available:
-            with self.assertRaises(RuntimeError):
-                with warnings.catch_warnings():
-                    cuda.empty(())
-
-    def test_empy_like_unavailable(self):
-        x = numpy.array([1])
-        if not cuda.available:
-            with self.assertRaises(RuntimeError):
-                with warnings.catch_warnings():
-                    cuda.empty_like(x)
-
 
 @testing.parameterize(
     {'c_contiguous': True},