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 TITANIC_PACK: Pack = Pack {
	name: "titanic",
	version: "1.0.0",
	license: "UNSPECIFIED",
	files: &[PackFile {
		name: "titanic.csv",
		size: 60_302,
		shake256: "f2633850d881726f82fe8afaec62694aa126dc5d39ba48d61cee8ae3d01fe56f",
		urls: &["https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv"],
	}],
};

/// `[pclass, sex, age, sibsp, parch, fare, embarked_C, embarked_Q,
/// embarked_S]` per passenger.
pub const FEATURE_COUNT: usize = 9;

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

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

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

impl super::Titanic {
	/// 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: &TitanicConfig) -> 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: &TitanicConfig) -> 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: &TitanicConfig,
		progress: &mut impl FnMut(FetchProgress) -> bool,
	) -> Result<Self> {
		Self::load_with_progress_on(&Engine::current()?, config, progress)
	}
}