Repository: scipy/scipy
File: scipy/sparse/tests/test_coo.py (Python)

Code before:
    (Ellipsis),
    # array indexing
    (2, [1, 2], slice(3)),
    (np.array([1, 3]), slice(1, None), 0),
    (np.array([1, 3]), slice(1, None), [0]),
    # fancy array indexing
    (np.array([1, 3]), slice(1, None), np.array([2, 4])),
    (2, np.array([1, 3]), np.array([2, 4])),
    (np.array([1, 3]), np.array([2, 4]), 1),
    (np.array([1, 3]), np.array([2, 4]), [2]),
]

@pytest.mark.parametrize(["A", "D", "idx"], [(A, D, idx) for idx in keys])
@pytest.mark.thread_unsafe
def test_3d_coo_set(A, D, idx):
    D[idx] = A[idx] = -99
    assert_equal(A.toarray(), D)


@pytest.mark.parametrize(
    "scalar_container",
    [lambda x: csr_array(np.array([[x]])), np.array, lambda x: x],
    ids=["sparse", "dense", "scalar"],
)
def test_3d_coo_singleton(scalar_container):
    A[(0, 0, 0)] = scalar_container(-99)
    D[(0, 0, 0)] = -99
    assert_equal(A.toarray(), D)


#D = np.arange(4 * 5 * 6 * 4 * 6).reshape((4, 5, 6, 4, 6))
D = np.arange(4 * 6 * 6 * 3 * 4).reshape((4, 6, 6, 3, 4))
A = coo_array(D)

keys = [
    # multidimensional
    ("all-ints", (1, 2, 1)),
    ("ellipsis-first", (..., 0)),
    ("ellipsis-last", (1, ...)),
    ("ellipsis-middle", (1, ..., 0)),
    # slices and ints
    ("split-ints", (slice(None, 4, None), 2, 1, slice(None, None, None), 1)),
    ("contiguous-ints-last", (slice(4, None, None), slice(None, None, None), 2, 1, 1)),
    ("contiguous-ints-first", (2, 1, 1, slice(4, None, None), slice(None, None, None))),
    ("empty-slice", (slice(4, 4, None), slice(None, None, None), 2, 1, 1)),
    # slices and arrays and ints
    ("split-2d-arrays-and-ints",
        (slice(None, 4, None), [[2, 1, 1], [2, 1, 2]], [[2, 1, 0], [3, 4, 0]],
         slice(None, None, None), 0)
    ),
    ("contiguous-2d-arrays-and-ints",

Review comment (bug):
@dschult @perimosocordiae thought I should ping you on this one. [Example failure](https://github.com/scipy/scipy/actions/runs/18622563782/job/53097944417).

Code after:
    (Ellipsis),
    # array indexing
    (2, [1, 2], slice(3)),
    (np.array([1, 3]), slice(1, None), 0),
    (np.array([1, 3]), slice(1, None), [0]),
    # fancy array indexing
    (np.array([1, 3]), slice(1, None), np.array([2, 4])),
    (2, np.array([1, 3]), np.array([2, 4])),
    (np.array([1, 3]), np.array([2, 4]), 1),
    (np.array([1, 3]), np.array([2, 4]), [2]),
]

@pytest.mark.parametrize(["A", "D", "idx"], [(A, D, idx) for idx in keys])
@pytest.mark.thread_unsafe
def test_3d_coo_set(A, D, idx):
    D[idx] = A[idx] = -99
    assert_equal(A.toarray(), D)


@pytest.mark.parametrize(
    "scalar_container",
    [lambda x: csr_array(np.array([[x]])), np.array, lambda x: x],
    ids=["sparse", "dense", "scalar"],
)
@pytest.mark.thread_unsafe(reason="fails in parallel")
def test_3d_coo_singleton(scalar_container):
    A[(0, 0, 0)] = scalar_container(-99)
    D[(0, 0, 0)] = -99
    assert_equal(A.toarray(), D)


#D = np.arange(4 * 5 * 6 * 4 * 6).reshape((4, 5, 6, 4, 6))
D = np.arange(4 * 6 * 6 * 3 * 4).reshape((4, 6, 6, 3, 4))
A = coo_array(D)

keys = [
    # multidimensional
    ("all-ints", (1, 2, 1)),
    ("ellipsis-first", (..., 0)),
    ("ellipsis-last", (1, ...)),
    ("ellipsis-middle", (1, ..., 0)),
    # slices and ints
    ("split-ints", (slice(None, 4, None), 2, 1, slice(None, None, None), 1)),
    ("contiguous-ints-last", (slice(4, None, None), slice(None, None, None), 2, 1, 1)),
    ("contiguous-ints-first", (2, 1, 1, slice(4, None, None), slice(None, None, None))),
    ("empty-slice", (slice(4, 4, None), slice(None, None, None), 2, 1, 1)),
    # slices and arrays and ints
    ("split-2d-arrays-and-ints",
        (slice(None, 4, None), [[2, 1, 1], [2, 1, 2]], [[2, 1, 0], [3, 4, 0]],
         slice(None, None, None), 0)
    ),