Repository: scipy/scipy
File: scipy/fft/tests/test_real_transforms.py (Python)

Code before:
@pytest.mark.parametrize("norm", ["backward", "ortho", "forward"])
def test_orthogonalize_dct1(norm, xp):
    x = xp.asarray(np.random.rand(100))

    x2 = xp_copy(x, xp=xp)
    xpx.at(x2, 0).multiply(SQRT_2)
    xpx.at(x2, -1).multiply(SQRT_2)

    y1 = dct(x, type=1, norm=norm, orthogonalize=True)
    y2 = dct(x2, type=1, norm=norm, orthogonalize=False)

    xpx.at(y2, 0).divide(SQRT_2)
    xpx.at(y2, -1).divide(SQRT_2)
    xp_assert_close(y1, y2)



@make_xp_test_case(dct, dst)
@pytest.mark.parametrize("norm", ["backward", "ortho", "forward"])
@pytest.mark.parametrize("func", [dct, dst])
def test_orthogonalize_dcst2(func, norm, xp):
    x = xp.asarray(np.random.rand(100))
    y1 = func(x, type=2, norm=norm, orthogonalize=True)
    y2 = func(x, type=2, norm=norm, orthogonalize=False)

    xpx.at(y2, 0 if func == dct else -1).divide(SQRT_2)
    xp_assert_close(y1, y2)


@make_xp_test_case(dct, dst)
@skip_xp_backends(cpu_only=True)
@pytest.mark.parametrize("norm", ["backward", "ortho", "forward"])
@pytest.mark.parametrize("func", [dct, dst])
def test_orthogonalize_dcst3(func, norm, xp):
    x = xp.asarray(np.random.rand(100))
    x2 = xp_copy(x, xp=xp)
    xpx.at(x2, 0 if func == dct else -1).multiply(SQRT_2)

    y1 = func(x, type=3, norm=norm, orthogonalize=True)
    y2 = func(x2, type=3, norm=norm, orthogonalize=False)
    xp_assert_close(y1, y2)


@skip_xp_backends(np_only=True,
                  reason='array-likes only supported for NumPy backend')
@pytest.mark.parametrize("func", [dct, idct, dctn, idctn, dst, idst, dstn, idstn])
def test_array_like(xp, func):
    x = [[[1.0, 1.0], [1.0, 1.0]],
         [[1.0, 1.0], [1.0, 1.0]],
         [[1.0, 1.0], [1.0, 1.0]]]
    xp_assert_close(func(x), func(xp.asarray(x)))

Review comment (suggestion):
```suggestion
    xpx.at(y2, 0 if func.__name__ == "dct" else -1).divide(SQRT_2)
```

Code after:
    y2 = func(x, type=type, norm=norm, orthogonalize=False)
    xp_assert_close(y1, y2)


@make_xp_test_case(dct)
@pytest.mark.parametrize("norm", ["backward", "ortho", "forward"])
def test_orthogonalize_dct1(norm, xp):
    x = xp.asarray(np.random.rand(100))

    x2 = xp_copy(x, xp=xp)
    xpx.at(x2, 0).multiply(SQRT_2)
    xpx.at(x2, -1).multiply(SQRT_2)

    y1 = dct(x, type=1, norm=norm, orthogonalize=True)
    y2 = dct(x2, type=1, norm=norm, orthogonalize=False)

    xpx.at(y2, 0).divide(SQRT_2)
    xpx.at(y2, -1).divide(SQRT_2)
    xp_assert_close(y1, y2)



@pytest.mark.parametrize("norm", ["backward", "ortho", "forward"])
@pytest.mark.parametrize("func", [make_xp_pytest_param(dct),
                                  make_xp_pytest_param(dst)])
def test_orthogonalize_dcst2(func, norm, xp):
    x = xp.asarray(np.random.rand(100))
    y1 = func(x, type=2, norm=norm, orthogonalize=True)
    y2 = func(x, type=2, norm=norm, orthogonalize=False)

    xpx.at(y2, 0 if func.__name__ == "dct" else -1).divide(SQRT_2)
    xp_assert_close(y1, y2)


@pytest.mark.parametrize("norm", ["backward", "ortho", "forward"])
@pytest.mark.parametrize("func", [make_xp_pytest_param(dct),
                                  make_xp_pytest_param(dst)])
def test_orthogonalize_dcst3(func, norm, xp):
    x = xp.asarray(np.random.rand(100))
    x2 = xp_copy(x, xp=xp)
    xpx.at(x2, 0 if func.__name__ == "dct" else -1).multiply(SQRT_2)

    y1 = func(x, type=3, norm=norm, orthogonalize=True)
    y2 = func(x2, type=3, norm=norm, orthogonalize=False)
    xp_assert_close(y1, y2)


@skip_xp_backends(np_only=True,
                  reason='array-likes only supported for NumPy backend')
@pytest.mark.parametrize("func", [dct, idct, dctn, idctn, dst, idst, dstn, idstn])
def test_array_like(xp, func):