forge
Explore
Log in

Don't you dare go Hollow

ec-aac SBR: downsampled SBR (ext rate < 2*core, e.g. al_sbr_sr_48_2_fsaac48 ASC 11 90 56 e5 98) ran the 64-band doubling chain with band tables at the 48 kHz ext rate: ours 2048/AU and band-table errors (no sideinfo rows, ours 1001472 = cap at 489 AUs x 2048 vs ffmpeg 1148 x 1024). ffmpeg (aacsbr_template.c 1147/1683/1418): sbr->sample_rate = 2*core for tables, downsampled = ext_sample_rate < sbr->sample_rate -> 32-band synthesis with the decimated window (ds[n]=c[2n]), 32 output samples/slot. Fix: parser rate always 2*core, SbrChain::set_downsampled, Synthesis::downsampled (N=32, v 640, shift -0.5 matching our analysis phase; python replica of analysis->synth32 corr 0.995 at lag 289 vs 0.9967 for the 64-band pair), k2 clamped to 32, LFE bypass uses the same bank. Also QMF_WINDOW[384] and [512] had the wrong sign vs ffmpeg us/ds tables (ffmpeg flips at 385/513, mirror-symmetric with 128/256; ours at 384/512; table now equals ffmpeg's us and ds to 1e-10), pinned sum updated 81.46300943655164 -> 82.21187106118578. cargo check -p ec-aac --all-targets clean; tests not run

Browse files at this commit

d8db6262615fcd98c2b226b0357869639a98f115Ahmet Kaan GümüşParent: a62782e
crates/ec-aac/src/decode.rsmodified+8 -0
@@ -582,6 +582,14 @@ impl BlockDecoder {
582 self.sbr = rate.map(crate::sbr_chain::SbrChain::new);582 self.sbr = rate.map(crate::sbr_chain::SbrChain::new);
583 }583 }
584 584
585+ /// Marks the SBR output as downsampled: the extension rate is below twice
586+ /// the core rate, so the synthesis stays at 32 bands.
587+ pub fn set_sbr_downsampled(&mut self, on: bool) {
588+ if let Some(sbr) = self.sbr.as_mut() {
589+ sbr.set_downsampled(on);
590+ }
591+ }
592+
585 /// Marks Parametric Stereo as signalled by the config, for the SBR chain593 /// Marks Parametric Stereo as signalled by the config, for the SBR chain
586 /// (if one is armed): its elements then decode to two channels.594 /// (if one is armed): its elements then decode to two channels.
587 pub fn set_sbr_ps(&mut self, on: bool) {595 pub fn set_sbr_ps(&mut self, on: bool) {
crates/ec-aac/src/lib.rsmodified+4 -2
@@ -144,8 +144,10 @@ impl AacDecoder {
144 // SBR (and Parametric Stereo, for HE-AACv2) is reconstructed: the144 // SBR (and Parametric Stereo, for HE-AACv2) is reconstructed: the
145 // core is decoded first, then the extension-rate chain runs on it.145 // core is decoded first, then the extension-rate chain runs on it.
146 if cfg.sbr_present {146 if cfg.sbr_present {
147- let rate = cfg.extension_sample_rate.unwrap_or(cfg.sample_rate * 2);147+ let sbr_rate = cfg.sample_rate * 2;
148- d.block.set_sbr_rate(Some(rate));148+ let ext_rate = cfg.extension_sample_rate.unwrap_or(sbr_rate);
149+ d.block.set_sbr_rate(Some(sbr_rate));
150+ d.block.set_sbr_downsampled(ext_rate < sbr_rate);
149 d.block.set_sbr_ps(cfg.ps_present);151 d.block.set_sbr_ps(cfg.ps_present);
150 } else if !cfg.ps_present {152 } else if !cfg.ps_present {
151 // Plain AAC-LC config: an SBR payload may still follow (implicit signalling).153 // Plain AAC-LC config: an SBR payload may still follow (implicit signalling).
crates/ec-aac/src/sbr_chain.rsmodified+33 -14
@@ -237,10 +237,14 @@ struct Element {
237 }237 }
238 238
239 impl Element {239 impl Element {
240- fn ensure_channels(&mut self, need: usize) {240+ fn ensure_channels(&mut self, need: usize, downsampled: bool) {
241 while self.channels.len() < need {241 while self.channels.len() < need {
242 let seed = 0x1234_5678u32.wrapping_add(self.channels.len() as u32 * 0x9e37_79b9);242 let seed = 0x1234_5678u32.wrapping_add(self.channels.len() as u32 * 0x9e37_79b9);
243- self.channels.push(ChannelState::new(1, seed));243+ let mut channel = ChannelState::new(1, seed);
244+ if downsampled {
245+ channel.synthesis = Synthesis::downsampled();
246+ }
247+ self.channels.push(channel);
244 }248 }
245 }249 }
246 }250 }
@@ -254,6 +258,7 @@ const PS_SLOTS: usize = 32;
254 /// encoder in practice emits it).258 /// encoder in practice emits it).
255 pub struct SbrChain {259 pub struct SbrChain {
256 rate: u32,260 rate: u32,
261+ downsampled: bool,
257 /// PS is signalled by the config (explicit HE-AACv2).262 /// PS is signalled by the config (explicit HE-AACv2).
258 ps_config: bool,263 ps_config: bool,
259 // Keyed by (element_instance_tag, is_cpe): SCE/LFE and CPE instance264 // Keyed by (element_instance_tag, is_cpe): SCE/LFE and CPE instance
@@ -272,6 +277,7 @@ impl SbrChain {
272 pub fn new(rate: u32) -> SbrChain {277 pub fn new(rate: u32) -> SbrChain {
273 SbrChain {278 SbrChain {
274 rate,279 rate,
280+ downsampled: false,
275 ps_config: false,281 ps_config: false,
276 elements: HashMap::new(),282 elements: HashMap::new(),
277 bypass: HashMap::new(),283 bypass: HashMap::new(),
@@ -279,6 +285,10 @@ impl SbrChain {
279 }285 }
280 286
281 /// Marks PS as signalled by the config: the element's output is stereo.287 /// Marks PS as signalled by the config: the element's output is stereo.
288+ pub fn set_downsampled(&mut self, on: bool) {
289+ self.downsampled = on;
290+ }
291+
282 pub fn set_ps_config(&mut self, on: bool) {292 pub fn set_ps_config(&mut self, on: bool) {
283 self.ps_config = on;293 self.ps_config = on;
284 for elem in self.elements.values_mut() {294 for elem in self.elements.values_mut() {
@@ -289,13 +299,13 @@ impl SbrChain {
289 /// Parses one FIL element's `sbr_extension_data` (the reader299 /// Parses one FIL element's `sbr_extension_data` (the reader
290 /// positioned right past `bs_extension_type`) for element `tag`.300 /// positioned right past `bs_extension_type`) for element `tag`.
291 pub fn parse(&mut self, r: &mut BitReader<'_>, tag: u8, is_cpe: bool) -> Option<SbrData> {301 pub fn parse(&mut self, r: &mut BitReader<'_>, tag: u8, is_cpe: bool) -> Option<SbrData> {
292- let ps_config = self.ps_config;302+ let (ps_config, downsampled) = (self.ps_config, self.downsampled);
293 let elem = self.element(tag, is_cpe);303 let elem = self.element(tag, is_cpe);
294 let data = elem.parser.parse(r, is_cpe).ok()?;304 let data = elem.parser.parse(r, is_cpe).ok()?;
295 let n_q = elem.parser.tables().map(|t| t.n_q).unwrap_or(1);305 let n_q = elem.parser.tables().map(|t| t.n_q).unwrap_or(1);
296 let ps_out = data.ps.is_some() || (ps_config && !is_cpe);306 let ps_out = data.ps.is_some() || (ps_config && !is_cpe);
297 let need = data.channels.len().max(if ps_out { 2 } else { 1 });307 let need = data.channels.len().max(if ps_out { 2 } else { 1 });
298- elem.ensure_channels(need);308+ elem.ensure_channels(need, downsampled);
299 for ch in &mut elem.channels {309 for ch in &mut elem.channels {
300 if ch.chirp.bands() != n_q {310 if ch.chirp.bands() != n_q {
301 ch.chirp = ChirpState::new(n_q);311 ch.chirp = ChirpState::new(n_q);
@@ -321,8 +331,9 @@ impl SbrChain {
321 331
322 fn apply_low_only(&mut self, tag: u8, is_cpe: bool, planes: &mut [Vec<f32>]) {332 fn apply_low_only(&mut self, tag: u8, is_cpe: bool, planes: &mut [Vec<f32>]) {
323 let dup = !is_cpe && planes.len() == 2;333 let dup = !is_cpe && planes.len() == 2;
334+ let downsampled = self.downsampled;
324 let elem = self.element(tag, is_cpe);335 let elem = self.element(tag, is_cpe);
325- elem.ensure_channels(planes.len());336+ elem.ensure_channels(planes.len(), downsampled);
326 let mut right_synth = if dup {337 let mut right_synth = if dup {
327 Some(std::mem::take(&mut elem.channels[1].synthesis))338 Some(std::mem::take(&mut elem.channels[1].synthesis))
328 } else {339 } else {
@@ -375,13 +386,19 @@ impl SbrChain {
375 /// planes, with the high bands left empty, which is what ffmpeg's output386 /// planes, with the high bands left empty, which is what ffmpeg's output
376 /// does for the LFE channel.387 /// does for the LFE channel.
377 pub fn bypass_plane(&mut self, tag: u8, plane: &mut Vec<f32>) {388 pub fn bypass_plane(&mut self, tag: u8, plane: &mut Vec<f32>) {
378- let (state, delay) = self389+ let downsampled = self.downsampled;
379- .bypass390+ let (state, delay) = self.bypass.entry(tag).or_insert_with(|| {
380- .entry(tag)391+ let mut state = ChannelState::new(1, 0);
381- .or_insert_with(|| (ChannelState::new(1, 0), vec![0.0; BYPASS_DELAY]));392+ let mut delay = BYPASS_DELAY;
393+ if downsampled {
394+ state.synthesis = Synthesis::downsampled();
395+ delay /= 2;
396+ }
397+ (state, vec![0.0; delay])
398+ });
382 let num_slots = plane.len() / ANALYSIS_BANDS;399 let num_slots = plane.len() / ANALYSIS_BANDS;
383 let mut out = std::mem::take(delay);400 let mut out = std::mem::take(delay);
384- out.reserve(num_slots * SYNTHESIS_BANDS);401+ out.reserve(num_slots * state.synthesis.bands());
385 for slot in 0..num_slots {402 for slot in 0..num_slots {
386 let mut chunk = [0f32; ANALYSIS_BANDS];403 let mut chunk = [0f32; ANALYSIS_BANDS];
387 chunk.copy_from_slice(&plane[slot * ANALYSIS_BANDS..(slot + 1) * ANALYSIS_BANDS]);404 chunk.copy_from_slice(&plane[slot * ANALYSIS_BANDS..(slot + 1) * ANALYSIS_BANDS]);
@@ -397,7 +414,7 @@ impl SbrChain {
397 }414 }
398 // The reconstructed planes lag their raw analysis by `HF_ADJ` slots;415 // The reconstructed planes lag their raw analysis by `HF_ADJ` slots;
399 // hold the bypass output back by the same amount so they line up.416 // hold the bypass output back by the same amount so they line up.
400- let produced = num_slots * SYNTHESIS_BANDS;417+ let produced = num_slots * state.synthesis.bands();
401 *plane = out[..produced].to_vec();418 *plane = out[..produced].to_vec();
402 *delay = out[produced..].to_vec();419 *delay = out[produced..].to_vec();
403 }420 }
@@ -488,6 +505,7 @@ impl SbrChain {
488 if source == "hold" {505 if source == "hold" {
489 HOLD_CALLS.fetch_add(1, Ordering::Relaxed);506 HOLD_CALLS.fetch_add(1, Ordering::Relaxed);
490 }507 }
508+ let band_limit = if self.downsampled { ANALYSIS_BANDS } else { SYNTHESIS_BANDS };
491 let Some(elem) = self.elements.get_mut(&(tag, is_cpe)) else {509 let Some(elem) = self.elements.get_mut(&(tag, is_cpe)) else {
492 return Ok(());510 return Ok(());
493 };511 };
@@ -705,7 +723,7 @@ impl SbrChain {
705 }723 }
706 724
707 let kx = (tables.kx as usize).min(ANALYSIS_BANDS);725 let kx = (tables.kx as usize).min(ANALYSIS_BANDS);
708- let k2 = (tables.k2 as usize).min(SYNTHESIS_BANDS);726+ let k2 = (tables.k2 as usize).min(band_limit);
709 let mut vs: Vec<[Complex<f64>; SYNTHESIS_BANDS]> = Vec::with_capacity(num_slots);727 let mut vs: Vec<[Complex<f64>; SYNTHESIS_BANDS]> = Vec::with_capacity(num_slots);
710 for slot in 0..num_slots {728 for slot in 0..num_slots {
711 let mut v = [Complex::ZERO; SYNTHESIS_BANDS];729 let mut v = [Complex::ZERO; SYNTHESIS_BANDS];
@@ -843,7 +861,8 @@ fn render_ps(
843 861
844 /// Runs `slots` through a synthesis bank, at the SBR output scale.862 /// Runs `slots` through a synthesis bank, at the SBR output scale.
845 fn synth_slots(synth: &mut Synthesis, slots: &[[Complex<f64>; SYNTHESIS_BANDS]]) -> Vec<f32> {863 fn synth_slots(synth: &mut Synthesis, slots: &[[Complex<f64>; SYNTHESIS_BANDS]]) -> Vec<f32> {
846- let mut out = Vec::with_capacity(slots.len() * SYNTHESIS_BANDS);864+ let bands = synth.bands();
865+ let mut out = Vec::with_capacity(slots.len() * bands);
847 for v in slots {866 for v in slots {
848 let mut pcm = synth.process_slot(v);867 let mut pcm = synth.process_slot(v);
849 for s in &mut pcm {868 for s in &mut pcm {
@@ -852,7 +871,7 @@ fn synth_slots(synth: &mut Synthesis, slots: &[[Complex<f64>; SYNTHESIS_BANDS]])
852 // core's amplitude; the 2x is the upsampler's gain.871 // core's amplitude; the 2x is the upsampler's gain.
853 *s *= 2.0 * crate::decode::OUTPUT_SCALE;872 *s *= 2.0 * crate::decode::OUTPUT_SCALE;
854 }873 }
855- out.extend_from_slice(&pcm);874+ out.extend_from_slice(&pcm[..bands]);
856 }875 }
857 out876 out
858 }877 }
crates/ec-aac/src/sbr_qmf.rsmodified+44 -42
@@ -218,70 +218,72 @@ impl Default for HfAnalysis {
218 }218 }
219 }219 }
220 220
221-/// The ISO/IEC 14496-3 4.6.18.8.2 64-band complex synthesis QMF bank:221+/// The ISO/IEC 14496-3 4.6.18.8.2 complex synthesis QMF bank: complex subband
222-/// complex subband slots in, doubled-rate PCM out, [`SYNTHESIS_BANDS`]222+/// slots in, PCM out. The 64-band form doubles the rate; the 32-band
223-/// output samples per slot. Verified against the literal spec equations at223+/// downsampled form (decimated window, band shift of half a sample like the
224-/// `corr=0.999999` self-consistency (see the module doc).224+/// analysis bank) keeps the core rate.
225 pub struct Synthesis {225 pub struct Synthesis {
226- /// History buffer `v`, `10 * PROTO_LEN / SYNTHESIS_BANDS * SYNTHESIS_BANDS`226+ bands: usize,
227- /// = `1280` samples (`4.6.18.8.2`'s own length, not `PROTO_LEN`).227+ v: Vec<f64>,
228- v: [f64; 1280],
229 cos_tab: Vec<f64>,228 cos_tab: Vec<f64>,
230 sin_tab: Vec<f64>,229 sin_tab: Vec<f64>,
231 }230 }
232 231
233 impl Synthesis {232 impl Synthesis {
234- /// A fresh bank with a silent history buffer.
235 pub fn new() -> Synthesis {233 pub fn new() -> Synthesis {
236- let mut cos_tab = vec![0.0f64; SYNTHESIS_BANDS * 128];234+ Synthesis::with_bands(SYNTHESIS_BANDS, 0.0)
237- let mut sin_tab = vec![0.0f64; SYNTHESIS_BANDS * 128];235+ }
238- for k in 0..SYNTHESIS_BANDS {236+
239- for n in 0..128 {237+ pub fn downsampled() -> Synthesis {
240- // phi = pi/128*(k+0.5)*(2n-255)238+ Synthesis::with_bands(SYNTHESIS_BANDS / 2, -0.5)
241- let phi = std::f64::consts::PI / 128.0239+ }
240+
241+ fn with_bands(bands: usize, shift: f64) -> Synthesis {
242+ let len = 2 * bands;
243+ let mut cos_tab = vec![0.0f64; bands * len];
244+ let mut sin_tab = vec![0.0f64; bands * len];
245+ for k in 0..bands {
246+ for n in 0..len {
247+ let phi = std::f64::consts::PI / len as f64
242 * (k as f64 + 0.5)248 * (k as f64 + 0.5)
243- * (2.0 * n as f64 - 255.0);249+ * (2.0 * n as f64 - (2 * len - 1) as f64 + shift);
244- cos_tab[k * 128 + n] = phi.cos();250+ cos_tab[k * len + n] = phi.cos();
245- sin_tab[k * 128 + n] = phi.sin();251+ sin_tab[k * len + n] = phi.sin();
246 }252 }
247 }253 }
248 Synthesis {254 Synthesis {
249- v: [0.0; 1280],255+ bands,
256+ v: vec![0.0; 10 * len],
250 cos_tab,257 cos_tab,
251 sin_tab,258 sin_tab,
252 }259 }
253 }260 }
254 261
255- /// Feeds one slot of [`SYNTHESIS_BANDS`] complex subband samples and262+ pub fn bands(&self) -> usize {
256- /// returns [`SYNTHESIS_BANDS`] output PCM samples.263+ self.bands
264+ }
265+
257 pub fn process_slot(&mut self, x: &[Complex<f64>; SYNTHESIS_BANDS]) -> [f32; SYNTHESIS_BANDS] {266 pub fn process_slot(&mut self, x: &[Complex<f64>; SYNTHESIS_BANDS]) -> [f32; SYNTHESIS_BANDS] {
258- // v[n] = v[n-128] for n=1279..128 (shift), then v[0..128] filled with267+ let bands = self.bands;
259- // v[n] = Re{ (1/64) sum_k X[k]*exp(j*phi) }, n=0..127.268+ let len = 2 * bands;
260- self.v.copy_within(0..1152, 128);269+ self.v.copy_within(0..9 * len, len);
261- for n in 0..128 {270+ for n in 0..len {
262 let mut re = 0.0f64;271 let mut re = 0.0f64;
263- for (k, xk) in x.iter().enumerate() {272+ for (k, xk) in x.iter().take(bands).enumerate() {
264- let row = k * 128;273+ let at = k * len + n;
265- // Re{X[k]*exp(j*phi)} = Xre*cos(phi) - Xim*sin(phi)274+ re += xk.re * self.cos_tab[at] - xk.im * self.sin_tab[at];
266- re += xk.re * self.cos_tab[row + n] - xk.im * self.sin_tab[row + n];
267 }275 }
268 self.v[n] = re / SYNTHESIS_BANDS as f64;276 self.v[n] = re / SYNTHESIS_BANDS as f64;
269 }277 }
270- // g[128i+n] = v[256i+n], g[128i+64+n] = v[256i+192+n], i=0..4, n=0..63278+ let step = SYNTHESIS_BANDS / bands;
271- let mut g = [0.0f64; PROTO_LEN];
272- for i in 0..5 {
273- for n in 0..64 {
274- g[128 * i + n] = self.v[256 * i + n];
275- g[128 * i + 64 + n] = self.v[256 * i + 192 + n];
276- }
277- }
278- // w[n] = g[n]*c[n], n=0..639; y[n] = sum_{k=0}^{9} w[64k+n], n=0..63
279 let mut out = [0.0f32; SYNTHESIS_BANDS];279 let mut out = [0.0f32; SYNTHESIS_BANDS];
280- for (n, o) in out.iter_mut().enumerate() {280+ for (n, o) in out.iter_mut().take(bands).enumerate() {
281 let mut acc = 0.0f64;281 let mut acc = 0.0f64;
282- for k in 0..10 {282+ for i in 0..5 {
283- let idx = 64 * k + n;283+ let near = self.v[2 * len * i + n];
284- acc += g[idx] * QMF_WINDOW[idx];284+ let far = self.v[2 * len * i + 3 * bands + n];
285+ acc += near * QMF_WINDOW[step * (len * i + n)];
286+ acc += far * QMF_WINDOW[step * (len * i + bands + n)];
285 }287 }
286 *o = acc as f32;288 *o = acc as f32;
287 }289 }
@@ -470,7 +472,7 @@ mod tests {
470 assert_eq!(QMF_WINDOW.len(), PROTO_LEN);472 assert_eq!(QMF_WINDOW.len(), PROTO_LEN);
471 let sum: f64 = QMF_WINDOW.iter().sum();473 let sum: f64 = QMF_WINDOW.iter().sum();
472 let sum_sq: f64 = QMF_WINDOW.iter().map(|v| v * v).sum();474 let sum_sq: f64 = QMF_WINDOW.iter().map(|v| v * v).sum();
473- assert!((sum - 81.46300943655164).abs() < 1e-9, "sum={sum}");475+ assert!((sum - 82.21187106118578).abs() < 1e-9, "sum={sum}");
474 assert!((sum_sq - 64.00000000000003).abs() < 1e-9, "sum_sq={sum_sq}");476 assert!((sum_sq - 64.00000000000003).abs() < 1e-9, "sum_sq={sum_sq}");
475 }477 }
476 478
crates/ec-aac/src/sbr_qmf_window.rsmodified+3 -3
@@ -114,7 +114,7 @@ pub const QMF_WINDOW: [f64; 640] = [
114 0.49677082545707, 0.48552530911099, 0.47424532146115, 0.46293080852757,114 0.49677082545707, 0.48552530911099, 0.47424532146115, 0.46293080852757,
115 0.45159965356824, 0.44025537543665, 0.42891199207373, 0.41756968968409,115 0.45159965356824, 0.44025537543665, 0.42891199207373, 0.41756968968409,
116 0.40623176767625, 0.39492117615675, 0.38363500139043, 0.37237955463061,116 0.40623176767625, 0.39492117615675, 0.38363500139043, 0.37237955463061,
117- -0.36115899031355, -0.3499914122931, -0.33887226938665, -0.32781137272105,117+ 0.36115899031355, -0.3499914122931, -0.33887226938665, -0.32781137272105,
118 -0.31682789136456, -0.30590985751916, -0.29507167170646, -0.28432141891085,118 -0.31682789136456, -0.30590985751916, -0.29507167170646, -0.28432141891085,
119 -0.27366340405625, -0.26310532994603, -0.25264803095722, -0.24230168845974,119 -0.27366340405625, -0.26310532994603, -0.25264803095722, -0.24230168845974,
120 -0.23206908706791, -0.22196526964149, -0.21197358538056, -0.20212501768103,120 -0.23206908706791, -0.22196526964149, -0.21197358538056, -0.20212501768103,
@@ -146,7 +146,7 @@ pub const QMF_WINDOW: [f64; 640] = [
146 0.02860721736385, 0.02718594296329, 0.02578758475467, 0.02441609920285,146 0.02860721736385, 0.02718594296329, 0.02578758475467, 0.02441609920285,
147 0.02306801692862, 0.02174675502535, 0.02045317933555, 0.01918724313698,147 0.02306801692862, 0.02174675502535, 0.02045317933555, 0.01918724313698,
148 0.01794333813443, 0.01673247129989, 0.01554055533423, 0.01439046660792,148 0.01794333813443, 0.01673247129989, 0.01554055533423, 0.01439046660792,
149- -0.01327182200351, -0.01218499959508, -0.01113155480321, -0.01011502154986,149+ 0.01327182200351, -0.01218499959508, -0.01113155480321, -0.01011502154986,
150 -0.00913253296085, -0.00817982333726, -0.00726158168517, -0.00637922932685,150 -0.00913253296085, -0.00817982333726, -0.00726158168517, -0.00637922932685,
151 -0.00553372111088, -0.004722259624, -0.00394011240522, -0.003193377839,151 -0.00553372111088, -0.004722259624, -0.00394011240522, -0.003193377839,
152 -0.00248267236449, -0.00180394725893, -0.00115681355227, -0.00054642808664,152 -0.00248267236449, -0.00180394725893, -0.00115681355227, -0.00054642808664,
@@ -196,7 +196,7 @@ mod tests {
196 argmax = i;196 argmax = i;
197 }197 }
198 }198 }
199- assert!((sum - 81.46300943655164).abs() < 1e-9, "sum={sum}");199+ assert!((sum - 82.21187106118578).abs() < 1e-9, "sum={sum}");
200 assert!((sum_sq - 64.00000000000003).abs() < 1e-9, "sum_sq={sum_sq}");200 assert!((sum_sq - 64.00000000000003).abs() < 1e-9, "sum_sq={sum_sq}");
201 assert!((max - 0.85373856005937).abs() < 1e-12, "max={max}");201 assert!((max - 0.85373856005937).abs() < 1e-12, "max={max}");
202 assert_eq!(argmax, 320);202 assert_eq!(argmax, 320);