Block

class npdsp.Block(name: str | None = None)[source]

Base class for all npDSP processing blocks.

A block transforms an input signal into an output signal. Blocks can be composed into Pipeline objects using the >> operator.

Parameters:

name (str, optional) – Optional name used to identify the block within a pipeline.

Notes

Subclasses must implement process(). Blocks are stateless by default, but subclasses can override stateful and reset() when they maintain state between calls.

abstractmethod process(x: NDArray[Any]) NDArray[Any][source]

Process an input signal.

Parameters:

x (Signal) – Input signal to process.

Returns:

Processed output signal.

Return type:

Signal

Raises:

NotImplementedError – Raised if a subclass does not implement this method.

profile(x: NDArray[Any], runs: int = 1, reset: bool = False) ProfileResults[source]

Profile the execution time of the block.

The block is executed one or more times and the minimum, mean, and maximum execution times are recorded.

Parameters:
  • x (Signal) – Input signal to process during profiling.

  • runs (int, default=1) – Number of times to execute the block.

  • reset (bool, default=False) – If True, reset the block before and after profiling.

Returns:

Profiling results containing the minimum, mean, and maximum execution times.

Return type:

ProfileResults

Notes

The output of each run is passed as the input to the next run. Therefore, for stateful blocks, successive runs may operate on different inputs or internal states.

reset() None[source]

Reset the internal state of the block.

Stateless blocks do not need to perform any action when reset. Stateful subclasses should override this method to restore their initial state.

property stateful: bool

Whether the block maintains state between calls.

Returns:

False by default. Stateful blocks should override this property and return True.

Return type:

bool