Skip to content

[Sad Catapella N6][Performance/Validation] RGB fit computes full image histograms before rejecting invalid channel count or pixel dtype #52

Closed

Description

@guijacquemet

Baseline and classification

Normalization Batch 6 at f784c95e3049483f87466150ffc5764375fa631d. Confirmed avoidable workload and late input rejection, runtime cost not measured.

Evidence

  • fit() lines 357–379 calls _pixel_histograms(statistics, channel_axis) unconditionally for pixel-array inputs and only afterward calls check_rgb(channel_count, _dtypes(items)).
  • _pixel_histograms() lines 436–442 constructs a complete histogram for each supplied channel, using np.take copies. For a four-channel uint16 FOV the calculation may include large per-channel arrays and multiple passes before a simple channel-count check rejects the RGB input. For invalid float32 RGB data, float histogram/range-check processing is similarly wasted.
  • RGB tests assert the errors but never assert they happen before histogram extraction. Prior performance issue #40 concerns unnecessary copies for valid pixel-array fits; this issue concerns needless full-image computation on invalid RGB input.

Fix / acceptance

When settings.image_type == 'rgb' and statistics is a raw array, check validated channel-axis cardinality and raw dtype before _pixel_histograms. For record inputs, validate first record/channel_count and group dtype consistency before constructing pooled histograms. Ensure invalid channel_axis errors remain actionable, empty planes still report NoValidPixelsError as before, and the preflight policy agrees with #23's resolved RGB dtype support. Use monkeypatched histogram function to assert zero histogram calls for invalid RGB shape/dtype, and test both positive and negative axis indexing, 3-channel uint8/16 success, noncontiguous view, and mixed records. Benchmark rejected large FOV latency and peak memory but no fabricated speedup claims. Numba is not required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions