Repository: scipy/scipy
File: scipy/interpolate/tests/test_bsplines.py (Python)

Code before:
        a, b = 0, 2*np.pi
        x = np.linspace(a, b, N + 1)    # nodes
        y = np.exp(x)

        with assert_raises(ValueError):
            make_splrep(x, y, s=1e-8, bc_type="nonsense")

    @pytest.mark.parametrize("bc_type", ["periodic", None])
    @pytest.mark.parametrize("k", [1, 2, 3, 4, 5])
    def test_make_splrep_with_unequal_weights(self, bc_type, k):
        # Sample data
        x = np.linspace(0, 2*np.pi, 10)
        y = np.sin(x)

        w = np.linspace(1, 5, len(x))

        tck = splrep(x, y, w=w, k=k, s=1e-8, per=(bc_type == 'periodic'))
        spl = make_splrep(x, y, w=w, s=1e-8, k=k, bc_type=bc_type)

        xp_assert_close(spl.t, tck[0])
        xp_assert_close(np.r_[spl.c, [0]*(spl.k+1)],
                        tck[1], atol=1e-8)


    @pytest.mark.parametrize("bc_type", ["periodic", None])
    def test_make_splrep_with_non_c_contiguous_input(self, bc_type):

        def check(spl, tck):
            xp_assert_close(spl.t, tck[0])
            xp_assert_close(np.r_[spl.c, [0]*(spl.k+1)],
                            tck[1], atol=1e-8)

        # Sample data
        x = np.linspace(0, 2*np.pi, 10)
        y = np.sin(x)

        x1, y1 = np.c_[x, y].T

        # Safety check to make sure inputs
        # are actually not C contiguous
        assert x1.flags.c_contiguous is False
        assert y1.flags.c_contiguous is False

        w = np.linspace(1, 5, len(x))
        w1, _ = np.c_[w, w].T

        # Safety check to make sure inputs
        # are actually not C contiguous
        assert w1.flags.c_contiguous is False

        tck = splrep(x, y, w=w, k=3, s=1e-8, per=(bc_type == 'periodic'))

Review comment (suggestion):
```suggestion
    def test_make_splrep_with_non_c_contiguous_input(self, bc_type):
          # regression test for https://github.com/scipy/scipy/issues/23371
```

Code after:
        a, b = 0, 2*np.pi
        x = np.linspace(a, b, N + 1)    # nodes
        y = np.exp(x)

        with assert_raises(ValueError):
            make_splrep(x, y, s=1e-8, bc_type="nonsense")

    @pytest.mark.parametrize("bc_type", ["periodic", None])
    @pytest.mark.parametrize("k", [1, 2, 3, 4, 5])
    def test_make_splrep_with_unequal_weights(self, bc_type, k):
        # Sample data
        x = np.linspace(0, 2*np.pi, 10)
        y = np.sin(x)

        w = np.linspace(1, 5, len(x))

        tck = splrep(x, y, w=w, k=k, s=1e-8, per=(bc_type == 'periodic'))
        spl = make_splrep(x, y, w=w, s=1e-8, k=k, bc_type=bc_type)

        xp_assert_close(spl.t, tck[0])
        xp_assert_close(np.r_[spl.c, [0]*(spl.k+1)],
                        tck[1], atol=1e-8)


    @pytest.mark.parametrize("bc_type", ["periodic", None])
    def test_make_splrep_with_non_c_contiguous_input(self, bc_type):
          # regression test for https://github.com/scipy/scipy/issues/23371

        def check(spl, tck):
            xp_assert_close(spl.t, tck[0])
            xp_assert_close(np.r_[spl.c, [0]*(spl.k+1)],
                            tck[1], atol=1e-8)

        # Sample data
        x = np.linspace(0, 2*np.pi, 10)
        y = np.sin(x)

        x1, y1 = np.c_[x, y].T

        # Safety check to make sure inputs
        # are actually not C contiguous
        assert x1.flags.c_contiguous is False
        assert y1.flags.c_contiguous is False

        w = np.linspace(1, 5, len(x))
        w1, _ = np.c_[w, w].T

        # Safety check to make sure inputs
        # are actually not C contiguous
        assert w1.flags.c_contiguous is False