예제 #1
0
def clamp_min(s: "Stream[float]", c_min: float) -> "Stream[float]":
    """Clamps the minimum value of a stream.

    Parameters
    ----------
    s : `Stream[float]`
        A float stream.
    c_min : float
        The mimimum value to clamp by.

    Returns
    -------
    `Stream[float]`
        The minimum clamped stream of `s`.
    """
    return BinOp(np.maximum)(s, Stream.constant(c_min)).astype("float")
예제 #2
0
def mul(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]":
    """Computes the multiplication of two float streams.

    Parameters
    ----------
    s1 : `Stream[float]`
        The first float stream.
    s2 : `Stream[float]` or float
        The second float stream.

    Returns
    -------
    `Stream[float]`
        A stream created from multiplying `s1` and `s2`.
    """
    if np.isscalar(s2):
        s2 = Stream.constant(s2, dtype="float")
        return BinOp(np.multiply, dtype="float")(s1, s2)
    return BinOp(np.multiply, dtype="float")(s1, s2)
예제 #3
0
def rsub(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]":
    """Computes the reverse subtraction of two float streams.

    Parameters
    ----------
    s1 : `Stream[float]`
        The first float stream.
    s2 : `Stream[float]` or float
        The second float stream.

    Returns
    -------
    `Stream[float]`
        A stream created from subtracting `s1` from `s2`.
    """
    if not np.isscalar(s2):
        raise Exception("Invalid stream operation.")
    s2 = Stream.constant(s2, dtype="float")
    return BinOp(np.subtract, dtype="float")(s2, s1)
예제 #4
0
def sub(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]":
    """Computes the subtraction of two float streams.

    Parameters
    ----------
    s1 : `Stream[float]`
        The first float stream.
    s2 : `Stream[float]` or float
        The second float stream.

    Returns
    -------
    `Stream[float]`
        A stream created from subtracting `s2` from `s1`.
    """
    if np.isscalar(s2):
        s2 = Stream.constant(s2, dtype="float")
        return BinOp(np.subtract, dtype="float")(s1, s2)
    return BinOp(np.subtract, dtype="float")(s1, s2)
예제 #5
0
def truediv(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]":
    """Computes the division of two float streams.

    Parameters
    ----------
    s1 : `Stream[float]`
        The first float stream.
    s2 : `Stream[float]` or float
        The second float stream.

    Returns
    -------
    `Stream[float]`
        A stream created from dividing `s1` by `s2`.
    """
    if np.isscalar(s2):
        s2 = Stream.constant(s2, dtype="float")
        return BinOp(np.divide, dtype="float")(s1, s2)
    return BinOp(np.divide, dtype="float")(s1, s2)