Enumerate every tx_type CDF width against its own inverse set
Browse files at this commitd8a578a1f13e84a1d7a78594925689f712eab0afParent: 5f52cbd- test
- enumerate every tx_type CDF width against its own inverse set
2 changed files +90 -14
crates/ec-av1/src/decode.rsmodified+25 -14
| @@ -4133,6 +4133,27 @@ fn dc_sign_ctx(vote: i32) -> usize { | ||
| 4133 | 4133 | } |
| 4134 | 4134 | } |
| 4135 | 4135 | |
| 4136 | +/// The `tx_type` a CDF symbol names, given the width of the row it was read | |
| 4137 | +/// from. | |
| 4138 | +/// | |
| 4139 | +/// The row's own width names its set (spec `Tx_Type_Intra_Inv_Set*` / | |
| 4140 | +/// `Tx_Type_Inter_Inv_Set*`): 17 slots (16 symbols) is `EXT_TX_SET_ALL16`, 13 | |
| 4141 | +/// (12) `EXT_TX_SET_DTT9_IDTX_1DDCT`, 8 (7) `TX_SET_INTRA_1`, and everything | |
| 4142 | +/// narrower the reduced `TX_SET_INTRA_2`/`TX_SET_INTER_3` order, whose two | |
| 4143 | +/// members are a prefix of the five. | |
| 4144 | +/// | |
| 4145 | +/// One function rather than a `match` at each reader, so | |
| 4146 | +/// [`crate::refusal_inventory`]'s enumeration of every (width, symbol) pair | |
| 4147 | +/// tests the mapping the readers actually use. | |
| 4148 | +pub(crate) fn tx_type_from_symbol(cdf_len: usize, t: usize) -> Option<TxType> { | |
| 4149 | + match cdf_len { | |
| 4150 | + 17 => TxType::from_symbol_all16(t), | |
| 4151 | + 13 => TxType::from_symbol_set2_12(t), | |
| 4152 | + 8 => TxType::from_symbol_set1(t), | |
| 4153 | + _ => TxType::from_symbol(t), | |
| 4154 | + } | |
| 4155 | +} | |
| 4156 | + | |
| 4136 | 4157 | /// The remainder of a level the base and base-range syntax could not reach |
| 4137 | 4158 | /// (spec 5.11.40): its bit length in unary, then that many of its own bits, |
| 4138 | 4159 | /// most significant first — the exact inverse of [`crate::tile::write_golomb`]. |
| @@ -4327,13 +4348,8 @@ fn read_coeffs( | ||
| 4327 | 4348 | if trace { |
| 4328 | 4349 | eprintln!("TRACE tx_type value={t} len={len}"); |
| 4329 | 4350 | } |
| 4330 | - tx_type = match len { | |
| 4331 | - 17 => TxType::from_symbol_all16(t), | |
| 4332 | - 13 => TxType::from_symbol_set2_12(t), | |
| 4333 | - 8 => TxType::from_symbol_set1(t), | |
| 4334 | - _ => TxType::from_symbol(t), | |
| 4335 | - } | |
| 4336 | - .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | |
| 4351 | + tx_type = tx_type_from_symbol(len, t) | |
| 4352 | + .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | |
| 4337 | 4353 | } |
| 4338 | 4354 | |
| 4339 | 4355 | let class = TxClass::of(tx_type); |
| @@ -4512,13 +4528,8 @@ fn read_coeffs_rect( | ||
| 4512 | 4528 | if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { |
| 4513 | 4529 | let len = tx_type_cdf.len(); |
| 4514 | 4530 | let t = dec.symbol(tx_type_cdf); |
| 4515 | - tx_type = match len { | |
| 4516 | - 17 => TxType::from_symbol_all16(t), | |
| 4517 | - 13 => TxType::from_symbol_set2_12(t), | |
| 4518 | - 8 => TxType::from_symbol_set1(t), | |
| 4519 | - _ => TxType::from_symbol(t), | |
| 4520 | - } | |
| 4521 | - .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | |
| 4531 | + tx_type = tx_type_from_symbol(len, t) | |
| 4532 | + .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | |
| 4522 | 4533 | if rect_trace { |
| 4523 | 4534 | eprintln!("EC_COEFF_STEP tag=tx_type plane=0 rng={}", dec.debug_state().0); |
| 4524 | 4535 | } |
crates/ec-av1/src/refusal_inventory.rsmodified+65 -0
| @@ -247,6 +247,12 @@ const PROVEN: &[(&str, &str)] = &[ | ||
| 247 | 247 | "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", |
| 248 | 248 | "every_partition_value_of_an_if_chain_alphabet_is_named_by_a_branch", |
| 249 | 249 | ), |
| 250 | + // lane-t900 r24, enumeration: every (CDF width, symbol) pair a tx_type row | |
| 251 | + // can present maps to a distinct member of that width's own set. | |
| 252 | + ( | |
| 253 | + "a tx_type symbol outside its CDF's own set: {t}", | |
| 254 | + "every_tx_type_symbol_of_every_cdf_width_maps_into_its_own_set", | |
| 255 | + ), | |
| 250 | 256 | ( |
| 251 | 257 | "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)", |
| 252 | 258 | "a_twelve_bit_sequence_header_is_refused_by_name", |
| @@ -668,6 +674,65 @@ mod tests { | ||
| 668 | 674 | assert_eq!(found, chains.len()); |
| 669 | 675 | } |
| 670 | 676 | |
| 677 | + /// Every `tx_type` symbol of every CDF width, mapped through the set that | |
| 678 | + /// width names. | |
| 679 | + /// | |
| 680 | + /// The reader decodes `t` from a row of `n` slots, so `t` is in | |
| 681 | + /// `0..n - 1`, and hands `(n, t)` to [`crate::decode::tx_type_from_symbol`] | |
| 682 | + /// -- the readers' own mapping, called here rather than transcribed | |
| 683 | + /// (class `shared-oracle-blindness`: a second copy of a table can be | |
| 684 | + /// self-consistently wrong). The widths are read from `cdf_state.rs`'s | |
| 685 | + /// `tx_type` field declarations, so a new table with a width the mapping | |
| 686 | + /// does not name fails this test rather than reaching the refusal at | |
| 687 | + /// runtime. | |
| 688 | + /// | |
| 689 | + /// Distinctness is part of the claim: a set of `n - 1` symbols must map to | |
| 690 | + /// `n - 1` DIFFERENT transform types, or the mapping has lost a member of | |
| 691 | + /// the spec's `Tx_Type_*_Inv_Set*` even while every symbol resolves. | |
| 692 | + #[test] | |
| 693 | + fn every_tx_type_symbol_of_every_cdf_width_maps_into_its_own_set() { | |
| 694 | + let mut widths: BTreeSet<usize> = BTreeSet::new(); | |
| 695 | + for line in include_str!("cdf_state.rs").lines() { | |
| 696 | + let t = line.trim(); | |
| 697 | + if !(t.starts_with("pub ") && t.contains("tx_type") && t.contains("[u16;")) { | |
| 698 | + continue; | |
| 699 | + } | |
| 700 | + let tail = t.rsplit("[u16;").next().unwrap_or(""); | |
| 701 | + let n: usize = tail | |
| 702 | + .split(']') | |
| 703 | + .next() | |
| 704 | + .unwrap_or("") | |
| 705 | + .trim() | |
| 706 | + .parse() | |
| 707 | + .unwrap_or_else(|_| panic!("cannot read a CDF width out of {t:?}")); | |
| 708 | + widths.insert(n); | |
| 709 | + } | |
| 710 | + assert!( | |
| 711 | + widths.len() >= 4, | |
| 712 | + "the cdf_state.rs scan found only {widths:?} -- it is broken, not the decoder" | |
| 713 | + ); | |
| 714 | + for &n in &widths { | |
| 715 | + let nsyms = n - 1; | |
| 716 | + let mut set: Vec<crate::transform::TxType> = Vec::new(); | |
| 717 | + for t in 0..nsyms { | |
| 718 | + let ty = crate::decode::tx_type_from_symbol(n, t).unwrap_or_else(|| { | |
| 719 | + panic!( | |
| 720 | + "a {n}-slot tx_type CDF codes symbol {t}, which maps to no transform \ | |
| 721 | + type -- the refusal \"a tx_type symbol outside its CDF's own set\" is \ | |
| 722 | + reachable, and that is a mapping-table gap to fix" | |
| 723 | + ) | |
| 724 | + }); | |
| 725 | + assert!( | |
| 726 | + !set.contains(&ty), | |
| 727 | + "a {n}-slot tx_type CDF maps symbol {t} to {ty:?}, which another symbol of \ | |
| 728 | + the same set already names -- a member of the spec's inverse table is lost" | |
| 729 | + ); | |
| 730 | + set.push(ty); | |
| 731 | + } | |
| 732 | + assert_eq!(set.len(), nsyms); | |
| 733 | + } | |
| 734 | + } | |
| 735 | + | |
| 671 | 736 | /// Every entry of [`PROVEN`] must still name a live refusal and a test |
| 672 | 737 | /// that exists, and the count it prints is the inventory's numerator. |
| 673 | 738 | #[test] |