nirs4all.pipeline.analysis.shape_inference module

Pre-fit operator output-shape inference.

Editor-time answer to “given this operator, these params and an input shape, what shape comes out?” — without fitting anything. Fitted estimators expose n_features_out_ only after fit; UIs (e.g. the nirs4all-studio pipeline editor) need the static answer while the user is still composing the pipeline.

The semantics live HERE, next to the operators, so adding or changing an operator keeps its shape rule in the same repo (previously hand-encoded in the studio HTTP layer — boundary violation PIPE-01 in its 2026-06-05 closeout).

infer_output_shape() returns None for unknown operators — callers should treat that as “shape-preserving, not guaranteed”.

nirs4all.pipeline.analysis.shape_inference.DIMENSION_BOUND_PARAMS: dict[str, str] = {'end': 'features', 'n_components': 'features', 'n_features': 'features', 'n_splits': 'samples', 'start': 'features', 'target_points': 'features', 'window_length': 'features'}

Parameters whose value is bounded by an input dimension. Maps parameter name to the bounding dimension ("features" or "samples").

nirs4all.pipeline.analysis.shape_inference.infer_output_shape(operator_name: str, params: Mapping[str, Any] | None, samples: int, features: int) → tuple[int, int] | None[source]

Infer an operator’s output shape before fitting.

Parameters:
  • operator_name – Display/class name of the operator (e.g. "PCA", "SNV", "CropTransformer").

  • params – Operator parameters as authored in the pipeline config.

  • samples – Input sample count.

  • features – Input feature count.

Returns:

(samples, features) after the operator, or None when the operator has no registered rule or its shape is data-dependent (callers should treat unknown operators as shape-preserving but unverified).