coremlit 0.1.2

Safe, synchronous CoreML runtime for macOS (CPU/GPU/Neural Engine) with opt-in on-device multimodal pipelines: speech (Whisper STT, forced alignment, speaker diarization, Silero VAD), AudioSet sound-event tagging, and audio/text/image embeddings (CLAP, granite, SigLIP)
//! `Model::compile` Ok path over a committed 120-byte identity `.mlmodel`
//! (generated by coremltools; see the fixture's short_description). Runs on
//! any macOS machine — no downloaded models, so NOT `#[ignore]`-gated.

use std::path::PathBuf;

use coremlit::{ComputeUnits, DataType, Features, Model, MultiArray};

#[test]
fn compile_produces_a_loadable_predictable_mlmodelc() {
  let source = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/identity.mlmodel");
  let compiled = Model::compile(&source).expect("CoreML compiles the identity model");
  assert_eq!(
    compiled.extension().and_then(|e| e.to_str()),
    Some("mlmodelc"),
    "compile returns the emitted bundle path, got {}",
    compiled.display()
  );
  assert!(compiled.is_dir(), "compiled model is a bundle directory");

  // The Ok path is only proven if the artifact actually runs.
  let model = Model::load(&compiled, ComputeUnits::CpuOnly).expect("compiled bundle loads");
  let x = MultiArray::from_slice(&[2], &[1.5f32, -2.0]).unwrap();
  let outputs = model.predict(&Features::new().with("x", x)).unwrap();
  let y = outputs.get("y").expect("identity output present");
  assert_eq!(y.shape(), vec![2]);
  assert_eq!(y.data_type(), DataType::F32);
  let values = y.as_slice::<f32>().unwrap();
  assert!(
    (values[0] - 1.5).abs() < 1e-6 && (values[1] + 2.0).abs() < 1e-6,
    "y == x"
  );

  // compile() emits a fresh temp bundle per call; leave no litter.
  std::fs::remove_dir_all(&compiled).expect("temp bundle removable");
}