///| Ordinary autoregressive decoding baseline. It intentionally shares the

///| probability and metrics types with speculative decoding so comparison is

///|
/// apples-to-apples: one target distribution produces exactly one token.
pub enum BaselineError {
  EmptySchedule
  ProbabilityFailure(Int)
} derive(Eq, Debug)

///|
pub fn decode_autoregressive(
  prefix : Array[Int],
  target_logits : Array[Array[Double]],
  uniforms : Array[Double],
) -> Result[SimulationResult, BaselineError] {
  if target_logits.length() == 0 || target_logits.length() != uniforms.length() {
    return Err(EmptySchedule)
  }
  let generated : Array[Int] = []
  for token in prefix {
    generated.push(token)
  }
  let metrics = DecodeMetrics::empty()
  for index in 0.. value
      Err(_) => return Err(ProbabilityFailure(index))
    }
    let token = match sample_categorical(distribution, uniforms[index]) {
      Ok(value) => value
      Err(_) => return Err(ProbabilityFailure(index))
    }
    generated.push(token)
    metrics.target_batches = metrics.target_batches + 1
    metrics.emitted_tokens = metrics.emitted_tokens + 1
  }
  Ok({ generated, metrics, rounds: target_logits.length() })
}