§
    ß©ºj!ã  ã                  óN  — U d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	m
Z
mZ ddlZddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZ dd	lmZ e	d
         Ze	d         Ze	d         ZdZ de!d<   ddœd©d„Z"dªd„Z#d«d „Z$d¬d#„Z%d­d(„Z&d®d)„Z'd¯d*„Z(d°d.„Z)d±d3„Z*	 	 d²d³d;„Z+d´d@„Z,dµdD„Z-d¶dH„Z.d·dN„Z/d¸dP„Z0d¹dQ„Z1dRddSddTœdºdX„Z2d»dZ„Z3d¼d\„Z4dRddSddd]œd½dc„Z5d¾df„Z6d¿dg„Z7dÀdh„Z8didjœdÁdn„Z9dÂdt„Z:dÃd€„Z;dÄd‚„Z<dÅdƒ„Z=dÆd†„Z>dÇdˆ„Z?dÈd‰„Z@dÉdŒ„ZAdÊd�„ZBd‘ZCd’e!d“<   d”dRddSd•d–ddd—ddd˜œdËd¥„ZDdÌd¦„ZEdÍd¨„ZFdS )ÎuK  Per-sample ingest route: framework-shaped records to vernier's inputs.

ADR-0063. A training loop holds predictions and ground truth as one
record per image, in whatever array type its framework uses. vernier
takes columnar ground truth (ADR-0060) and one of three detection
routes (ADR-0030, ADR-0057). This module is the conversion between
them, and it is the only place that conversion should be written.

The rules it encodes are the reason it exists. Each descends from a
pycocotools quirk vernier already dispositions, and most are silent
when violated rather than loud:

* every image gets an ``images`` entry, including one with no
  annotations â€” the evaluation counts images, not annotations;
* annotation ids start at **1**; COCOeval's results are wrong from 0;
* ``area`` falls back **per element**, to the mask's area whenever the
  annotation carries a mask and to the box's when it does not, which is
  what COCOeval buckets by (quirk **J3**) â€” a framework that never
  recorded an area stores zeros, so the fallback is load-bearing;
* ``iscrowd`` is widened to ``int64``: vernier reads any non-zero as a
  crowd, so a ``uint8`` column wraps 256 to 0 (quirks **D1**, **E1**);
* image sizes resolve as :func:`vernier.adapters.with_mask_image_sizes`
  resolves them â€” the image's own first mask, else the size its
  detections carry, else the ``0x0`` nothing reads;
* an empty per-image box array may arrive ``(1, 0)`` rather than
  ``(0, 4)`` (TorchMetrics' ``_fix_empty_tensors`` shapes it that way to
  avoid a DDP all-reduce hang), which breaks both concatenation and
  per-image counting unless it is normalized first;
* the fastest detection route depends on whether masks are present â€”
  the ``(N, 7)`` matrix carries box state with no Python object per
  detection, while a mask needs the columnar route, the only one that
  carries one *and* keeps the arrays whole.

**No framework is imported or named.** Arrays are read through DLPack
or :func:`numpy.asarray`, and a device tensor is moved by duck-typed
``.detach()`` / ``.cpu()``. ``tests/python/test_no_framework_imports.py``
is the gate.
é    )ÚannotationsN)ÚMappingÚSequence)ÚAnyÚLiteralÚ	TypeAliasÚcast)ÚNDArray)Ú_core)ÚDetectionColumnsÚ
DetectionsÚDetectionsInputÚ
GtCategoryÚ
PredictionÚRLEInputÚTargetÚTargetColumns)Ú
ParityMode©ÚxywhÚxyxyÚcxcywh©ÚautoÚsuppliedÚboxÚmask©ÚbboxÚsegmz6Prediction | Target | DetectionColumns | TargetColumnsr   Ú
_ColumnishT©Úcast_inputsÚvaluer   ÚfieldÚstrr#   ÚboolÚreturnúNDArray[Any]c               ó$  — t          | d¦  «        r|                      ¦   «         } t          | d¦  «        r|                      ¦   «         } 	 t          j        | ¦  «        }n1# t
          t          f$ r}t          | |||¬¦  «        }Y d}~nd}~ww xY w|S )aÅ  Return ``value`` as a numpy array without naming its framework.

    ``.detach()`` drops an autograd graph and ``.cpu()`` moves a device
    tensor; both are probed by attribute, so torch, jax and anything
    else offering them work, and numpy (offering neither) falls straight
    through. The final :func:`numpy.asarray` is zero-copy for any CPU
    buffer exporting the array or DLPack protocol; only a dtype it
    refuses costs anything more.
    ÚdetachÚcpur"   N)Úhasattrr+   r,   ÚnpÚasarrayÚ	TypeErrorÚ
ValueErrorÚ_as_f64_unrepresentable)r$   r%   r#   ÚarrayÚexcs        ú`/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/vernier/_samples.pyÚ	_as_arrayr6   K   s¦   € õ ˆu�hÑÔð Ø—’‘”ˆÝˆu�eÑÔð Ø—	’	‘”ˆðTÝ œj¨Ñ/Ô/ˆˆøÝ•zÐ"ð Tð Tð TÝ'¨¨u°cÀ{ÐSÑSÔSˆˆˆˆˆˆøøøøðTøøøà€Ls   Á
A ÁBÁ0BÂBr4   Ú	Exceptionc               óú   — |st          |› d|› d�¦  «        |‚t          | d¦  «        r>	 t          j        |                      ¦   «         ¦  «        S # t           t
          f$ r Y nw xY wt          |› d|› d�¦  «        |‚)a±  Retry a dtype numpy has no equivalent for, through the value's own f64 conversion.

    An autocast training loop holds ``bfloat16``, which numpy cannot
    represent, so :func:`numpy.asarray` refuses the tensor outright and
    the caller sees a dtype complaint naming a library vernier never
    mentions. ``.double()`` is probed by attribute like ``.detach()``
    above, and is exact -- ``bfloat16`` is ``float32`` with a truncated
    mantissa, so this invents no precision the value did not have.

    Converting is what ``cast_inputs`` gates (ADR-0004, ADR-0030), so
    ``cast_inputs=False`` refuses here rather than in
    :func:`_cast_f64`, which would never see this value.
    z>: expected dtype float64, got a dtype numpy cannot represent (z<). Pass cast_inputs=True to convert, or convert it yourself.Údoublez: cannot read as an array (ú))r0   r-   r.   r/   r9   r1   )r$   r%   r4   r#   s       r5   r2   r2   `   s¾   € ð  ð ÝØð Hð HÐTWð Hð Hð Hñ
ô 
ð ð	õ ˆu�hÑÔð ð	Ý”:˜eŸlšl™nœnÑ-Ô-Ð-øÝ�:Ð&ð 	ð 	ð 	ØˆDð	øøøå
�uÐ?Ð?¸Ð?Ð?Ð?Ñ
@Ô
@ÀcÐIs   ª%A ÁA$Á#A$r3   úNDArray[np.float64]c               ó¤   — | j         t          j        k    r|st          |› d| j         › d�¦  «        ‚t          j        | t          j        ¬¦  «        S )a  Convert ``array`` to ``dtype``, or refuse when casting is off.

    ADR-0004 pins ``f64`` at the array boundary and ADR-0030 refuses
    ``f32`` rather than promoting it silently, because a silent
    promotion resurfaces as parity drift. That reasoning holds where the
    caller chose the dtype. It does not hold here: a model emits
    ``float32``, so refusing it would make every caller write the
    conversion this route exists to delete. ``cast_inputs=False``
    restores the strict boundary for a caller who wants it.
    z: expected dtype float64, got z;. Pass cast_inputs=True to convert, or convert it yourself.©Údtype)r>   r.   Úfloat64r0   r/   )r3   r%   r#   s      r5   Ú	_cast_f64r@   }   sh   € ð „{•b”jÒ Ð ¨Ð ÝØð Hð H°E´Kð Hð Hð Hñ
ô 
ð 	
õ Œ:�e¥2¤:Ð.Ñ.Ô.Ð.ó    Ú
box_formatÚ	BoxFormatc               óØ  — t          | ||¬¦  «        }|j        r7|j        dk    s|j        d         dk    rt	          |› d|j        › d�¦  «        ‚n$|j        dk    rt	          |› d|j        › �¦  «        ‚t          |||¬¦  «        }t          j        |d¦  «        }|dk    rt          j        |¦  «        S t          j	        |¦  «        }|d	k    r>|d
d
…dd…f         |d
d
…dd…f<   |d
d
…dd…f         |d
d
…dd…f         z
  |d
d
…dd…f<   n\|dk    rA|d
d
…dd…f         |d
d
…dd…f<   |d
d
…dd…f         |d
d
…dd…f         dz  z
  |d
d
…dd…f<   nt	          |› d|›d�¦  «        ‚|S )a!  Return one image's boxes as ``(N, 4)`` float64 in COCO ``xywh``.

    ``reshape(-1, 4)`` is a no-op on an already-``(N, 4)`` array and
    turns the ``(1, 0)`` empty TorchMetrics produces back into
    ``(0, 4)``, which is the shape concatenation and per-image counting
    both need.
    r"   é   é   é   z&: expected an (N, 4) array, got shape uF   . A transposed (4, N) layout is not accepted â€” pass boxes row-major.)éÿÿÿÿrG   r   r   Nr   r   g       @z: unknown box_format ú%; expected 'xywh', 'xyxy' or 'cxcywh')
r6   ÚsizeÚndimÚshaper1   r@   r.   ÚreshapeÚascontiguousarrayÚ
empty_like)r$   rB   r%   r#   r3   ÚcastedÚboxesÚ	converteds           r5   Ú_boxesrS   �   s
  € õ �e˜U°Ð<Ñ<Ô<€Eð „zð XØŒ:˜Š?ˆ?˜eœk¨!œn°Ò1Ð1ÝØð Wð WÀÄð Wð Wð Wñô ð ð 2ð
 
