Exemplo n.º 1
0
    def test_xi_broadcast(self):
        # verify that the interpolators broadcast xi
        x, y, values = self._sample_2d_data()
        points = (x, y)

        xi = cp.linspace(0, 1, 2)
        yi = cp.linspace(0, 3, 3)

        for method in ["nearest", "linear"]:  # 'splinef2d']:
            sample = (xi[:, None], yi[None, :])
            v1 = interpn(points,
                         values,
                         sample,
                         method=method,
                         bounds_error=False)
            assert_equal(v1.shape, (2, 3))

            xx, yy = np.meshgrid(xi, yi)
            sample = cp.c_[xx.T.ravel(), yy.T.ravel()]

            v2 = interpn(points,
                         values,
                         sample,
                         method=method,
                         bounds_error=False)
            assert_allclose(v1, v2.reshape(v1.shape))
Exemplo n.º 2
0
    def test_nonscalar_values(self):
        # Verify that non-scalar valued values also works
        points, values = self._sample_4d_data()

        np.random.seed(1234)
        values = cp.asarray(np.random.rand(3, 3, 3, 3, 6))
        sample = cp.asarray(np.random.rand(7, 11, 4))

        for method in ["nearest", "linear"]:
            v = interpn(points,
                        values,
                        sample,
                        method=method,
                        bounds_error=False)
            assert_equal(v.shape, (7, 11, 6), err_msg=method)

            vs = [
                interpn(
                    points,
                    values[..., j],
                    sample,
                    method=method,
                    bounds_error=False,
                ) for j in range(6)
            ]
            v2 = cp.asarray(vs).transpose(1, 2, 0)

            assert_allclose(v, v2, err_msg=method)
Exemplo n.º 3
0
 def test_xi_1d(self):
     # verify that 1-D xi works as expected
     points, values = self._sample_4d_data()
     sample = cp.asarray([0.1, 0.1, 10.0, 9.0])
     v1 = interpn(points, values, sample, bounds_error=False)
     v2 = interpn(points, values, sample[None, :], bounds_error=False)
     assert_allclose(v1, v2)
Exemplo n.º 4
0
    def test_list_input(self):
        x, y, z = self._sample_2d_data()
        xi = cp.asarray([[1, 2.3, 5.3, 0.5, 3.3, 1.2, 3],
                         [1, 3.3, 1.2, 4.0, 5.0, 1.0, 3]]).T

        for method in ["nearest", "linear"]:  # 'splinef2d']:
            v1 = interpn((x, y), z, xi, method=method)
            v2 = interpn((x.tolist(), y.tolist()),
                         z.tolist(),
                         xi.tolist(),
                         method=method)
            assert_allclose(v1, v2, err_msg=method)
Exemplo n.º 5
0
    def test_complex(self):
        x, y, values = self._sample_2d_data()
        points = (x, y)
        values = values - 2j * values

        sample = cp.asarray([[1, 2.3, 5.3, 0.5, 3.3, 1.2, 3],
                             [1, 3.3, 1.2, 4.0, 5.0, 1.0, 3]]).T

        for method in ["linear", "nearest"]:
            v1 = interpn(points, values, sample, method=method)
            v2r = interpn(points, values.real, sample, method=method)
            v2i = interpn(points, values.imag, sample, method=method)
            v2 = v2r + 1j * v2i
            assert_allclose(v1, v2)
Exemplo n.º 6
0
 def test_nearest_4d(self):
     # create a 4-D grid of 3 points in each dimension
     points, values = self._sample_4d_data()
     interp_rg = RegularGridInterpolator(points, values, method="nearest")
     sample = cp.asarray([[0.1, 0.1, 10.0, 9.0]])
     wanted = interpn(points, values, sample, method="nearest")
     assert_array_almost_equal(interp_rg(sample), wanted)
Exemplo n.º 7
0
    def test_xi_nd(self):
        # verify that higher-d xi works as expected
        points, values = self._sample_4d_data()

        np.random.seed(1234)
        sample = cp.asarray(np.random.rand(2, 3, 4))

        v1 = interpn(points,
                     values,
                     sample,
                     method="nearest",
                     bounds_error=False)
        assert_equal(v1.shape, (2, 3))

        v2 = interpn(
            points,
            values,
            sample.reshape(-1, 4),
            method="nearest",
            bounds_error=False,
        )
        assert_allclose(v1, v2.reshape(v1.shape))
Exemplo n.º 8
0
 def test_4d_nearest_outofbounds(self):
     # create a 4-D grid of 3 points in each dimension
     points, values = self._sample_4d_data()
     sample = cp.asarray([[0.1, -0.1, 10.1, 9.0]])
     wanted = 999.99
     actual = interpn(
         points,
         values,
         sample,
         method="nearest",
         bounds_error=False,
         fill_value=999.99,
     )
     assert_array_almost_equal(actual, wanted)