def test_min(): result = cuspatial.CubicSpline( cudf.Series([0, 1, 2, 3, 4]).astype("float32"), cudf.Series([3, 2, 3, 4, 3]).astype("float32"), cudf.Series([0, 5]).astype("int32"), ) assert_eq( result.c, cudf.DataFrame({ "d3": [0.5, -0.5, -0.5, 0.5], "d2": [0, 3, 3, -6], "d1": [-1.5, -4.5, -4.5, 22.5], "d0": [3, 4, 4, -23], }), check_dtype=False, )
def test_class_new_interpolation(): t = cudf.Series(np.hstack((np.arange(5), ) * 3)).astype("float32") y = cudf.Series([3, 2, 3, 4, 3, 3, 2, 3, 4, 3, 3, 2, 3, 4, 3]).astype("float32") prefix_sum = cudf.Series(cp.arange(4) * 5).astype("int32") new_samples = cudf.Series(np.hstack( (np.linspace(0, 4, 9), ) * 3)).astype("float32") curve = cuspatial.CubicSpline(t, y, prefixes=prefix_sum) new_x = cudf.Series(np.repeat(np.arange(0, 3), 9)).astype("int32") old_x = cudf.Series(np.repeat(np.arange(0, 3), 5)).astype("int32") new_points = curve(new_samples, groups=new_x) old_points = curve(t, groups=old_x) new_points_at_control_points = new_points[0, 2, 4, 6, 8, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26] new_points_at_control_points.index = cudf.RangeIndex( 0, len(new_points_at_control_points)) assert_eq(new_points_at_control_points, old_points)
def test_cusparse(): result = cuspatial.CubicSpline( cudf.Series([0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4]).astype("float32"), cudf.Series([3, 2, 3, 4, 3, 3, 2, 3, 4, 3, 3, 2, 3, 4, 3]).astype("float32"), prefixes=cudf.Series([0, 5, 10, 15]).astype("int32"), ) cudf.testing.assert_frame_equal( result.c, cudf.DataFrame({ "d3": [ 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, ], "d2": [0, 3, 3, -6, 0, 3, 3, -6, 0, 3, 3, -6], "d1": [ -1.5, -4.5, -4.5, 22.5, -1.5, -4.5, -4.5, 22.5, -1.5, -4.5, -4.5, 22.5, ], "d0": [3, 4, 4, -23, 3, 4, 4, -23, 3, 4, 4, -23], }), check_dtype=False, )