Œ�aŠˆÝ˜EÐVÐVÈÌÐVÐVÑWÔWÐWÝ�u˜e°Ð=Ñ=Ô=€FÝŒJ�v˜wÑ'Ô'€EØ�VÒÐÝÔ# EÑ*Ô*Ð*Ý”˜eÑ$Ô$€IØ�VÒÐØ! ! ! ! Q q S &œMˆ	�!�!�!�Q�q�S�&ÑØ! ! ! ! Q q S &œM¨E°!°!°!°Q°q°S°&¬MÑ9ˆ	�!�!�!�Q�q�S�&ÑÐØ	�xÒ	Ð	Ø! ! ! ! Q q S &œMˆ	�!�!�!�Q�q�S�&ÑØ! ! ! ! Q q S &œM¨E°!°!°!°Q°q°S°&¬M¸CÑ,?Ñ?ˆ	�!�!�!�Q�q�S�&ÑÐõ ØÐ^Ð^¨:Ð^Ð^Ð^ñ
ô 
ð 	
ð ÐrA   ÚrecordúPrediction | TargetÚlabelsúNDArray[np.int64]c               óÐ   — d| vr>t          | ¦  «        r/t          j        t          |¦  «        dft          j        ¬¦  «        S t          t          | d|¦  «        ||› d�|¬¦  «        S )u‡  One record's boxes, which a mask-only pipeline need not carry.

    Under ``segm`` the box column is required by the ground-truth schema
    (ADR-0060) but **no kernel reads it**: matching is on mask IoU, the
    area bucketing reads the ``area`` column, and detection areas come
    from the mask (``dt_area="mask"``). Verified by construction â€” true,
    zeroed and deliberately wrong boxes all produce identical ``segm``
    metrics. So an instance-segmentation pipeline that never materializes
    boxes, which TorchMetrics also permits under ``iou_type="segm"``, can
    omit them and gets a zero column it cannot observe.

    This is the same move :func:`vernier.adapters.with_mask_image_sizes`
    already makes for an unsized image (ADR-0055): fill where nothing
    looks, rather than demand a value the caller does not have.

    A bbox grid over that zero column reports 0, so
    :func:`coco_metrics` refuses ``iou_type="bbox"`` when a record omits
    its boxes, and a caller driving a grid directly owns the same check.
    vernier will not derive the box from the mask: ADR-0057 refuses to
    repair an input the caller did not supply.
    rQ   rG   r=   ú.boxesr"   )Ú
_has_masksr.   ÚzerosÚlenr?   rS   Ú	_required)rT   r%   rV   rB   r#   s        r5   Ú_record_boxesr^   ¾   st   € ð: �fÐÐ¥¨FÑ!3Ô!3ÐÝŒx�˜V™œ aÐ(µ´
Ð;Ñ;Ô;Ð;ÝÝ�&˜' 5Ñ)Ô)¨:¸%Ð7GÐ7GÐ7GÐU`ðñ ô ð rA   c                ó|  — t          | |¦  «        }|j        j        dk    rA|j        r9t	          j        |t	          j        |¦  «        ¦  «        st          |› d�¦  «        ‚n'|j        j        dvrt          |› d|j        › �¦  «        ‚t	          j	        |t          j
        ¬¦  «        }t	          j        |d¦  «        S )u…  Return an integer column as ``(N,)`` int64, refusing fractional values.

    A float column is checked before the cast rather than truncated. For
    ``labels``, ``2.7`` silently becoming class 2 is a wrong evaluation
    with no diagnostic; for ``iscrowd``, ``0.5`` truncates to 0 and
    un-crowds the annotation â€” the same silent outcome the int64
    widening exists to prevent.
    Úfz): must be integral, got fractional valuesÚiubz!: expected an integer array, got r=   ©rH   )r6   r>   ÚkindrJ   r.   Úarray_equalÚfloorr1   r0   r/   Úint64rM   )r$   r%   r3   Úintegerss       r5   Ú	_integersrh   â   s¸   € õ �e˜UÑ#Ô#€EØ„{Ô˜3ÒÐØŒ:ð 	R�bœn¨UµB´H¸U±O´OÑDÔDð 	RÝ ÐPÐPÐPÑQÔQÐQøØ	ŒÔ	 Ð	&Ð	&Ý˜5ÐPÐPÀ5Ä;ÐPÐPÑQÔQÐQÝ"$¤*¨U½"¼(Ð"CÑ"CÔ"C€HÝŒ:�h Ñ&Ô&Ð&rA   c                ó‚   — t          d| ¦  «        }dD ]+}|                     |¦  «        }|�t          |¦  «        r dS Œ,dS )a,  Whether a record carries any mask, in either accepted spelling.

    A present-but-empty column counts as *no* masks. A caller assembling
    columns generically sets the key unconditionally, and reading that as
    "zero masks for N annotations" would reject a perfectly good
    bbox-only run.
    úMapping[str, Any])ÚrlesÚmasksNTF)r	   Úgetr\   )rT   ÚentryÚkeyr$   s       r5   rZ   rZ   õ   sP   € õ Ð$ fÑ-Ô-€EØ ð ð ˆØ—	’	˜#‘”ˆØÐ¥ U¡¤ÐØ�4�4øØˆ5rA   ÚcountÚintúlist[RLEInput]c                ó–  — t          d| ¦  «        }|                     d¦  «        |                     d¦  «        }}|�t          |¦  «        rt          |¦  «        }nd|�It          |¦  «        r:t	          ||› d�¦  «        }|j        dk    rt          |¦  «        n|j        r|gng }n|€|�g }nt          |› d�¦  «        ‚t          d„ |D ¦   «         ¦  «        st          d	|¦  «        }n§g }|D ]¢}	t          d
t          |	t          ¦  «        r|	nd¦  «        }
|
€$|                     t          d|	¦  «        ¦  «         ŒO|
\  }}|                     t          dt          |d         ¦  «        t          |d         ¦  «        f|dœ¦  «        ¦  «         Œ£t          |¦  «        |k    r%t          |› dt          |¦  «        › d|› d�¦  «        ‚|S )aG  Return one image's masks in a shape vernier's RLE ingest accepts.

    Takes either ``rles`` (already encoded) or ``masks`` (bitmasks).
    A ``(size, counts)`` pair is normalized to the dict form: that pair
    is how a TorchMetrics metric state carries a mask, and it is not one
    of the shapes :data:`RLEInput` names.
    rj   rk   rl   Nz.masksé   z1: a mask column must be spelled 'rles' or 'masks'c              3  ó@   K  — | ]}t          |t          ¦  «        V — Œd S ©N)Ú
isinstanceÚtuple)Ú.0Úitems     r5   ú	<genexpr>z_rles.<locals>.<genexpr>$  s,   è è € Ð9Ð9¨4�z˜$¥Ñ&Ô&Ð9Ð9Ð9Ð9Ð9Ð9rA   rr   z tuple[Sequence[int], Any] | Noner   r   rF   )rJ   Úcountsú: ú masks for z# labels; every annotation needs one)r	   rm   r\   Úlistr6   rK   rJ   ÚKeyErrorÚanyrw   rx   Úappendrq   r1   )rT   r%   rp   rn   rk   rl   Úitemsr3   Ú
normalizedrz   ÚpairrJ   r|   s                r5   Ú_rlesr†     s  € õ Ð$ fÑ-Ô-€EØ—)’)˜FÑ#Ô# U§Y¢Y¨wÑ%7Ô%7ˆ%€DàÐ�C ™IœIÐÝ�T‘
”
ˆˆØ	Ð	�s 5™zœzÐ	Ý˜% EÐ!1Ð!1Ð!1Ñ2Ô2ˆØ$œz¨Qš˜•�U‘”�ÀÄ
Ð5R°e°W°WÐPRˆˆØ	Ð	˜UÐ.Øˆˆå˜%ÐRÐRÐRÑSÔSÐSõ Ð9Ð9°5Ð9Ñ9Ô9Ñ9Ô9ð ÝÐ*¨EÑ2Ô2ˆ
ˆ
ð ˆ
Øð 
	ð 
	ˆDÝØ2½JÀtÍUÑ<SÔ<SÐ4]°D°DÐY]ñô ˆDð ˆ|Ø×!Ò!¥$ z°4Ñ"8Ô"8Ñ9Ô9Ð9Ð9à#‘��fØ×!Ò!Ý˜­s°4¸´7©|¬|½SÀÀaÄ¹\¼\Ð.JÐV\Ð%]Ð%]Ñ^Ô^ñô ð ð õ ˆ:�„˜%ÒÐÝØÐ^Ð^�˜J™œÐ^Ð^°EÐ^Ð^Ð^ñ
ô 
ð 	
ð ÐrA   ÚpredictionsúSequence[Prediction]ÚtargetsúSequence[Target]c           
     ó   — g }t          t          | |d¬¦  «        ¦  «        D ]�\  }\  }}|                     d¦  «        }|                     d¦  «        }|�!|�||k    rt          d|› d|› d|› d�¦  «        ‚|�|n|}|                     |€|nt          |¦  «        ¦  «         Œ‚t          t          |¦  «        ¦  «        t          |¦  «        k    rt          d	¦  «        ‚t          j	        |t          j
        ¬
¦  «        S )uV  Resolve each record pair's image id, defaulting to its position.

    A trainer that never assigns ids gets positional ones, which is what
    ``0..M-1`` means everywhere else in this route. When both sides
    carry an id they must agree â€” a mismatch means the two sequences are
    not aligned, which no downstream check would catch.
    T©ÚstrictÚimage_idNzsamples[z1]: predictions and targets disagree on image_id (z vs z.); the two sequences must be aligned per imagez&image_id must be unique across samplesr=   )Ú	enumerateÚziprm   r1   r‚   rq   r\   Úsetr.   r/   rf   )	r‡   r‰   ÚidsÚiÚ
predictionÚtargetÚ	target_idÚprediction_idÚresolveds	            r5   Ú
_image_idsr™   <  s2  € ð €CÝ#,­S°¸gÈdÐ-SÑ-SÔ-SÑ#TÔ#Tð 	=ð 	=ÑˆÑˆJ˜Ø—J’J˜zÑ*Ô*ˆ	Ø"Ÿš zÑ2Ô2ˆØÐ  ]Ð%>À9ÐP]ÒC]ÐC]Ýða˜1ð að aØ!ðað aØ'0ðað að añô ð ð !*Ð 5�9�9¸=ˆØ�
Š
˜Ð(�1�1­c°(©m¬mÑ<Ô<Ð<Ð<Ý
�3ˆs‰8Œ8�}„}�˜C™œÒ Ð ÝÐAÑBÔBÐBÝŒ:�c¥¤Ð*Ñ*Ô*Ð*rA   Úgt_rlesú#Sequence[Sequence[RLEInput] | None]Údt_rlesú*Sequence[Sequence[RLEInput] | None] | Noner   ú'Sequence[tuple[int, int] | None] | Noneú+tuple[NDArray[np.int64], NDArray[np.int64]]c                óT   — t          d„ | D ¦   «         |€dnd„ |D ¦   «         |¦  «        S )uW  The ``height`` / ``width`` columns a columnar ground truth needs.

    The columnar mirror of :func:`vernier.adapters.detection_image_sizes`.
    ADR-0055 published the dict-shaped resolver and explicitly left this
    case to the caller â€” "the `cocoDt`-less array-grid caller still
    builds the mapping itself, from the first detection mask's ``size``
    per image" â€” which made it the one rule every columnar consumer
    reimplements.

    Resolution order per image: a caller-supplied size wins, else the
    image's own first mask, else the size its detections carry, else
    ``0x0`` â€” the last of which nothing reads, because no annotation
    points at that image. The mask-derived part matches
    :func:`vernier.adapters.with_mask_image_sizes`. Both optional
    sequences must cover every image; a short one is refused rather than
    read as "no size for the rest".

    Args:
        gt_rles: One entry per image â€” that image's ground-truth masks,
            or ``None`` / empty when it has none.
        dt_rles: The same for the detection side, when known.
        supplied: One entry per image â€” the size the caller pinned for
            it (``Target.size``), or ``None``. Takes precedence over
            both mask sources.

    Returns:
        ``(height, width)``, each an ``(M,)`` int64 array aligned with
        ``gt_rles``.
    c                ó&   — g | ]}|r|d          nd‘ŒS ©r   N© ©ry   Úimages     r5   ú
