oadsrust 0.3.0

Content-addressed dataset packs and loaders for OA
// @generated by tool/gen/ds/generate.py — edit tool/gen/ds/schema/packs.json instead.
use crate::core::pack::{FetchProgress, Pack, PackFile};
use oa::{Engine, Result};
use std::path::PathBuf;

pub(crate) const IRIS_PACK: Pack = Pack {
	name: "iris",
	version: "1.0.0",
	license: "PUBLIC-DOMAIN",
	files: &[PackFile {
		name: "iris.zip",
		size: 3_738,
		shake256: "7418f5e74f2344148ad3b6b98401bf9acc347d0e00ded050131fb5e49259afff",
		urls: &["https://archive.ics.uci.edu/static/public/53/iris.zip"],
	}],
};

/// Species labels in canonical order; label index `i` names `CLASSES[i]`.
pub const CLASSES: [&str; 3] = ["setosa", "versicolor", "virginica"];

/// Sepal/petal length and width columns in centimetres.
pub const FEATURE_COUNT: usize = 4;

/// Load options for [`Iris`][crate::tabular::iris::Iris].
#[derive(Clone, Debug)]
pub struct IrisConfig {
	/// Scale each column to `[0, 1]` by its min-max range; `false` keeps
	/// centimetres.
	pub normalize: bool,
	/// Cache root override; `None` resolves `OA_DATA_DIR`, then the platform
	/// cache.
	pub cache_dir: Option<PathBuf>,
}

impl Default for IrisConfig {
	fn default() -> Self {
		Self {
			normalize: true,
			cache_dir: None,
		}
	}
}

impl IrisConfig {
	/// Construct the record with its default state.
	#[inline]
	#[must_use]
	pub fn new() -> Self {
		Self::default()
	}
}

impl super::Iris {
	/// Decode the selected split and upload it on this thread's
	/// default engine.
	///
	/// # Errors
	///
	/// Returns an error when the default engine cannot be
	/// initialized, plus the errors of
	/// [`load_on`](Self::load_on).
	#[inline]
	pub fn load(config: &IrisConfig) -> Result<Self> {
		Self::load_on(&Engine::current()?, config)
	}

	/// Decode the selected split and upload it on `engine`.
	///
	/// This is the [`load`](Self::load) contract evaluated on
	/// `engine` instead of this thread's default engine.
	///
	/// # Errors
	///
	/// Returns the errors of
	/// [`load_with_progress_on`](Self::load_with_progress_on).
	#[inline]
	pub fn load_on(engine: &Engine, config: &IrisConfig) -> Result<Self> {
		Self::load_with_progress_on(engine, config, &mut |_| true)
	}

	/// [`load`](Self::load) with a fetch progress callback.
	///
	/// # Errors
	///
	/// Returns an error when the default engine cannot be
	/// initialized, plus the errors of
	/// [`load_with_progress_on`](Self::load_with_progress_on).
	#[inline]
	pub fn load_with_progress(
		config: &IrisConfig,
		progress: &mut impl FnMut(FetchProgress) -> bool,
	) -> Result<Self> {
		Self::load_with_progress_on(&Engine::current()?, config, progress)
	}
}