ezmsg.sigproc.linear#

Apply a linear transformation: output = scale * input + offset.

Supports per-element scale and offset along a specified axis. For full matrix transformations, use AffineTransformTransformer instead.

Note

This module supports the Array API standard, enabling use with NumPy, CuPy, PyTorch, and other compatible array libraries.

Classes

class LinearTransform(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[LinearTransformSettings, AxisArray, AxisArray, LinearTransformTransformer]

Unit wrapper for LinearTransformTransformer.

Parameters:

settings (Settings | None)

SETTINGS#

alias of LinearTransformSettings

class LinearTransformSettings(scale: float | list[float] | Buffer | numpy._typing._array_like._SupportsArray[dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[dtype[Any]]] | complex | bytes | str | numpy._typing._nested_sequence._NestedSequence[complex | bytes | str] = 1.0, offset: float | list[float] | Buffer | numpy._typing._array_like._SupportsArray[dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[dtype[Any]]] | complex | bytes | str | numpy._typing._nested_sequence._NestedSequence[complex | bytes | str] = 0.0, axis: str | None = None)[source]#

Bases: Settings

Parameters:
scale: float | list[float] | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = 1.0#

Scale factor(s). Can be a scalar (applied to all elements) or an array matching the size of the specified axis for per-element scaling.

offset: float | list[float] | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = 0.0#

Offset value(s). Can be a scalar (applied to all elements) or an array matching the size of the specified axis for per-element offset.

axis: str | None = None#

Axis along which to apply per-element scale/offset. If None, scalar scale/offset are broadcast to all elements.

__init__(scale=1.0, offset=0.0, axis=None)#
Parameters:
Return type:

None

class LinearTransformState[source]#

Bases: object

scale: ndarray[tuple[Any, ...], dtype[_ScalarT]] = None#

Prepared scale array for broadcasting.

offset: ndarray[tuple[Any, ...], dtype[_ScalarT]] = None#

Prepared offset array for broadcasting.

class LinearTransformTransformer(*args, **kwargs)[source]#

Bases: BaseStatefulTransformer[LinearTransformSettings, AxisArray, AxisArray, LinearTransformState]

Apply linear transformation: output = scale * input + offset.

This transformer is optimized for element-wise linear operations with optional per-channel (or per-axis) coefficients. For full matrix transformations, use AffineTransformTransformer instead.

Examples

# Uniform scaling and offset >>> transformer = LinearTransformTransformer(LinearTransformSettings(scale=2.0, offset=1.0))

# Per-channel scaling (e.g., for 3-channel data along “ch” axis) >>> transformer = LinearTransformTransformer(LinearTransformSettings( … scale=[0.5, 1.0, 2.0], … offset=[0.0, 0.1, 0.2], … axis=”ch” … ))

class LinearTransformSettings(scale: float | list[float] | Buffer | numpy._typing._array_like._SupportsArray[dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[dtype[Any]]] | complex | bytes | str | numpy._typing._nested_sequence._NestedSequence[complex | bytes | str] = 1.0, offset: float | list[float] | Buffer | numpy._typing._array_like._SupportsArray[dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[dtype[Any]]] | complex | bytes | str | numpy._typing._nested_sequence._NestedSequence[complex | bytes | str] = 0.0, axis: str | None = None)[source]#

Bases: Settings

Parameters:
scale: float | list[float] | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = 1.0#

Scale factor(s). Can be a scalar (applied to all elements) or an array matching the size of the specified axis for per-element scaling.

offset: float | list[float] | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = 0.0#

Offset value(s). Can be a scalar (applied to all elements) or an array matching the size of the specified axis for per-element offset.

axis: str | None = None#

Axis along which to apply per-element scale/offset. If None, scalar scale/offset are broadcast to all elements.

__init__(scale=1.0, offset=0.0, axis=None)#
Parameters:
Return type:

None

class LinearTransformState[source]#

Bases: object

scale: ndarray[tuple[Any, ...], dtype[_ScalarT]] = None#

Prepared scale array for broadcasting.

offset: ndarray[tuple[Any, ...], dtype[_ScalarT]] = None#

Prepared offset array for broadcasting.

class LinearTransformTransformer(*args, **kwargs)[source]#

Bases: BaseStatefulTransformer[LinearTransformSettings, AxisArray, AxisArray, LinearTransformState]

Apply linear transformation: output = scale * input + offset.

This transformer is optimized for element-wise linear operations with optional per-channel (or per-axis) coefficients. For full matrix transformations, use AffineTransformTransformer instead.

Examples

# Uniform scaling and offset >>> transformer = LinearTransformTransformer(LinearTransformSettings(scale=2.0, offset=1.0))

# Per-channel scaling (e.g., for 3-channel data along “ch” axis) >>> transformer = LinearTransformTransformer(LinearTransformSettings( … scale=[0.5, 1.0, 2.0], … offset=[0.0, 0.1, 0.2], … axis=”ch” … ))

class LinearTransform(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[LinearTransformSettings, AxisArray, AxisArray, LinearTransformTransformer]

Unit wrapper for LinearTransformTransformer.

Parameters:

settings (Settings | None)

SETTINGS#

alias of LinearTransformSettings