<listcomp>z"gt_image_sizes.<locals>.<listcomp>w  s%   € Ð:Ð:Ð:¨�UÐ	$ˆˆqŒˆ Ð:Ð:Ð:rA   Nc                ó&   — g | ]}|r|d          nd‘ŒS r¢   r£   r¤   s     r5   r¦   z"gt_image_sizes.<locals>.<listcomp>x  s%   € Ð%WÐ%WÐ%WÀe°%Ð&A e¨A¤h h¸TÐ%WÐ%WÐ%WrA   )Ú_sizes_from_firsts)rš   rœ   r   s      r5   Úgt_image_sizesr©   T  sE   € õD Ø:Ð:°'Ð:Ñ:Ô:Ø�ˆˆÐ%WÐ%WÈwÐ%WÑ%WÔ%WØñô ð rA   Úgt_firstúSequence[RLEInput | None]Údt_firstú Sequence[RLEInput | None] | Nonec           	     óþ  — t          | ¦  «        }d|fd|ffD ]?\  }}|�8t          |¦  «        |k    r%t          |› dt          |¦  «        › d|› d�¦  «        ‚Œ@t          j        |t          j        ¬¦  «        }t          j        |t          j        ¬¦  «        }t          |¦  «        D ]S}|€dn||         }	| |         }
|	€|
�t          |
¦  «        }	|	€|�||         }|�t          |¦  «        }	|	�|	\  ||<   ||<   ŒT||fS )uæ  The resolution order itself, over one candidate mask per image.

    Only the *first* mask of an image is ever read, so both callers
    reduce to this â€” :func:`gt_image_sizes` from per-image sequences and
    :func:`_flat_image_sizes` through per-image bounds. One copy of the
    rule, because a fix to it has to land everywhere at once.

    A sequence that does not cover every image is refused rather than
    read as "no size for the rest" (ADR-0057: refuse, never repair).
    Úsizeszdetection masksNr}   ú entries for ú imagesr=   )r\   r1   r.   r[   rf   ÚrangeÚ_size_of)rª   r¬   r   rp   ÚnameÚsequenceÚheightsÚwidthsr“   rJ   ÚfirstÚ	candidates               r5   r¨   r¨   }  s2  € õ �‰MŒM€EØ# XÐ.Ð1BÀHÐ0MÐNð Tð T‰ˆˆhØÐ¥C¨¡M¤M°UÒ$:Ð$:Ý ÐRÐR­¨H©¬ÐRÐRÀEÐRÐRÐRÑSÔSÐSøÝ!#¤¨%µr´xÐ!@Ñ!@Ô!@€GÝ "¤¨µb´hÐ ?Ñ ?Ô ?€FÝ�5‰\Œ\ð 
)ð 
)ˆØÐ'ˆtˆt¨X°a¬[ˆØ˜”ˆØˆ<˜EÐ-Ý˜E‘?”?ˆDØˆ<˜HÐ0Ø  œˆIØÐ$Ý 	Ñ*Ô*�ØÐØ$(Ñ!ˆG�A‰J˜˜q™	øØ�Fˆ?ÐrA   r¸   r   útuple[int, int] | Nonec                óp  — t          | t          ¦  «        rQt          d| ¦  «                             d¦  «        }|€dS t	          |d         ¦  «        t	          |d         ¦  «        fS t          | d¦  «        }|j        dk    rdS t	          |j        d         ¦  «        t	          |j        d         ¦  «        fS )zL``(height, width)`` a single mask declares, or ``None`` if it declares none.rj   rJ   Nr   rF   rk   rE   )rw   Údictr	   rm   rq   r6   rK   rL   )r¸   rJ   r3   s      r5   r³   r³      s¡   € å�%�ÑÔð *ÝÐ'¨Ñ/Ô/×3Ò3°FÑ;Ô;ˆØˆ<Ø�4Ý�4˜”7‰|Œ|�S  a¤™\œ\Ð)Ð)Ý�e˜VÑ$Ô$€EØ„z�Q‚€ØˆtÝˆuŒ{˜1Œ~ÑÔ¥ E¤K°¤NÑ 3Ô 3Ð3Ð3rA   ÚentriesúSequence[GtCategory]úlist[tuple[int, GtCategory]]c                ó   — d„ | D ¦   «         S )zEPair each category with its id, which :func:`_categories` guarantees.c                óX   — g | ]'}t          |                     d d¦  «        ¦  «        |f‘Œ(S )Úidr   )rq   rm   )ry   rn   s     r5   r¦   z_with_ids.<locals>.<listcomp>¯  s3   € ÐBÐBÐB°�S�—’˜4 Ñ#Ô#Ñ$Ô$ eÐ,ÐBÐBÐBrA   r£   )r½   s    r5   Ú	_with_idsrÃ   ­  s   € àBÐB¸'ÐBÑBÔBÐBrA   Ú
categoriesú+Sequence[int] | Sequence[GtCategory] | NoneÚlabel_columnsúSequence[NDArray[np.int64]]úlist[GtCategory]c           	     óh  — | �µt          | ¦  «        }g }t          |¦  «        D ]“\  }}t          |t          ¦  «        r:d|vrt	          d|› d�¦  «        ‚|                     t          |¦  «        ¦  «         ŒT|                     t          |¦  «        t          t          |¦  «        ¦  «        dœ¦  «         Œ”nS|r&t          j	        t          j
        |¦  «        ¦  «        nt          j        dt          j        ¦  «        }d„ |D ¦   «         }d„ t          t          |¦  «        d	„ ¬
¦  «        D ¦   «         S )zôResolve the ``categories`` section.

    ``None`` takes the union of every label seen on **both** sides: a
    class that appears only in predictions is still a category, and
    dropping it would silently stop scoring its false positives.
    NrÂ   zcategories[z] has no 'id'©rÂ   r´   r   c                óf   — g | ].}t          |¦  «        t          t          |¦  «        ¦  «        d œ‘Œ/S )rÊ   )rq   r&   ©ry   r$   s     r5   r¦   z_categories.<locals>.<listcomp>È  s2   € ÐQÐQÐQÀ5�#˜e™*œ*­cµ#°e±*´*©o¬oÐ>Ð>ÐQÐQÐQrA   c                ó   — g | ]\  }}|‘ŒS r£   r£   )ry   Ú_rn   s      r5   r¦   z_categories.<locals>.<listcomp>Í  s   € ÐWÐWÐW‘h�a˜ˆEÐWÐWÐWrA   c                ó   — | d         S )Nr   r£   )r…   s    r5   ú<lambda>z_categories.<locals>.<lambda>Í  s   € ÈdÐSTÌg€ rA   )ro   )r   r�   rw   r¼   r€   r‚   rq   r&   r.   ÚuniqueÚconcatenateÚemptyrf   ÚsortedrÃ   )rÄ   rÆ   r˜   r½   Úpositionr$   Úseens          r5   Ú_categoriesr×   ²  s;  € ð ÐÝ˜
Ñ#Ô#ˆØ$&ˆÝ(¨Ñ2Ô2ð 	Lð 	L‰OˆH�eÝ˜%¥Ñ&Ô&ð LØ˜uÐ$Ð$Ý"Ð#H°Ð#HÐ#HÐ#HÑIÔIÐIØ—’�t E™{œ{Ñ+Ô+Ð+Ð+à—’¥c¨%¡j¤j½#½cÀ%¹j¼j¹/¼/ÐJÐJÑKÔKÐKÐKð	Lð <IÐc�rŒy�œ¨Ñ6Ô6Ñ7Ô7Ð7ÍbÌhÐWXÕZ\ÔZbÑNcÔNcˆØQÐQÈDÐQÑQÔQˆð
 XÐW¥&­°7Ñ);Ô);ÐAUÐAUÐ"VÑ"VÔ"VÐWÑWÔWÐWrA   ro   c                óD   — || vrt          |› d|› d�¦  «        ‚| |         S )u¢  One required field off a record, or a ``KeyError`` naming it.

    Defaulting a missing field to an empty array would turn a misspelled
    key into an annotation-less image or a detection-free prediction â€”
    an evaluation that runs to completion and reports a plausible,
    meaningless number. An image genuinely without annotations says so
    with an explicit empty array (ADR-0057: refuse, never repair).
    ú.zA is required; pass an explicit empty array for an image with none)r€   )rT   ro   r%   s      r5   r]   r]   Ð  sA   € ð �&ÐÐÝØÐ]Ð]�sÐ]Ð]Ð]ñ
