<commit_before>import unittest

import numpy

import cupy
from cupy import testing


@testing.parameterize(
    {'shape': (2, 3, 4), 'indexes': (slice(None), [1, 0])},
    {'shape': (2, 3, 4), 'indexes': (slice(None), [1, 0])},
    {'shape': (2, 3, 4), 'indexes': ([1, -1], slice(None))},
    {'shape': (2, 3, 4), 'indexes': (Ellipsis, [1, 0])},
    {'shape': (2, 3, 4), 'indexes': ([1, -1], Ellipsis)},
    {'shape': (2, 3, 4),
     'indexes': (slice(None), slice(None), [[1, -1], [0, 3]])},
)
@testing.gpu
class TestArrayAdvancedIndexingParametrized(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_array_equal()
    def test_adv_getitem(self, xp, dtype):
        a = testing.shaped_arange(self.shape, xp, dtype)
        return a[self.indexes]


@testing.parameterize(
    {'shape': (2, 3, 4), 'transpose': (1, 2, 0),
     'indexes': (slice(None), [1, 0])},
)
@testing.gpu
class TestArrayAdvancedIndexingParametrizedTransp(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_array_equal()
    def test_adv_getitem(self, xp, dtype):
        a = testing.shaped_arange(self.shape, xp, dtype)
        if self.transpose:
            a = a.transpose(self.transpose)
        return a[self.indexes]


@testing.parameterize(
    {'shape': (2, 3, 4), 'indexes': (slice(None),)},
    {'shape': (2, 3, 4), 'indexes': (numpy.array([1, 0],))},
)
@testing.gpu
class TestArrayAdvancedIndexingArrayClass(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_array_equal()
    def test_adv_getitem(self, xp, dtype):
        indexes = list(self.indexes)
        a = testing.shaped_arange(self.shape, xp, dtype)

        if xp is numpy:
            for i, s in enumerate(indexes):
                if isinstance(s, cupy.ndarray):
                    indexes[i] = s.get()

        return a[tuple(indexes)]


@testing.parameterize(
    {'shape': (), 'indexes': ([1],)},
    {'shape': (2, 3), 'indexes': (slice(None), [1, 2], slice(None))},
)
@testing.gpu
class TestArrayInvalidIndexAdv(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_raises()
    def test_invalid_adv_getitem(self, xp, dtype):
        a = testing.shaped_arange(self.shape, xp, dtype)
        a[self.indexes]


@testing.parameterize(
    {'shape': (2, 3, 4), 'indexes': ([1, 0], [2, 1])},
)
@testing.gpu
class TestArrayAdvancedIndexingNotSupported(unittest.TestCase):

    @testing.for_all_dtypes()
    def test_not_supported_adv_indexing(self, dtype):
        a = testing.shaped_arange(self.shape, cupy, dtype)
        with self.assertRaises(NotImplementedError):
            a[self.indexes]<commit_msg>test for advanced indexing with multiple arrays<commit_after>import unittest

import numpy

import cupy
from cupy import testing


@testing.parameterize(
    {'shape': (2, 3, 4), 'indexes': (slice(None), [1, 0])},
    {'shape': (2, 3, 4), 'indexes': (slice(None), [1, 0])},
    {'shape': (2, 3, 4), 'indexes': ([1, -1], slice(None))},
    {'shape': (2, 3, 4), 'indexes': (Ellipsis, [1, 0])},
    {'shape': (2, 3, 4), 'indexes': ([1, -1], Ellipsis)},
    {'shape': (2, 3, 4),
     'indexes': (slice(None), slice(None), [[1, -1], [0, 3]])},
    {'shape': (2, 3, 4), 'indexes': ([1, 0], [2, 1])},
    {'shape': (2, 3, 4), 'indexes': (slice(None), [1, 0], [2, 1])},
    {'shape': (2, 3), 'indexes': ([[0, 1], [1, 0]], [[1, 1], [2, 1]])},
    # array appears with split
    {'shape': (2, 3, 4), 'indexes': ([0, 1], slice(None), [1, 0])},
    {'shape': (2, 3, 4), 'indexes': ([0, 1], slice(None), 1)},
    {'shape': (2, 3, 4), 'indexes': ([1, 0], slice(0, 3, 2), [1, 0])},
    # three arrays
    {'shape': (2, 3, 4), 'indexes': ([1, 0], [2, 1], [3, 1])},
    {'shape': (2, 3, 4), 'indexes': ([1, 0], 1, [3, 1])},
    {'shape': (2, 3, 4), 'indexes': ([1, 0], 1, None, [3, 1])},
    # index broadcasting
    {'shape': (2, 3, 4), 'indexes': (slice(None), [1, 2], [[1, 0], [0, 1], [-1, 1]])},
)
@testing.gpu
class TestArrayAdvancedIndexingParametrized(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_array_equal()
    def test_adv_getitem(self, xp, dtype):
        a = testing.shaped_arange(self.shape, xp, dtype)
        return a[self.indexes]


@testing.parameterize(
    {'shape': (2, 3, 4), 'indexes': (None, [1, 0], [0, 2], slice(None))},
    {'shape': (2, 3, 4), 'indexes': (None, [0, 1], None, [2, 1], slice(None))}
)
@testing.gpu
class TestArrayAdvancedIndexingParametrized(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_array_equal()
    def test_adv_getitem(self, xp, dtype):
        a = testing.shaped_arange(self.shape, xp, dtype)
        return a[self.indexes]

@testing.parameterize(
    {'shape': (2, 3, 4), 'transpose': (1, 2, 0),
     'indexes': (slice(None), [1, 0])},
    {'shape': (2, 3, 4), 'transpose': (1, 0, 2),
     'indexes': (None, [1, 2], [0, -1])},
)
@testing.gpu
class TestArrayAdvancedIndexingParametrizedTransp(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_array_equal()
    def test_adv_getitem(self, xp, dtype):
        a = testing.shaped_arange(self.shape, xp, dtype)
        if self.transpose:
            a = a.transpose(self.transpose)
        return a[self.indexes]


@testing.parameterize(
    {'shape': (2, 3, 4), 'indexes': (slice(None),)},
    {'shape': (2, 3, 4), 'indexes': (numpy.array([1, 0],))},
)
@testing.gpu
class TestArrayAdvancedIndexingArrayClass(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_array_equal()
    def test_adv_getitem(self, xp, dtype):
        indexes = list(self.indexes)
        a = testing.shaped_arange(self.shape, xp, dtype)

        if xp is numpy:
            for i, s in enumerate(indexes):
                if isinstance(s, cupy.ndarray):
                    indexes[i] = s.get()

        return a[tuple(indexes)]


@testing.parameterize(
    {'shape': (), 'indexes': ([1],)},
    {'shape': (2, 3), 'indexes': (slice(None), [1, 2], slice(None))},
)
@testing.gpu
class TestArrayInvalidIndexAdv(unittest.TestCase):

    @testing.for_all_dtypes()
    @testing.numpy_cupy_raises()
    def test_invalid_adv_getitem(self, xp, dtype):
        a = testing.shaped_arange(self.shape, xp, dtype)
        a[self.indexes]
{'fraction_non_alphanumeric': 0.20583988448580137, 'fraction_numerical': 0.03529600513396439, 'mean_word_length': 3.573734409391049, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1368655', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2355, 'n_words': 558}