import numpy
import unittest

import cupy
from cupy import testing


@testing.gpu
class TestNdim(unittest.TestCase):

    @testing.numpy_cupy_equal()
    def test_ndim_ndarray1d(self, xp):
        return xp.ndim(xp.arange(5))

    @testing.numpy_cupy_equal()
    def test_ndim_ndarray2d(self, xp):
        assert xp.ndim(xp.ones((2, 4))) == 2

    @testing.numpy_cupy_equal()
    def test_ndim_ndarray0d(self, xp):
        assert xp.ndim(xp.asarray(5)) == 1

    @testing.numpy_cupy_equal()
    def test_ndim_scalar(self, xp):
        assert xp.ndim(5) == 0

    @testing.numpy_cupy_equal()
    def test_ndim_none(self, xp):
        assert xp.ndim(None) == 0

    @testing.numpy_cupy_equal()
    def test_ndim_string(self, xp):
        assert xp.ndim('abc') == 0

    @testing.numpy_cupy_equal()
    def test_ndim_list1(self, xp):
        assert xp.ndim([1, 2, 3]) == 1

    @testing.numpy_cupy_equal()
    def test_ndim_list2(self, xp):
        assert xp.ndim([[1, 2, 3], [4, 5, 6]]) == 2

    @testing.numpy_cupy_equal()
    def test_ndim_tuple(self, xp):
        assert xp.ndim(((1, 2, 3), (4, 5, 6))) == 2

    @testing.numpy_cupy_equal()
    def test_ndim_set(self, xp):
        assert xp.ndim({1, 2, 3}) == 1

    @testing.numpy_cupy_equal()
    def test_ndim_list_of_ndarray(self, xp):
        assert xp.ndim([xp.arange(5), ] * 3) == 2

    @testing.numpy_cupy_equal()
    def test_ndim_list_of_ndarray2(self, xp):
        assert xp.ndim([xp.arange(5), xp.arange(3)]) == 1

    @testing.numpy_cupy_equal()
    def test_ndim_object(self, xp):
        assert xp.ndim(dict(a=5, b='b'))

    # numpy.dim works on CuPy arrays and cupy.ndim works on NumPy arrays
    def test_ndim_array_function(self):
        a = cupy.ones((4, 4))
        assert numpy.ndim(a) == 2

        a = cupy.asarray(5)
        assert numpy.ndim(a) == 0

        a = numpy.ones((4, 4))
        assert cupy.ndim(a) == 2

        a = numpy.asarray(5)
        assert cupy.ndim(a) == 0

    @testing.numpy_cupy_equal()
    def test_ndim_mixed_list_of_ndarray(self, xp):
        assert xp.ndim([cupy.arange(5), numpy.arange(5)]) == 2

import numpy
import unittest

import cupy
from cupy import testing


@testing.gpu
class TestNdim(unittest.TestCase):

    @testing.numpy_cupy_equal()
    def test_ndim_ndarray1d(self, xp):
        return xp.ndim(xp.arange(5))

    @testing.numpy_cupy_equal()
    def test_ndim_ndarray2d(self, xp):
        assert xp.ndim(xp.ones((2, 4))) == 2

    @testing.numpy_cupy_equal()
    def test_ndim_ndarray0d(self, xp):
        assert xp.ndim(xp.asarray(5)) == 1

    @testing.numpy_cupy_equal()
    def test_ndim_scalar(self, xp):
        assert xp.ndim(5) == 0

    @testing.numpy_cupy_equal()
    def test_ndim_none(self, xp):
        assert xp.ndim(None) == 0

    @testing.numpy_cupy_equal()
    def test_ndim_string(self, xp):
        assert xp.ndim('abc') == 0

    @testing.numpy_cupy_equal()
    def test_ndim_list1(self, xp):
        assert xp.ndim([1, 2, 3]) == 1

    @testing.numpy_cupy_equal()
    def test_ndim_list2(self, xp):
        assert xp.ndim([[1, 2, 3], [4, 5, 6]]) == 2

    @testing.numpy_cupy_equal()
    def test_ndim_tuple(self, xp):
        assert xp.ndim(((1, 2, 3), (4, 5, 6))) == 2

    @testing.numpy_cupy_equal()
    def test_ndim_set(self, xp):
        assert xp.ndim({1, 2, 3}) == 1

    @testing.numpy_cupy_equal()
    def test_ndim_object(self, xp):
        assert xp.ndim(dict(a=5, b='b')) == 0

    # numpy.dim works on CuPy arrays and cupy.ndim works on NumPy arrays
    def test_ndim_array_function(self):
        a = cupy.ones((4, 4))
        assert numpy.ndim(a) == 2

        a = cupy.asarray(5)
        assert numpy.ndim(a) == 0

        a = numpy.ones((4, 4))
        assert cupy.ndim(a) == 2

        a = numpy.asarray(5)
        assert cupy.ndim(a) == 0

remove tests involving lists of arrays