ô 
ð 	
ð �#Œ;ÐrA   c               ó¦   — t          t          | ||¦  «        |› d|› �|¬¦  «        }t          ||› d|› �|¬¦  «        }t          j        |d¦  «        S )z)One required float64 column off a record.rÙ   r"   rb   )r6   r]   r@   r.   rM   )rT   ro   r%   r#   r3   Úcolumns         r5   Ú_columnrÜ   à  se   € å•i ¨¨UÑ3Ô3¸Ð5EÐ5EÀÐ5EÐ5EÐS^Ð_Ñ_Ô_€EÝ�u Ð.Ð.¨Ð.Ð.¸KÐHÑHÔH€FÝŒ:�f˜eÑ$Ô$Ð$rA   r   r   ©rB   rÄ   Úarear#   rÞ   Ú
AreaPolicyú)tuple[_core.CocoDataset, DetectionsInput]c               ó<   — t          | |||||¬¦  «        \  }}}||fS )u•  Build vernier's evaluation inputs from per-image records (ADR-0063).

    ``predictions[i]`` and ``targets[i]`` describe the same image; the
    two sequences must be the same length and aligned.

    **There is no ``iou_type``.** The masks decide: records that carry
    them produce inputs a ``segm`` grid can read, and records that do
    not produce bbox-only inputs. Naming the IoU type here as well as at
    the grid would be two places to say one thing and a chance for them
    to disagree â€” and it bought nothing measurable, since attaching
    segmentation costs ~2% of the conversion and the detection route it
    would select is within 0.3% of the alternative on a real grid. One
    set of inputs therefore serves both passes of a two-IoU-type run.

    The pair is returned rather than a metric, because it is what every
    surface that takes a parsed ground truth reads:
    :class:`vernier.instance.Evaluator`, the ``evaluate_*_grid`` and
    ``evaluate_*_summary`` entry points, custom grids (ADR-0040),
    calibration through ``cells_from_grid``, the partitioned/DDP path,
    and â€” since ADR-0064 â€” every instance diagnostic:
    :func:`vernier.instance.error_decomposition` (TIDE),
    :func:`vernier.instance.optimal_lrp`,
    :func:`vernier.instance.confusion_matrix`,
    :func:`vernier.instance.fp_iou_histogram` and the ``tables=`` /
    ``manifest=`` paths of
    :meth:`vernier.instance.Evaluator.evaluate`. One conversion reaches
    all of them; :func:`coco_metrics` is the convenience wrapper for the
    AP case.

    Two of this function's decisions need both sides, which is why it is
    one call and not two: a class seen only in predictions must still
    become a category, and image sizes fall back from the ground truth's
    masks to the detections'.

    Args:
        predictions: One record per image. See :class:`Prediction`.
        targets: One record per image. See :class:`Target`.
        box_format: Layout ``boxes`` is read as. Never auto-detected: a
            ``(N, 4)`` array is ambiguous between ``xywh`` and ``xyxy``,
            and a wrong guess yields plausible, wrong AP rather than an
            error.
        categories: The COCO ``categories`` section, as ids or as
            entries. ``None`` takes the union of every label on both
            sides.
        area: How the ground truth's ``area`` column is filled.
            ``"auto"`` reads a supplied positive area and otherwise
            falls back per element â€” to the mask's area under ``segm``,
            the box's under ``bbox``.
        cast_inputs: Convert array dtypes rather than refusing them.
            On by default here, unlike the rest of vernier's array
            surface; see :func:`_cast`.

    Returns:
        The parsed ground truth and the detections, ready for any
        ``evaluate_*`` entry point.

    Raises:
        ValueError: If the sequences differ in length or are misaligned,
            if a record's columns disagree in length, or if a label is
            fractional.
        KeyError: If a required field is absent.
        TypeError: If a value cannot be read as an array, or its dtype
            is wrong under ``cast_inputs=False``.
    rÝ   )Ú_records_to_inputs)	r‡   r‰   rB   rÄ   rÞ   r#   ÚdatasetÚ
detectionsrÎ   s	            r5   Úcoco_inputsrå   ç  s?   € õR 0ØØØØØØðñ ô Ñ€GˆZ˜ð �JÐÐrA   ú;tuple[_core.CocoDataset, DetectionsInput, list[GtCategory]]c               óŽ
  — t          | ¦  «        t          |¦  «        k    r/t          dt          | ¦  «        › dt          |¦  «        › �¦  «        ‚t          ||¬¦  «         t          | |¦  «        }g }g }g }	g }
g }t	          |¦  «        D �]\  }}d|› d�}t          t          |d|¦  «        |› d�¦  «        }t          |||||¬¦  «        }t          |¦  «        t          |¦  «        k    r2t          |› d	t          |¦  «        › d
t          |¦  «        › d�¦  «        ‚d|v rt          |d         |› d�¦  «        n+t          j	        t          |¦  «        t          j
        ¦  «        }d|v rt          |d||¬¦  «        n t          j	        t          |¦  «        ¦  «        }d|fd|ffD ]Z\  }}t          |¦  «        t          |¦  «        k    r5t          |› d|› d	t          |¦  «        › dt          |¦  «        › d�¦  «        ‚Œ[|                     |¦  «         |                     |¦  «         |	                     |¦  «         |
                     |¦  «         |                     t          |¦  «        rt          ||t          |¦  «        ¦  «        ng ¦  «         �Œg }g }g }g }t	          | ¦  «        D �]N\  }}d|› d�}t          t          |d|¦  «        |› d�¦  «        }t          |||||¬¦  «        }t          |d||¬¦  «        }t          |¦  «        t          |¦  «        cxk    rt          |¦  «        k    sDn t          |› dt          |¦  «        › dt          |¦  «        › dt          |¦  «        › d�¦  «        ‚|                     |¦  «         |                     |¦  «         |                     |¦  «         |                     t          |¦  «        rt          ||t          |¦  «        ¦  «        ng ¦  «         �ŒPd„ |D ¦   «         }d„ |D ¦   «         }t          j        d„ |D ¦   «         t          j
        ¬¦  «        }t          j        d„ |D ¦   «         t          j
        ¬¦  «        }t!          t#          |dt          j        ¦  «        t#          |dt          j
        ¦  «        t#          |	dt          j
        ¦  «        t#          |
dt          j        ¦  «        ||t#          |dt          j        ¦  «        t#          |dt          j        ¦  «        t#          |dt          j
        ¦  «        |||t'          |¦  «        ||¬¦  «        S )aB  :func:`coco_inputs`, also returning the resolved ``categories``.

    :func:`coco_metrics` needs that order for its ``classes`` key and
    for the per-class vectors' axis. Taking it from the resolution the
    build already performs is what keeps the metric wrapper from reading
    every label column a second time.
    z;predictions and targets must describe the same images: got ú and ©rÞ   rB   ztargets[ú]rV   z.labelsr"   r}   ú boxes for ú labelsÚiscrowdz.iscrowdrÞ   rÙ   r°   zpredictions[Úscoresz : boxes/labels/scores disagree (ú, r:   c                ó   — g | ]	}|D ]}|‘ŒŒ
S r£   r£   ©ry   r¥   Úrles      r5   r¦   z&_records_to_inputs.<locals>.<listcomp>†  ó%   € Ð>Ð>Ð>˜E¸Ð>Ð>°�CÐ>Ð>Ð>Ð>rA   c                ó   — g | ]	}|D ]}|‘ŒŒ
S r£   r£   rñ   s      r5   r¦   z&_records_to_inputs.<locals>.<listcomp>‡  ró   rA   c                ó,   — g | ]}t          |¦  «        ‘ŒS r£   ©r\   ©ry   rV   s     r5   r¦   z&_records_to_inputs.<locals>.<listcomp>ˆ  ó   € Ð@Ð@Ð@¨F�C ™KœKÐ@Ð@Ð@rA   r=   c                ó,   — g | ]}t          |¦  «        ‘ŒS r£   rö   r÷   s     r5   r¦   z&_records_to_inputs.<locals>.<listcomp>‰  rø   rA   )r   rG   )r   ©Úgt_boxesÚ	gt_labelsÚ	gt_crowdsÚgt_areaÚ	gt_countsrš   Údt_boxesÚ	dt_scoresÚ	dt_labelsÚ	dt_countsrœ   Ú	image_idsr¯   rÄ   rÞ   )r\   r1   Ú_validate_literalsr™   r�   rh   r]   r^   r.   r[   rf   rÜ   r‚   rZ   r†   r/   Ú_buildÚ_joinr?   Ú_declared_sizes)r‡   r‰   rB   rÄ   rÞ   r#   r  rû   rü   rý   Úgt_suppliedrš   r“   r•   r%   rV   rQ   Úcrowdsr   r´   rÛ   r   r  r  rœ   r”   rî   Úflat_gt_rlesÚflat_dt_rlesrÿ   r  s                                  r5   râ   râ   ;  s—  € õ  ˆ;ÑÔ�3˜w™<œ<Ò'Ð'Ýð9Ý�{Ñ#Ô#ð9ð 9Ý*-¨g©,¬,ð9ð 9ñ
ô 
ð 	
õ ˜D¨ZÐ8Ñ8Ô8Ð8Ý˜;¨Ñ0Ô0€Ià*,€HØ)+€IØ)+€IØ-/€KØ$&€GÝ˜wÑ'Ô'ð Xñ X‰	ˆˆ6Ø˜1���ˆõ �9 V¨X°uÑ=Ô=À%Ð?PÐ?PÐ?PÑQÔQˆÝ˜f e¨V°ZÈ[ÐYÑYÔYˆÝˆu‰:Œ:�˜V™œÒ$Ð$Ý ÐTÐT­¨U©¬ÐTÐTÅÀFÁÄÐTÐTÐTÑUÔUÐUð ˜FÐ"Ð"õ �f˜YÔ'¨EÐ);Ð);Ð);Ñ<Ô<Ð<å”�#˜f™+œ+¥r¤xÑ0Ô0ð 	ð ˜ÐÐõ �F˜F E°{ÐCÑCÔCÐCå”�#˜f™+œ+Ñ&Ô&ð 	ð
 (¨Ð0°6¸8Ð2DÐEð 	dð 	d‰LˆD�&Ý�6‰{Œ{�c &™kœkÒ)Ð)Ý  EÐ!bÐ!b¨DÐ!bÐ!bµC¸±K´KÐ!bÐ!bÍcÐRXÉkÌkÐ!bÐ!bÐ!bÑcÔcÐcð *à�Š˜ÑÔÐØ×Ò˜Ñ Ô Ð Ø×Ò˜Ñ Ô Ð Ø×Ò˜8Ñ$Ô$Ð$Ø�Š½JÀvÑ<NÔ<NÐV•u˜V U­C°©K¬KÑ8Ô8Ð8ÐTVÑWÔWÐWÑWà*,€HØ)+€IØ+-€IØ$&€GÝ" ;Ñ/Ô/ð `ñ `‰ˆˆ:Ø#˜qÐ#Ð#Ð#ˆÝ�9 Z°¸5ÑAÔAÀeÐCTÐCTÐCTÑUÔUˆÝ˜j¨%°¸ÐQ\Ð]Ñ]Ô]ˆÝ˜ X¨uÀ+ÐNÑNÔNˆÝ�E‘
”
�c &™kœkÐ8Ð8Ò8Ð8­S°©[¬[Ò8Ð8Ð8Ð8ÝØð @ð @Ý˜‘J”Jð@ð @Ý"% f¡+¤+ð@ð @Ý14°V±´ð@ð @ð @ñô ð ð 	�Š˜ÑÔÐØ×Ò˜Ñ Ô Ð Ø×Ò˜Ñ Ô Ð Ø�ŠÅ
È:Ñ@VÔ@VÐ^•u˜Z¨µ°F±´Ñ<Ô<Ð<Ð\^Ñ_Ô_Ð_Ñ_à>Ð> WÐ>Ñ>Ô>€LØ>Ð> WÐ>Ñ>Ô>€LÝ”
Ð@Ð@°iÐ@Ñ@Ô@ÍÌÐQÑQÔQ€IÝ”
Ð@Ð@°iÐ@Ñ@Ô@ÍÌÐQÑQÔQ€IÝÝ�x ­¬Ñ4Ô4Ý˜	 4­¬Ñ2Ô2Ý˜	 4­¬Ñ2Ô2Ý�k 4­¬Ñ4Ô4ØØÝ�x ­¬Ñ4Ô4Ý˜	 4­¬Ñ4Ô4Ý˜	 4­¬Ñ2Ô2ØØØÝ˜gÑ&Ô&ØØðñ ô ð rA   ú#list[tuple[int, int] | None] | Nonec                óT   — d„ | D ¦   «         }t          d„ |D ¦   «         ¦  «        r|ndS )zA``Target.size`` per image, or ``None`` when no record pinned one.c                ó8   — g | ]}|                      d ¦  «        ‘ŒS )rJ   )rm   )ry   r•   s     r5   r¦   z#_declared_sizes.<locals>.<listcomp>Ÿ  s$   € Ð9Ð9Ð9 v�—
’
˜6Ñ"Ô"Ð9Ð9Ð9rA   c              3  ó   K  — | ]}|d uV — Œ	d S rv   r£   )ry   rJ   s     r5   r{   z"_declared_sizes.<locals>.<genexpr>   s'   è è € ÐAÐA°˜4 tÐ+ÐAÐAÐAÐAÐAÐArA   N)r�   )r‰   Údeclareds     r5   r  r  �  s;   € à9Ð9°Ð9Ñ9Ô9€HÝÐAÐA¸ÐAÑAÔAÑAÔAÐKˆ8ˆ8ÀtÐKrA   )rB   rÄ   rÞ   r  r#   rä   r   r   r  ú
Any | Nonec               ó	  — t          ||¬¦  «         t          |d¦  «        }t          | d¦  «        }t          |¦  «        t          |¦  «        k    r/t          dt          |¦  «        › dt          |¦  «        › �¦  «        ‚t          |¦  «        }	|€ t	          j        |	t          j        ¬¦  «        n@t	          j        t	          j        t          |d¦  «        t          j        ¬¦  «        d	¦  «        }
t          |
¦  «        |	k    r#t          d
t          |
¦  «        › d|	› d�¦  «        ‚t          t	          j
        |
