def function_points_to_proto(
    x: Sequence[float] | np.ndarray,
    y: Sequence[float] | np.ndarray,
    msg: program_pb2.CustomArg | None = None,
) -> program_pb2.CustomArg:
    """Return CustomArg that expresses a function through its x and y values.

    Args:
        x: Sequence of values of the free variable.
            For 1D functions, this input is assumed to be given in increasing order.
        y: Sequence of values of the dependent variable.
            Where y[i] = func(x[i]) where `func` is the function being encoded.
        msg: Optional CustomArg to serialize to.
            If not provided a CustomArg is created.

    Returns:
        A CustomArg encoding the function.

    Raises:
        ValueError: If
            - `x` is 1D and not sorted in increasing order.
            - `x` and `y` don't have the same number of points.
            - `y` is multidimensional.
            - `x` is multidimensional.
    """

    x = np.asarray(x)
    y = np.asarray(y)

    if len(x.shape) != 1:
        raise ValueError('The free variable must be one dimensional')

    if len(x.shape) == 1 and not np.all(np.diff(x) > 0):
        raise ValueError('The free variable must be sorted in increasing order')

    if len(y.shape) != 1:
        raise ValueError('The dependent variable must be one dimensional')

    if x.shape[0] != y.shape[0]:
        raise ValueError('Mismatch between number of points in x and y')

    if msg is None:
        msg = program_pb2.CustomArg()
    msg.function_interpolation_data.x_values[:] = x
    msg.function_interpolation_data.y_values[:] = y
    return msg
Return CustomArg that expresses a function through its x and y values.

    Args:
        x: Sequence of values of the free variable.
            For 1D functions, this input is assumed to be given in increasing order.
        y: Sequence of values of the dependent variable.
            Where y[i] = func(x[i]) where `func` is the function being encoded.
        msg: Optional CustomArg to serialize to.
            If not provided a CustomArg is created.

    Returns:
        A CustomArg encoding the function.

    Raises:
        ValueError: If
            - `x` is 1D and not sorted in increasing order.
            - `x` and `y` don't have the same number of points.
            - `y` is multidimensional.
            - `x` is multidimensional.
    
cirq-google/cirq_google/ops/internal_gate.py