← Back to Pull requests

Add a MaskAwareCodecMixin so that inner codecs can skip masked values #4

Open
unknown opened this pull request with 231 lines diff across 2 files
View on GitHub
unknown unknown commented on Sep 30, 2026 11:11 UTC
Author

Summary

This PR adds a small protocol that lets the inner codec of a MaskMetaCodec know which values are masked, so that it can skip them instead of encoding a fill value for them.

  • new numcodecs_mask.abc.MaskAwareCodecMixin with two abstract methods, encode_masked(buf, mask) and decode_masked(buf, mask, out=None). The mask is a boolean array of the data's shape marking values that do not need to be preserved; the values at masked positions are unspecified on input and output.

  • MaskMetaCodec calls encode_masked/decode_masked on inner codecs that implement the mixin (the bitmap is now decoded first, then the data), and falls back to encode/decode otherwise. The stream format is unchanged and mask-unaware codecs behave exactly as before.

  • MaskMetaCodec implements the mixin itself, so nested mask meta-codecs forward the union of their masks to the innermost codec.

  • tests with a sparse test codec (only unmasked values are stored, received masks are recorded): single mask, nested masks (union), and unchanged behaviour for mask-unaware codecs.
  • Motivation

    Entropy coders that condition on neighbouring values (e.g. the context-mixing coders in numcodecs-context-mixing) can avoid spending any bits on masked values and treat them as missing in their contexts. In the missing-values challenge of the compression lab (69 % NaN), coding a fill value for the masked positions costs 13 % of the compression ratio compared to skipping them; a mask-aware inner codec recovers this while keeping the masking modular.

    Follow-ups (not in this PR)

  • forwarding masks through CodecStack/FramedCodecStack (numcodecs-combinators) and through pw_ratio to their inner codecs,

  • mask-aware implementations in numcodecs-eb-quantize and numcodecs-context-mixing.
  • Diff: 231 lines (+173 / -58) across 2 files Reviewer: juntyr Review duration: 16932m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.37) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 231 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.326
    Real PR Conversation Timeline
    1 comments
    "Review active on #4"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37% (MEDIUM) · Higher = larger blast radius
    37%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.7% · Safe to merge
    19.7%