¦  «        ¦  «        |	k    rt          d¦  «        ‚t          t          |dd¦  «        d¦  «        }t          |d|||¬¦  «        }t          t          | dd¦  «        d¦  «        }t          | d|||¬¦  «        }t          | dd|¬¦  «        }d|t          |¦  «        fd|t          |¦  «        ffD ]b\  }}}t          |                     ¦   «         ¦  «        |k    r7t          |› dt          |                     ¦   «         ¦  «        › d|› d�¦  «        ‚Œct          |¦  «        t          |¦  «        k    r0t          dt          |¦  «        › dt          |¦  «        › d�¦  «        ‚d|v rt          |d         d¦  «        n+t	          j        t          |¦  «        t          j        ¦  «        }d|v rt          |dd|¬¦  «        n+t	          j        t          |¦  «        t          j        ¦  «        }d|fd|ffD ]X\  }}t          |¦  «        t          |¦  «        k    r3t          d|› dt          |¦  «        › dt          |¦  «        › d�¦  «        ‚ŒYd}d|v rˆt	          j        t	          j        t          |d         d ¦  «        t          j        ¦  «        d!¦  «        }t          |¦  «        |	k    r#t          d"t          |¦  «        › d|	› d�¦  «        ‚d#„ |D ¦   «         }t'          |||||t)          |dt          |¦  «        ¦  «        ||||t)          | dt          |¦  «        ¦  «        |
|||¬$¦  «        \  }}}||fS )%aH  Build vernier's evaluation inputs from whole columns (ADR-0063).

    The columnar spelling of :func:`coco_inputs`. Same rules, same
    result -- both land on one builder, and
    ``test_columnar_and_per_sample_agree`` pins the two to the identical
    ``dataset_hash``. What differs is only how the caller already holds
    its state.

    Prefer this when the state is *already* concatenated, which is the
    case for a TorchMetrics-shaped metric: splitting it into per-image
    records for :func:`coco_inputs` only to have vernier concatenate it
    again costs a Python-level pass per image per field, and at
    validation scale that is the most expensive thing on the path. A
    caller with genuine per-image records should use :func:`coco_inputs`
    and not synthesize columns.

    ``counts`` carries the image structure -- entry ``i`` is image
    ``i``'s row count -- so the columns themselves need no image
    grouping. Ground truth and detections have independent counts, both
    of length ``M``.

    Args:
        detections: Every detection, as columns. See
            :class:`DetectionColumns`.
        targets: Every ground-truth annotation, as columns. See
            :class:`TargetColumns`.
        box_format: Layout ``boxes`` is read as; never auto-detected.
        categories: The COCO ``categories`` section, as ids or entries.
            ``None`` takes the union of every label on both sides.
        area: How the ground truth's ``area`` column is filled.
        image_ids: ``(M,)`` image ids, defaulting to ``0..M-1``.
        cast_inputs: Convert array dtypes rather than refusing them.

    Returns:
        The parsed ground truth and the detections, ready for any
        ``evaluate_*`` entry point.

    Raises:
        ValueError: If a ``counts`` column does not sum to its columns'
            length, if the two ``counts`` differ in length, or for any
            reason :func:`coco_inputs` raises.
        KeyError: If a required column is absent.
        TypeError: If a value cannot be read as an array, or its dtype is
            wrong under ``cast_inputs=False``.
    ré   r‰   rä   zHtargets.counts and detections.counts must describe the same images: got rè   Nr=   r  rb   zimage_ids: r°   r±   z&image_ids must be unique across imagesrV   ztargets.labelsr"   zdetections.labelsrî   z.counts sums to z but there are z rowsz$detections: labels/scores disagree (rï   r:   rí   ztargets.iscrowdrÞ   ztargets.r}   rì   r¯   ztargets.sizes)rH   rE   ztargets.sizes: c                óP   — g | ]#\  }}t          |¦  «        t          |¦  «        f‘Œ$S r£   ©rq   )ry   ÚhÚws      r5   r¦   z,coco_inputs_from_columns.<locals>.<listcomp>  s-   € Ð7Ð7Ð7¡d a¨•#�a‘&”&�#˜a™&œ&Ð!Ð7Ð7Ð7rA   rú   )r  Ú_countsr\   r1   r.   Úarangerf   rM   r/   r6   rÑ   rh   r]   Ú_columns_boxesrÜ   rq   Úsumr[   r?   r  Ú
_flat_rles)rä   r‰   rB   rÄ   rÞ   r  r#   rÿ   r  Ún_imagesr’   rü   rû   r  r   r  r´   r|   Úrowsr
  r   rÛ   r¯   r  rã   Údetections_inputrÎ   s                              r5   Úcoco_inputs_from_columnsr   £  sÀ  € õn ˜D¨ZÐ8Ñ8Ô8Ð8Ý˜ Ñ+Ô+€IÝ˜
 LÑ1Ô1€IÝ
ˆ9�~„~�˜Y™œÒ'Ð'Ýð9Ý�y‘>”>ð9ð 9Ý(+¨I©¬ð9ð 9ñ
ô 
ð 	
õ �9‰~Œ~€Hð Ðõ 	Œ	�(¥"¤(Ð+Ñ+Ô+Ð+åŒZ�œ
¥9¨Y¸Ñ#DÔ#DÍBÌHÐUÑUÔUÐW\Ñ]Ô]ð õ
 ˆ3�x„x�8ÒÐÝÐO¥s¨3¡x¤xÐOÐO¸hÐOÐOÐOÑPÔPÐPõ �2Œ9�S‰>Œ>ÑÔ˜hÒ&Ð&ÝÐAÑBÔBÐBå�) G¨X°yÑAÔAÐCSÑTÔT€IÝ˜g y°)¸ZÐU`ÐaÑaÔa€HÝ�) J°¸,ÑGÔGÐI\Ñ]Ô]€IÝØ�L )¨ZÀ[ðñ ô €Hõ ˜
 H¨lÈÐTÑTÔT€Ið 
�I�s 9™~œ~Ð.Ø	�y¥# i¡.¤.Ð1ðð eð eÑˆˆf�dõ ˆv�zŠz‰|Œ|ÑÔ Ò$Ð$Ý ÐcÐcµc¸&¿*º*¹,¼,Ñ6GÔ6GÐcÐcÐX\ÐcÐcÐcÑdÔdÐdð %å
ˆ9�~„~�˜Y™œÒ'Ð'ÝÐcÅÀIÁÄÐcÐcÕRUÐV_ÑR`ÔR`ÐcÐcÐcÑdÔdÐdð ˜ÐÐõ 	�'˜)Ô$Ð&7Ñ8Ô8Ð8åŒX•c˜)‘n”n¥b¤hÑ/Ô/ð ð �WÐÐõ 	�˜ ¸ÐDÑDÔDÐDåŒX•c˜)‘n”n¥b¤jÑ1Ô1ð ð
 $ VÐ,¨v°xÐ.@ÐAð cð c‰ˆˆfÝˆv‰;Œ;�#˜i™.œ.Ò(Ð(ÝÐa¨ÐaÐaµ°F±´ÐaÐaÍ#ÈiÉ.Ì.ÐaÐaÐaÑbÔbÐbð )ð 6:€EØ�'ÐÐÝ”:ÝŒJ•y ¨Ô!1°?ÑCÔCÅRÄXÑNÔNÐPWñ
ô 
ˆõ ˆx‰=Œ=˜HÒ$Ð$ÝÐ\­s°8©}¬}Ð\Ð\È8Ð\Ð\Ð\Ñ]Ô]Ð]Ø7Ð7¨hÐ7Ñ7Ô7ˆÝ#)ØØØØØÝ˜7 I­s°9©~¬~Ñ>Ô>ØØØØÝ˜: |µS¸±^´^ÑDÔDØØØØð$ñ $ô $Ñ €GÐ˜qð" Ð$Ð$Ð$rA   Úcolumnsú DetectionColumns | TargetColumnsc                ó¬   — t          t          | d|¦  «        |› d�¦  «        }t          j        t          j        |t          j        ¬¦  «        d¦  «        S )z?The per-image row counts, which is what assigns rows to images.r|   z.countsr=   rb   )r6   r]   r.   rM   r/   rf   )r!  r%   Úraws      r5   r  r  +  sI   € å
•I˜g x°Ñ7Ô7¸EÐ9JÐ9JÐ9JÑ
KÔ
K€CÝŒ:•b”j ­B¬HÐ5Ñ5Ô5°uÑ=Ô=Ð=rA   c          	     óH  — d| vr/t          j        t          |¦  «        dft           j        ¬¦  «        S t	          | d         ||› d�|¬¦  «        }t          |¦  «        t          |¦  «        k    r2t          |› dt          |¦  «        › dt          |¦  «        › d�¦  «        ‚|S )	zDThe box column, zero-filled when absent (see :func:`_record_boxes`).rQ   rG   r=   rY   r"   r}   rë   rì   )r.   r[   r\   r?   rS   r1   )r!  r%   rV   rB   r#   rQ   s         r5   r  r  1  s¤   € ð �gÐÐÝŒx�˜V™œ aÐ(µ´
Ð;Ñ;Ô;Ð;Ý�7˜7Ô# Z°EÐ1AÐ1AÐ1AÈ{Ð[Ñ[Ô[€EÝ
ˆ5�z„z•S˜‘[”[Ò Ð Ý˜EÐPÐP¥S¨¡Z¤ZÐPÐP½CÀ¹K¼KÐPÐPÐPÑQÔQÐQØ€LrA   c                óF   — t          | ¦  «        sg S t          | ||¦  «        S )z<The flat mask column, or empty when the caller carries none.)rZ   r†   )r!  r%   rp   s      r5   r  r  B  s)   € å�gÑÔð Øˆ	Ý�˜% Ñ'Ô'Ð'rA   r£   )Ú	iou_typesr'  úSequence[str]ÚNonec                óš   — | dvrt          d| ›d�¦  «        ‚|dvrt          d|›d�¦  «        ‚|D ]}|dvrt          d|›d	�¦  «        ‚Œd
S )u[  Refuse an unrecognised option rather than falling through to a default.

    Every one of these selects a behaviour that is silently wrong if
    mis-selected, so a typo must raise instead of picking an arm â€” an
    unrecognised ``iou_type`` would otherwise reach the ``else`` arm and
    report one IoU type's metrics under another's keys.
    r   zunknown area z.; expected 'auto', 'supplied', 'box' or 'mask'r   zunknown box_format rI   r   zunknown iou_type z; expected 'bbox' or 'segm'N)r1   )rÞ   rB   r'  rc   s       r5   r  r  I  s˜   € ð Ð6Ð6Ð6ÝÐ_¨Ð_Ð_Ð_Ñ`Ô`Ð`ØÐ3Ð3Ð3ÝÐb¨zÐbÐbÐbÑcÔcÐcØð Vð VˆØÐ'Ð'Ð'ÝÐT°ÐTÐTÐTÑUÔUÐUð (ðVð VrA   úSequence[NDArray[Any]]Úempty_shapeútuple[int, ...]r>   ú	type[Any]c                ó‚   — | D ]'}t          |¦  «        rt          j        | ¦  «        c S Œ(t          j        ||¬¦  «        S )zIConcatenate per-image columns, with a correctly-shaped empty for no rows.r=   )r\   r.   rÒ   r[   )r!  r,  r>   rÛ   s       r5   r  r  Z  sQ   € ð ð +ð +ˆÝˆv‰;Œ;ð 	+Ý”> 'Ñ*Ô*Ð*Ð*Ð*ð	+åŒ8�K uÐ-Ñ-Ô-Ð-rA   rû   rü   rý   rþ   rÿ   úSequence[RLEInput]r   r  r  r  r¯   c           
     óì  — t          |¦  «        dk    pt          |
