Skip to content

qiu_signals.arithmetic

Arithmetic operators shared by the signal classes.

Classes:

  • ArithmeticOperators –

    Mixin implementing the arithmetic operators through a single _binary.

Functions:

  • is_scalar –

    Whether the value is a scalar number, e.g. a Python or NumPy number.

  • require_same_axis –

    Raise if two signals to be combined are not sampled on equal axes.

Attributes:

  • BinaryOperator –

    An elementwise binary operator, e.g. operator.add.

BinaryOperator module-attribute

BinaryOperator = Callable[[Any, Any], Any]

An elementwise binary operator, e.g. operator.add.

ArithmeticOperators

Mixin implementing the arithmetic operators through a single _binary.

Subclasses implement _binary(other, op, reflected), which combines the signal with other by the elementwise operator op, as op(self, other) or, if reflected, as op(other, self). It returns NotImplemented for unsupported operands, so that Python tries the other operand's operator.

is_scalar

is_scalar(value: object) -> bool

Whether the value is a scalar number, e.g. a Python or NumPy number.

Source code in packages/qiu-signals/src/qiu_signals/arithmetic.py
12
13
14
def is_scalar(value: object) -> bool:
    """Whether the value is a scalar number, e.g. a Python or NumPy number."""
    return isinstance(value, Number)

require_same_axis

require_same_axis(axis: object, other_axis: object) -> None

Raise if two signals to be combined are not sampled on equal axes.

Source code in packages/qiu-signals/src/qiu_signals/arithmetic.py
17
18
19
20
21
22
23
def require_same_axis(axis: object, other_axis: object) -> None:
    """Raise if two signals to be combined are not sampled on equal axes."""
    if axis != other_axis:
        raise ValueError(
            f"Signals can only be combined on equal axes, got {axis!r} and "
            f"{other_axis!r}."
        )