def test_03(self):
        for i in range(5):
            # these limits are just to limit the time it takes to test.
            deg = np.random.randint(0, 4)  # Maximum polynomial degree = 3
            ndim = np.random.randint(1, 6)  # Maximim 5-Dimensional array
            axis = np.random.randint(0, ndim)
            max_dim_size = 11  # The maximum number of elements along one dimension

            if ndim > 1:
                tmp_shape = np.random.randint(1, max_dim_size, size=ndim)
                data_shape = tmp_shape.copy()
                data_shape[axis] = np.random.randint(1, max_dim_size)
                data_shape = tuple(data_shape)

                p_shape = tmp_shape.copy()
                p_shape[axis] = deg + 1
                p_shape = tuple(p_shape)
            else:
                data_shape = (np.random.randint(1, max_dim_size), )
                p_shape = (deg + 1, )

            p = np.random.random(size=p_shape)
            x_nparr = np.random.random(size=data_shape)
            x = da.from_array(x_nparr, chunks=np.ones((ndim, )))

            y_expected = np.zeros(data_shape)

            for i in range(deg + 1):
                y_expected += p.take([i], axis=axis) * \
                    np.power(x_nparr, deg - i)

            y_actual = ndpolyval(p, x, axis=axis)
            np.testing.assert_almost_equal(y_actual.data, y_expected.data)
    def test_04(self):
        # Creating synthetic data
        x = np.linspace(-8 * np.pi, 8 * np.pi, 33, dtype=np.float64)
        y0 = 1.0 * x
        y1 = np.sin(x)
        y = np.tile((y0 + y1).reshape((1, -1, 1, 1)), (2, 1, 3, 4))

        p = ndpolyfit(x, y, deg=1, axis=1)
        y_trend = ndpolyval(p, x, axis=1)

        y_detrended = detrend(y, x=x, axis=1)

        np.testing.assert_almost_equal(y_detrended + y_trend, y)
    def test_02(self):
        # Creating synthetic data
        x = np.linspace(-8 * np.pi, 8 * np.pi, 33, dtype=np.float64)
        y0 = 1.0 * x
        y1 = np.sin(x)
        y = y0 + y1

        p = ndpolyfit(np.arange(x.size), y, deg=1)
        y_trend = ndpolyval(p, np.arange(x.size))

        y_detrended = detrend(y)

        np.testing.assert_almost_equal(y_detrended + y_trend, y)
    def test_03(self):
        # Creating synthetic data
        x = np.linspace(-8 * np.pi, 8 * np.pi, 33, dtype=np.float64)
        y0 = 1.0 * x
        y1 = np.sin(x)
        y = y0 + y1

        p = ndpolyfit(x, y, deg=1)
        y_trend = ndpolyval(p, x)

        y_detrended = detrend(y, x=x, return_info=False)

        np.testing.assert_almost_equal(y_detrended + y_trend, y)

        np.testing.assert_equal({}, y_detrended.attrs)