¦  «        dk    }t          |                     ¦   «         ¦  «        }d||fd|
t          |	                     ¦   «         ¦  «        ffD ]>\  }}}t          |¦  «        d|fvr%t          |› dt          |¦  «        › d|› d�¦  «        ‚Œ?|s|�t	          |||
|	|¦  «        nWt          j        t          |¦  «        t
          j        ¦  «        t          j        t          |¦  «        t
          j        ¦  «        f\  }}t          j        d|dz   t
          j        ¬	¦  «        t          j	        ||¦  «        |t          j
        | ¦  «        t          | |||¬
¦  «        |dœ}t          |¦  «        rt          |¦  «        |d<   t          |||g¦  «        }t          j                             |||dœ||¦  «        }t#          |||||	|
|¬¦  «        }|||fS )a  Assemble vernier's inputs from whole columns.

    The single builder both public spellings land on, so a per-sample
    call and a columnar one cannot drift: everything above this point is
    a way of producing these arrays, and everything the evaluator sees
    is decided here.
    r   r‰   rä   r}   r~   uN    rows; a mask column is all-or-nothing â€” every row carries one, or none doesNrF   r=   )rÞ   )rÂ   rŽ   Úcategory_idr   rÞ   rí   Úsegmentation)rÂ   ÚheightÚwidth)Úmasked)r\   rq   r  r1   Ú_flat_image_sizesr.   r[   rf   r  ÚrepeatrN   Ú_gt_arear   r×   r   ÚCocoDatasetÚfrom_arraysÚ_detections)rû   rü   rý   rþ   rÿ   rš   r   r  r  r  rœ   r  r¯   rÄ   rÞ   r6  Útotalr´   rk   r  r¶   r·   r   r˜   rã   rä   s                             r5   r  r  d  s0  € õ6 �‰\Œ\˜AÒÐ1¥ W¡¤°Ò!1€FÝ�	—’‘”Ñ Ô €Eð 
�G˜UÐ#Ø	�w¥ I§M¢M¡O¤OÑ 4Ô 4Ð5ðð ð Ñˆˆd�Dõ ˆt‰9Œ9˜Q ˜IÐ%Ð%ÝØð Ið I�3˜t™9œ9ð Ið I°ð Ið Ið Iñô ð ð &ð ð	VØÐ&õ 	˜' 9¨g°yÀ%ÑHÔHÐHåŒh•s˜9‘~”~¥r¤xÑ0Ô0µ"´(½3¸y¹>¼>Í2Ì8Ñ2TÔ2TÐUñ €GˆVõ Œi˜˜5 1™9­B¬HÐ5Ñ5Ô5Ý”I˜i¨Ñ3Ô3Ø ÝÔ$ XÑ.Ô.Ý˜ 7¨G¸$Ð?Ñ?Ô?Øð#ð #€Kõ ˆ7�|„|ð 4Ý&*¨7¡m¤mˆ�NÑ#Ý˜:¨	°9Ð'=Ñ>Ô>€HÝÔ×+Ò+Ø G°fÐ=Ð=ØØñô €Gõ
 Ø�8˜Y¨	°9¸gÈfðñ ô €Jð �J Ð(Ð(rA   r|   c                ó¢   — t          j        t          | ¦  «        dz   t           j        ¬¦  «        }t          j        | |dd…         ¬¦  «         |S )zCRow bounds per image: ``offsets[i]:offsets[i + 1]`` is image ``i``.rF   r=   N)Úout)r.   r[   r\   rf   Úcumsum)r|   Úboundss     r5   Ú_offsetsrB  «  sD   € å "¤­¨V©¬°q©ÅÄÐ IÑ IÔ I€FÝ„Iˆf˜&   œ*Ð%Ñ%Ô%Ð%Ø€MrA   c                ó\   — t          t          | |¦  «        t          ||¦  «        |¦  «        S )zI:func:`gt_image_sizes`, reading flat mask lists through per-image bounds.)r¨   Ú_firsts)rš   rÿ   rœ   r  r   s        r5   r7  r7  ²  s+   € õ �g g¨yÑ9Ô9½7À7ÈIÑ;VÔ;VÐX`ÑaÔaÐarA   rk   úlist[RLEInput | None]c                ó²   ‡ — t          ‰ ¦  «        sdgt          |¦  «        z  S t          |¦  «        }ˆ fd„t          |dd…         |d¬¦  «        D ¦   «         S )u  Each image's first mask, the only one a size is ever read from.

    An empty flat list means the side carries no masks at all â€” a bbox
    ground truth beside masked detections, say â€” so every image reports
    ``None`` rather than indexing past the end.
    Nc                ó.   •— g | ]\  }}|r‰|         nd ‘ŒS rv   r£   )ry   Ústartrp   rk   s      €r5   r¦   z_firsts.<locals>.<listcomp>Ç  s*   ø€ ÐaÐaÐa©|¨u°e˜5Ð*ˆD�ŒKˆK dÐaÐaÐarA   rH   TrŒ   )r\   rB  r�   )rk   r|   Úats   `  r5   rD  rD  ½  se   ø€ õ ˆt‰9Œ9ð $Øˆv�˜F™œÑ#Ð#Ý	�&Ñ	Ô	€BØaÐaÐaÐa½sÀ2ÀcÀrÀcÄ7ÈFÐ[_Ð?`Ñ?`Ô?`ÐaÑaÔaÐarA   rQ   c               ód  — |dk    r|S t          |¦  «        dk    }|dk    r|st          d¦  «        ‚|dk    r't          t          j        |dk    ¦  «        ¦  «        r|S |o|dk    }|rt          |¦  «        n| dd…df         | dd…d	f         z  }|d
v r|S t          j        |dk    ||¦  «        S )uÅ  Fill the ground truth's ``area`` column.

    ADR-0060 makes this required and read verbatim, because it is what
    the small / medium / large bucketing reads â€” vernier will not derive
    it, since "silently substituting ``w * h`` would re-bucket every
    polygon GT". So the choice is made here, explicitly.

    ``"auto"`` mirrors COCO: a positive supplied area wins, and anything
    else falls back **per element** to the *mask's* area when the record
    carries a mask, and to the box's only when it does not. The
    per-element part matters â€” a framework that records areas for some
    annotations and zeros for the rest is the common case, not a corner
    one.

    The mask takes precedence **regardless of ``iou_type``**, because a
    COCO ground truth has one ``area`` per annotation and it is the
    segmentation's: ``COCOeval`` under ``iouType="bbox"`` buckets by
    that same field rather than recomputing ``w * h``. Deriving the box
    area for a bbox pass would silently disagree with every
    pycocotools-shaped evaluator for any object whose two areas straddle
    ``32**2`` or ``96**2`` â€” visible only as AP moving between the
    small and medium buckets, with no error anywhere.
    r   r   r   z3area='mask' needs masks on the ground-truth recordsr   r   NrE   rt   )r   r   )r\   r1   r'   r.   ÚallÚ_mask_areasÚwhere)rQ   r   rš   rÞ   Ú	has_masksÚ	from_maskÚcomputeds          r5   r9  r9  Ê  sÔ   € ð< ˆzÒÐØˆÝ�G‘”˜qÒ €IØˆv‚~€~˜i€~ÝÐNÑOÔOÐOð ˆv‚~€~�$�rœv h°¢lÑ3Ô3Ñ4Ô4€~ØˆØÐ+˜d ešm€IØ'0ÐO�{˜7Ñ#Ô#Ð#°e¸A¸A¸A¸q¸D´kÀEÈ!È!È!ÈQÈ$ÄKÑ6O€HØˆÐÐØˆÝŒ8�H˜q’L (¨HÑ5Ô5Ð5rA   c                ó  — t          j        t          | ¦  «        t           j        ¬¦  «        }g }g }t	          | ¦  «        D ]¢\  }}t          |t          ¦  «        r+|                     |¦  «         |                     |¦  «         ŒEt          |d|› d�¦  «        }|j	        dk    rt          d|› d|j        › �¦  «        ‚t          t          j        |¦  «        ¦  «        ||<   Œ£|r£	 t          j        |¦  «        }n@# t           t          f$ r,} t#          |¦  «        t%          ||¦  «        ¦  «        |‚d}~ww xY wt          j        |t           j        ¬¦  «        }	t          |¦  «        t          | ¦  «        k    r|	|dd…<   n|	||<   |S )u„  Foreground pixel count per ground-truth mask.

    A bitmask is summed in NumPy and a pre-encoded RLE goes to the FFI.
    Both give the same number â€” bit-identical, since a foreground count
    is exact in f64 â€” but the round trip through the RLE codec costs
    ~19x more than the sum, and it re-rasterizes masks that
    ``CocoDataset.from_arrays`` rasterizes again a moment later.

    The FFI hands back a buffer rather than a list of floats, so the
    all-encoded case â€” every mask pre-encoded, which is what a
    TorchMetrics-shaped state holds â€” is a single memcpy with no
    per-mask Python object anywhere on the path.
    r=   úmasks[rê   rE   z%]: expected a 2-D bitmask, got shape N)r.   rÓ   r\   r?   r�   rw   r¼   r‚   r6   rK   r1   rL   ÚfloatÚcount_nonzeror   Úrle_arear0   ÚtypeÚ
