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::IdxSplit;
use crate::core::pack::{FetchProgress, Pack, PackFile};
use oa::{Engine, Result};
use std::path::PathBuf;

pub(crate) const MOVIELENS_100K_PACK: Pack = Pack {
	name: "movielens_100k",
	version: "0.9.0",
	license: "custom research license",
	files: &[PackFile {
		name: "ml-100k.zip",
		size: 4_924_029,
		shake256: "acd15fe1a40e7edb02c19b0c011233b307605b387a0bbbb780a337206e43dca6",
		urls: &["https://files.grouplens.org/datasets/movielens/ml-100k.zip"],
	}],
};

/// `[user_id, item_id, timestamp]` per rating row.
pub const FEATURE_COUNT: usize = 3;

/// Official u1.base/u1.test split selection.
pub type Movielens100kSplit = IdxSplit;

/// Load options for [`Movielens100k`][crate::tabular::movielens_100k::Movielens100k].
#[derive(Clone, Debug)]
pub struct Movielens100kConfig {
	/// Which official u1 cross-validation split to materialize.
	pub split: Movielens100kSplit,
	/// Cache root override. `None` resolves `OA_DATA_DIR`, then the platform
	/// cache directory; see [`data_root`](crate::pack::data_root).
	pub cache_dir: Option<PathBuf>,
}

impl Default for Movielens100kConfig {
	fn default() -> Self {
		Self {
			split: Movielens100kSplit::Train,
			cache_dir: None,
		}
	}
}

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

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