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 IMDB_PACK: Pack = Pack {
	name: "imdb",
	version: "1.0.0",
	license: "unspecified",
	files: &[PackFile {
		name: "aclImdb_v1.tar.gz",
		size: 84_125_825,
		shake256: "2688e6ee353cdc3412901bad1cd42be7d432a845c0b231e2860d822eebd14e81",
		urls: &["https://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz"],
	}],
};

/// Official imdb split selection.
pub type ImdbSplit = IdxSplit;

/// Load options for [`Imdb`][crate::text::imdb::Imdb].
#[derive(Clone, Debug)]
pub struct ImdbConfig {
	/// Which official split to materialize.
	pub split: ImdbSplit,
	/// Document window in UTF-8 bytes; longer documents truncate,
	/// shorter ones zero-pad.
	pub text_len: usize,
	/// 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>,
	/// Scale bytes into `[0, 1]`. `false` keeps raw `0..=255` values.
	pub normalize: bool,
}

impl Default for ImdbConfig {
	fn default() -> Self {
		Self {
			split: ImdbSplit::Train,
			text_len: 512,
			cache_dir: None,
			normalize: true,
		}
	}
}

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

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