_attributeÚ
frombuffer)
rš   ÚareasÚencodedÚ
encoded_atrÕ   rz   ÚbitmaskÚdecodedr4   Úvaluess
             r5   rL  rL  ù  s©  € õ "$¤­#¨g©,¬,½b¼jÐ!IÑ!IÔ!I€EØ €GØ€JÝ# GÑ,Ô,ð 
?ð 
?‰ˆ�$Ý�d�DÑ!Ô!ð 		?Ø�NŠN˜4Ñ Ô Ð Ø×Ò˜hÑ'Ô'Ð'Ð'å Ð&:¨xÐ&:Ð&:Ð&:Ñ;Ô;ˆGØŒ|˜qÒ Ð Ý Ø[˜XÐ[Ð[ÈGÌMÐ[Ð[ñô ð õ $¥BÔ$4°WÑ$=Ô$=Ñ>Ô>ˆE�(‰OˆOØð 'ð	BÝ”n WÑ-Ô-ˆGˆGøÝ�:Ð&ð 	Bð 	Bð 	Bð •$�s‘)”)�J s¨JÑ7Ô7Ñ8Ô8¸cÐAøøøøð	Bøøøõ ”˜w­b¬jÐ9Ñ9Ô9ˆõ ˆw‰<Œ<�3˜w™<œ<Ò'Ð'ØˆE�!�!�!‰HˆHà &ˆE�*ÑØ€Ls   Ã'C< Ã<D9Ä'D4Ä4D9r[  úSequence[int]c                óâ   — t          | ¦  «        }t          j        d|¦  «        }|€|S d|t          |                     d¦  «        ¦  «                 › d||                     ¦   «         d…         › �S )zBRewrite an ``rles[j]`` message to the caller's own mask numbering.zrles\[(\d+)\]NrR  rF   rê   )r&   ÚreÚmatchrq   ÚgroupÚend)r4   r[  Úmessagerb  s       r5   rW  rW  &  si   € å�#‰hŒh€Gõ ŒHÐ% wÑ/Ô/€EØ€}ØˆØN�J�s 5§;¢;¨q¡>¤>Ñ2Ô2Ô3ÐNÐN°g¸e¿iºi¹k¼k¸m¸mÔ6LÐNÐNÐNrA   rî   r6  r   c               ód  ‡‡‡‡— |sjt          ‰¦  «        s t          j        dt          j        ¬¦  «        S t          j        t          j        | |¦  «        ‰‰‰g¦  «        }t          d|¦  «        S t          |¦  «        }ˆˆˆˆfd„t          | |dd…         |dd…         d¬	¦  «        D ¦   «         S )
av  Pick the fastest detection route that can express these detections.

    ``bbox`` takes the ``(N, 7)`` matrix -- the only route that hands the
    whole state over with no Python object per detection. What it cannot
    carry is exactly what a bbox pass does not use: a segmentation, an
    explicit id, a supplied area.

    ``segm`` takes the columnar route, the only one that carries a mask
    *and* keeps the arrays whole; its per-image entries are **views**
    into the columns, not copies. The third route, a list of COCO result
    dicts, costs more per-detection Python than the rest of the ingest
    put together.
    )r   é   r=   r;   c                ó¾   •— g | ]Y\  }}}t          t          |¦  «        t          j        ‰||…         ¦  «        ‰||…         ‰||…         ‰||…         ¬ ¦  «        ‘ŒZS ))rŽ   rQ   rî   rV   rk   )r   rq   r.   rN   )ry   rŽ   rH  ÚstoprQ   rV   rk   rî   s       €€€€r5   r¦   z_detections.<locals>.<listcomp>R  s„   ø€ ð 	ð 	ð 	ñ "ˆH�e˜Tõ 	Ý˜‘]”]ÝÔ& u¨U°4¨ZÔ'8Ñ9Ô9Ø˜% ˜*Ô%Ø˜% ˜*Ô%Ø�e˜D�jÔ!ð	
ñ 	
ô 	
ð	ð 	ð 	rA   NrH   rF   TrŒ   )	r\   r.   r[   r?   Úcolumn_stackr8  r	   rB  r�   )	r  rQ   rî   rV   r|   rk   r6  ÚmatrixrI  s	    ``` `   r5   r<  r<  2  sÖ   øøøø€ ð. ð 3Ý�6‰{Œ{ð 	6Ý”8˜F­"¬*Ð5Ñ5Ô5Ð5õ ”¥"¤)¨I°vÑ">Ô">ÀÀvÈvÐ!VÑWÔWˆÝÐ)¨6Ñ2Ô2Ð2Ý	�&Ñ	Ô	€Bð	ð 	ð 	ð 	ð 	ð 	ð 	õ &)¨°B°s¸°s´G¸RÀÀÀ¼VÈDÐ%QÑ%QÔ%Qð	ñ 	ô 	ð 	rA   )ÚmapÚmap_50Úmap_75Ú	map_smallÚ
map_mediumÚ	map_largezmar_{0}zmar_{1}zmar_{2}Ú	mar_smallÚ
mar_mediumÚ	mar_largeztuple[str, ...]Ú
_STAT_KEYSr   F)rF   é
   éd   Ú	corrected)Úiou_typerB   rÄ   rÞ   Úclass_metricsÚmax_detsÚiou_thresholdsÚrecall_thresholdsÚparity_modeÚnum_threadsr#   ry  ú'SampleIouType | Sequence[SampleIouType]rz  r{  r|  úSequence[float] | Noner}  r~  r   r  ú
int | Noneúdict[str, float | NDArray[Any]]c               óÆ  — t          |t          ¦  «        r|fnt          |¦  «        }t          |||¬¦  «         d„ |D ¦   «         }t	          |¦  «        dk    s-|d         dk     s!|d         |d         cxk     r|d         k     s"n t          dt          |¦  «        › d�¦  «        ‚d	|v rt          | |¦  «         t          | |||||¬
¦  «        \  }}}d|v r$t          |t          ¦  «        st          d¦  «        ‚i }|D �]&}t	          |¦  «        dk    rdn|› d�}|
|d         d|€dnt          |¦  «        |	€dnt          |	¦  «        |dœ}|d	k    rt          j
        ||fdd	i|¤Žnt          j        ||fddi|¤Ž}|                     |¦  «        }|                     |¦  «        j        }t          t           |d¬¦  «        D ]"\  }}t#          |¦  «        || |j        |Ž z   <   Œ#|r=t'          |j        ¦  «        ||› d�<   t'          |j        ¦  «        ||› d|d         › d�<   �Œ(t-          j        d„ t1          |¦  «        D ¦   «         t,          j        ¬¦  «        |d<   |S )uù
  Evaluate per-image records and return the COCO metrics (ADR-0063).

    The convenience wrapper over :func:`coco_inputs` for the AP case.
    Anything else â€” a custom grid, calibration, the partitioned path, or
    any of the diagnostics (TIDE, LRP, the confusion matrix, the FP-IoU
    histogram, result tables) â€” takes :func:`coco_inputs`' pair
    directly; every one of them reads it (ADR-0064).

    Values are Python floats and numpy arrays. Converting them to a
    framework tensor is the caller's one line (``torch.as_tensor(...)``,
    zero-copy off numpy); vernier returns no framework type and imports
    no framework.

    ``parity_mode`` defaults to ``"corrected"``, matching
    :class:`vernier.instance.Evaluator`. Under ``"strict"``, ``map``
    reports pycocotools' ``-1`` whenever 100 is not among ``max_dets``,
    which is a genuine pycocotools behaviour and rarely what a training
    run wants to log.

    Args:
        predictions: One record per image. See :class:`Prediction`.
        targets: One record per image. See :class:`Target`.
        iou_type: One IoU type, or several. With more than one, each
            metric key is prefixed (``bbox_map``, ``segm_map``). This is
            the one place the IoU type is named, because it is the one
            that calls a kernel; :func:`coco_inputs` builds inputs that
            serve whichever grid the masks allow.
        box_format: Layout ``boxes`` is read as.
        categories: See :func:`coco_inputs`.
        area: See :func:`coco_inputs`.
        class_metrics: Also return per-class AP and AR vectors, aligned
            with the resolved category ids. Off by default: each vector
            materializes a fresh array across the FFI.
        max_dets: The COCO detection-count ladder â€” three increasing
            positive caps, since the summary reports ``mar`` at each and
            caps every image at the last.
        iou_thresholds: IoU grid, defaulting to COCO's ``.50:.05:.95``.
        recall_thresholds: Recall grid, defaulting to COCO's 101 points.
        parity_mode: ``"strict"`` or ``"corrected"`` (ADR-0002).
        num_threads: Thread budget. ``None`` evaluates sequentially
            (ADR-0047), which is the DDP-safe default â€” a rank sharing a
            node should not claim every core.
        cast_inputs: See :func:`coco_inputs`.

    Returns:
        The twelve COCO statistics under the conventional metric names,
        plus ``classes`` and, under ``class_metrics``, the per-class
        vectors.

    Raises:
        ValueError: If ``iou_type`` or ``max_dets`` is not one of the
            accepted values, or for any reason :func:`coco_inputs`
            raises.
        KeyError: If ``iou_type`` includes ``"bbox"`` and a record omits
            its boxes.
    )rÞ   rB   r'  c                ó,   — g | ]}t          |¦  «        ‘ŒS r£   r  rÌ   s     r5   r¦   z coco_metrics.<locals>.<listcomp>À  s   € Ð/Ð/Ð/˜U�c�%‰jŒjÐ/Ð/Ð/rA   rt   r   rF   rE   z5max_dets must be three increasing positive caps, got z¼. Every image is capped at the last, so a descending ladder truncates the run to the smallest cap while the keys still read `mar_100`; a repeated one collapses two `mar_{n}` keys into one.r   rÝ   r    z<iou_type='segm' needs masks on the records; none were passedÚ rÎ   rH   TN)r~  Úmax_dets_per_imageÚuse_catsr|  r}  r  Údt_arear   rŒ   Úmap_per_classÚmar_Ú
