MCPcopy Create free account
hub / github.com/bamler-lab/constriction / decode

Method decode

src/pybindings/stream/queue.rs:599–656  ·  view source on GitHub ↗
(
        &mut self,
        py: Python<'_>,
        model: &Model,
        optional_amt_or_model_params: &Bound<'_, PyTuple>,
    )

Source from the content-addressed store, hash-verified

597 /// ```
598 #[pyo3(signature = (model, *optional_amt_or_model_params))]
599 pub fn decode(
600 &mut self,
601 py: Python<'_>,
602 model: &Model,
603 optional_amt_or_model_params: &Bound<'_, PyTuple>,
604 ) -> PyResult<Py<PyAny>> {
605 match optional_amt_or_model_params.len() {
606 0 => {
607 let mut symbol = 0;
608 model.0.as_parameterized(py, &mut |model| {
609 symbol = self.inner.decode_symbol(EncoderDecoderModel(model))?;
610 Ok(())
611 })?;
612 return Ok(symbol
613 .into_pyobject(py)
614 .unwrap_infallible()
615 .into_any()
616 .unbind());
617 }
618 1 => {
619 if let Ok(amt) = optional_amt_or_model_params
620 .get_borrowed_item(0)
621 .expect("len checked above")
622 .extract::<usize>()
623 {
624 let mut symbols = Vec::with_capacity(amt);
625 model.0.as_parameterized(py, &mut |model| {
626 for symbol in self
627 .inner
628 .decode_iid_symbols(amt, EncoderDecoderModel(model))
629 {
630 symbols.push(symbol?);
631 }
632 Ok(())
633 })?;
634 return Ok(PyArray1::from_iter(py, symbols).into_any().unbind());
635 }
636 }
637 _ => {} // Fall through to code below.
638 };
639
640 let mut symbols = Vec::with_capacity(
641 model.0.len(
642 optional_amt_or_model_params
643 .get_borrowed_item(0)
644 .expect("len checked above"),
645 )?,
646 );
647 model
648 .0
649 .parameterize(py, optional_amt_or_model_params, false, &mut |model| {
650 let symbol = self.inner.decode_symbol(EncoderDecoderModel(model))?;
651 symbols.push(symbol);
652 Ok(())
653 })?;
654
655 Ok(PyArray1::from_vec(py, symbols).into_any().unbind())
656 }

Callers 15

test_module_example2Function · 0.95
test_module_example3Function · 0.95
test_range_coding_modFunction · 0.95
test_old_module_example2Function · 0.95
test_range_coding_seekFunction · 0.95
fixed_model_paramsFunction · 0.95
variable_model_paramsFunction · 0.95
discrete_distributionFunction · 0.95

Calls 7

EncoderDecoderModelClass · 0.85
unwrap_infallibleMethod · 0.80
lenMethod · 0.45
as_parameterizedMethod · 0.45
decode_symbolMethod · 0.45
decode_iid_symbolsMethod · 0.45
parameterizeMethod · 0.45

Tested by 15

test_module_example2Function · 0.76
test_module_example3Function · 0.76
test_range_coding_modFunction · 0.76
test_old_module_example2Function · 0.76
test_range_coding_seekFunction · 0.76
fixed_model_paramsFunction · 0.76
variable_model_paramsFunction · 0.76
discrete_distributionFunction · 0.76