_per_classc                ó   — g | ]\  }}|‘ŒS r£   r£   )ry   r2  rÎ   s      r5   r¦   z coco_metrics.<locals>.<listcomp>ô  s   € Ð?Ð?Ð?™˜ aˆÐ?Ð?Ð?rA   r=   Úclasses)rw   r&   rx   r  r\   r1   Ú_require_boxesrâ   r   r   Úevaluate_bbox_gridÚevaluate_segm_gridÚ
accumulateÚ	summarizeÚstatsr�   ru  rS  ÚformatrŒ  Ú	precisionÚrecallr.   r/   rÃ   rf   )r‡   r‰   ry  rB   rÄ   rÞ   rz  r{  r|  r}  r~  r  r#   r'  Úladderrã   rä   r˜   Úresultsrc   ÚprefixÚsharedÚgridÚaccumulatedr”  ro   r$   s                              r5   Úcoco_metricsrž  t  s  € õR " (­CÑ0Ô0ÐEˆˆˆµe¸H±o´oð õ ˜D¨ZÀ9ÐMÑMÔMÐMØ/Ð/ hÐ/Ñ/Ô/€FÝ
ˆ6�{„{�aÒÐ˜6 !œ9 qš=˜=°°q´	¸FÀ1¼IÐ0QÐ0QÒ0QÐ0QÈÈqÌ	Ò0QÐ0QÐ0QÐ0QÝð9ÅEÈ(ÁOÄOð 9ð 9ð 9ñ
ô 
ð 	
ð �ÐÐÝ�{ GÑ,Ô,Ð,õ
 %7ØØØØØØð%ñ %ô %Ñ!€GˆZ˜ð �ÐÐ¥:¨j½$Ñ#?Ô#?ÐÝÐWÑXÔXÐXØ/1€GØð \ñ \ˆÝ˜9‘~”~¨Ò*Ð*��°4°
°
°
ˆà&Ø"(¨¤*ØØ&4Ð&<˜d˜dÅ$À~ÑBVÔBVØ):Ð)B  ÍÐM^ÑH_ÔH_Ø&ð"
ð "
ˆð �vŠ~ˆ~õ Ô$ W¨jÐSÐSÀ&ÐSÈFÐSÐSÐSåÔ)¨'°:ÐXÐXÀvÐXÐQWÐXÐXð 	ð
 —o’o fÑ-Ô-ˆØ×%Ò% fÑ-Ô-Ô3ˆÝ�j¨%¸Ð=Ñ=Ô=ð 	Að 	A‰JˆC�Ý49¸%±L´LˆG�F˜Z˜SœZ¨Ð0Ñ0Ñ1Ð1Øð 	\Ý0:¸;Ô;PÑ0QÔ0QˆG�vÐ,Ð,Ð,Ñ-Ý=GÈÔHZÑ=[Ô=[ˆG�vÐ9Ð9 6¨"¤:Ð9Ð9Ð9Ñ:ùåœØ?Ð?­9°XÑ+>Ô+>Ð?Ñ?Ô?ÅrÄxðñ ô €GˆIÑð €NrA   c                ó~   — d|fd| ffD ]3\  }}t          |¦  «        D ]\  }}d|vrt          |› d|› d�¦  «        ‚ŒŒ4dS )a>  Refuse a bbox evaluation over records that omit their boxes.

    :func:`_record_boxes` zero-fills the column for a mask-only
    pipeline, which a segm grid cannot observe and a bbox grid reports
    as ``0``. The check belongs here because this is the first point
    that knows which grid will read the inputs.
    r‰   r‡   rQ   ú[zl].boxes is required for iou_type='bbox'; a record carrying only masks gets a zero box column, which scores 0N)r�   r€   )r‡   r‰   r´   Úrecordsr“   rT   s         r5   r�  r�  ù  s•   € ð % gÐ.°ÀÐ0LÐMð ð ‰ˆˆgÝ" 7Ñ+Ô+ð 	ð 	‰IˆAˆvØ˜fÐ$Ð$ÝØð Qð Q˜að Qð Qð Qñô ð ð %ð	ðð rA   Útensorc                ój  — | d         }t          j        t          j        |dd¦  «        |j        d         df¦  «        }|dk    }|                     d¬¦  «        }t          j        ||d¦  «                             d¬¦  «        }t          j        |dk    |t          j        |d¦  «        z  d¦  «        S )uc  Reduce a precision or recall tensor to one value per category.

    Mirrors what vernier reports in its own per-class table
    (``crates/vernier-core/src/tables.rs``): the mean over the IoU axis
    â€” and, for precision, the recall axis â€” at the **all-areas** bucket
    and the **largest** maxDets cap. Averaging over the area and maxDets
    axes instead would fold AP_small/medium/large, and AR@1/AR@10, into
    a number matching neither ``map`` nor the ``ap`` column of
    ``EvalResult.per_class`` for the same run.

    Precision is ``(T, R, K, A, M)`` and recall is ``(T, K, A, M)``, so
    after selecting ``A`` and ``M`` the category axis is last in both.
    ``-1`` is the empty-cell sentinel (quirk **C5**); the mean covers the
    defined entries only, so a category present in no image reports
    ``-1`` rather than dragging the average down.
    ).r   rH   rH   r   rF   )Úaxisg        g      ð¿)r.   rM   ÚmoveaxisrL   r  rM  Úmaximum)r¢  Úselectedr^  Údefinedr|   Útotalss         r5   rŒ  rŒ  
  s¢   € ð& �jÔ!€HÝŒZ�œ H¨b°!Ñ4Ô4°x´~ÀbÔ7IÈ2Ð6NÑOÔO€FØ�rŠk€GØ�[Š[˜aˆ[Ñ Ô €FÝŒX�g˜v sÑ+Ô+×/Ò/°QÐ/Ñ7Ô7€FÝŒ8�F˜Q’J ­¬°F¸AÑ)>Ô)>Ñ >ÀÑEÔEÐErA   )r$   r   r%   r&   r#   r'   r(   r)   )
r$   r   r%   r&   r4   r7   r#   r'   r(   r)   )r3   r)   r%   r&   r#   r'   r(   r;   )
r$   r   rB   rC   r%   r&   r#   r'   r(   r;   )rT   rU   r%   r&   rV   rW   rB   rC   r#   r'   r(   r;   )r$   r   r%   r&   r(   rW   )rT   r!   r(   r'   )rT   r!   r%   r&   rp   rq   r(   rr   )r‡   rˆ   r‰   rŠ   r(   rW   )NN)rš   r›   rœ   r�   r   rž   r(   rŸ   )rª   r«   r¬   r­   r   rž   r(   rŸ   )r¸   r   r(   rº   )r½   r¾   r(   r¿   )rÄ   rÅ   rÆ   rÇ   r(   rÈ   )rT   r!   ro   r&   r%   r&   r(   r   )
rT   r!   ro   r&   r%   r&   r#   r'   r(   r)   )r‡   rˆ   r‰   rŠ   rB   rC   rÄ   rÅ   rÞ   rß   r#   r'   r(   rà   )r‡   rˆ   r‰   rŠ   rB   rC   rÄ   rÅ   rÞ   rß   r#   r'   r(   ræ   )r‰   rŠ   r(   r  )rä   r   r‰   r   rB   rC   rÄ   rÅ   rÞ   rß   r  r  r#   r'   r(   rà   )r!  r"  r%   r&   r(   rW   )r!  r"  r%   r&   rV   rW   rB   rC   r#   r'   r(   r;   )r!  r"  r%   r&   rp   rq   r(   rr   )rÞ   r&   rB   r&   r'  r(  r(   r)  )r!  r+  r,  r-  r>   r.  r(   r)   ) rû   r;   rü   rW   rý   rW   rþ   r;   rÿ   rW   rš   r0  r   r;   r  r;   r  rW   r  rW   rœ   r0  r  rW   r¯   rž   rÄ   rÅ   rÞ   rß   r(   ræ   )r|   rW   r(   rW   )rš   r0  rÿ   rW   rœ   r0  r  rW   r   rž   r(   rŸ   )rk   r0  r|   rW   r(   rE  )
rQ   r;   r   r;   rš   r0  rÞ   rß   r(   r;   )rš   r0  r(   r;   )r4   r7   r[  r_  r(   r&   )r  rW   rQ   r;   rî   r;   rV   rW   r|   rW   rk   r0  r6  r'   r(   r   )r‡   rˆ   r‰   rŠ   ry  r€  rB   rC   rÄ   rÅ   rÞ   rß   rz  r'   r{  r_  r|  r�  r}  r�  r~  r   r  r‚  r#   r'   r(   rƒ  )r‡   rˆ   r‰   rŠ   r(   r)  )r¢  r;   r(   r;   )GÚ__doc__Ú
__future__r   ra  Úcollections.abcr   r   Útypingr   r   r   r	   Únumpyr.   Únumpy.typingr
   Úvernierr   Úvernier._array_typesr   r   r   r   r   r   r   r   Úvernier._typesr   rC   rß   ÚSampleIouTyper!   Ú__annotations__r6   r2   r@   rS   r^   rh   rZ   r†   r™   r©   r¨   r³   rÃ   r×   r]   rÜ   rå   râ   r  r   r  r  r  r  r  r  rB  r7  rD  r9  rL  rW  r<  ru  rž  r�  rŒ  r£   rA   r5   ú<module>rµ     s"  ðð%ð %ð %ðN #Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0à Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  à Ð Ð Ð Ð Ð ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð &Ð %Ð %Ð %Ð %Ð %ð Ð,Ô-€	ð Ð6Ô7€
ð ˜Ô'€ð Q€
Ð PÐ PÐ PÑ Pð >Bð ð ð ð ð ð ð*Jð Jð Jð Jð:/ð /ð /ð /ð&+ð +ð +ð +ð\!ð !ð !ð !ðH'ð 'ð 'ð 'ð&ð ð ð ð 4ð 4ð 4ð 4ðn+ð +ð +ð +ð4 ;?Ø8<ð&ð &ð &ð &ð &ðR ð  ð  ð  ðF
4ð 
4ð 
4ð 
4ðCð Cð Cð Cð
Xð Xð Xð Xð<ð ð ð ð %ð %ð %ð %ð #Ø>BØØðQð Qð Qð Qð Qð Qðh_ð _ð _ð _ðDLð Lð Lð Lð #Ø>BØØ ØðE%ð E%ð E%ð E%ð E%ð E%ðP>ð >ð >ð >ðð ð ð ð"(ð (ð (ð (ð RTð Vð Vð Vð Vð Vð Vð".ð .ð .ð .ðD)ð D)ð D)ð D)ðNð ð ð ðbð bð bð bð
bð 
bð 
bð 
bð,6ð ,6ð ,6ð ,6ð^*ð *ð *ð *ðZ	Oð 	Oð 	Oð 	Oð)ð )ð )ð )ðd€
ð ð ð ñ ð( 9?Ø"Ø>BØØØ*Ø-1Ø04Ø)Ø"ØðBð Bð Bð Bð Bð BðJð ð ð ð"Fð Fð Fð Fð Fð FrA   