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 SMALLNORB_PACK: Pack = Pack {
	name: "smallnorb",
	version: "1.0.0",
	license: "CC BY-SA 3.0 (attribution, NYU)",
	files: &[
		PackFile {
			name: "training-dat.gz",
			size: 131_896_188,
			shake256: "737be6afab2463d95611421444cf7707d34f72bc8f0cec8d9ebd4ce0f050fe16",
			urls: &[
				"https://cs.nyu.edu/~ylclab/data/norb-v1.0-small/smallnorb-5x46789x9x18x6x2x96x96-training-dat.mat.gz",
			],
		},
		PackFile {
			name: "training-cat.gz",
			size: 348,
			shake256: "3f1e94930ea384b2ecef08cca9b43af1e7e9757526bf0b10b6ee0f7a91b503d3",
			urls: &[
				"https://cs.nyu.edu/~ylclab/data/norb-v1.0-small/smallnorb-5x46789x9x18x6x2x96x96-training-cat.mat.gz",
			],
		},
		PackFile {
			name: "training-info.gz",
			size: 71_052,
			shake256: "f95711c2fb6381f566c771d1cf7f69580f7b81aca31c7513de9dcdb47c947bb1",
			urls: &[
				"https://cs.nyu.edu/~ylclab/data/norb-v1.0-small/smallnorb-5x46789x9x18x6x2x96x96-training-info.mat.gz",
			],
		},
		PackFile {
			name: "testing-dat.gz",
			size: 130_799_817,
			shake256: "5cac160c412103ae38a810c92729ea2423428db36cf48e0f9498a37285d016f3",
			urls: &[
				"https://cs.nyu.edu/~ylclab/data/norb-v1.0-small/smallnorb-5x01235x9x18x6x2x96x96-testing-dat.mat.gz",
			],
		},
		PackFile {
			name: "testing-cat.gz",
			size: 347,
			shake256: "2b71364067b90bac7cc5604f6093e294698bb17cbce6300d37734f73f9606077",
			urls: &[
				"https://cs.nyu.edu/~ylclab/data/norb-v1.0-small/smallnorb-5x01235x9x18x6x2x96x96-testing-cat.mat.gz",
			],
		},
		PackFile {
			name: "testing-info.gz",
			size: 10_428,
			shake256: "1e1d0aaa0a3bcf1fc871e8aeb518da679c76b3e130ca43dd02497426cfd75257",
			urls: &[
				"https://cs.nyu.edu/~ylclab/data/norb-v1.0-small/smallnorb-5x01235x9x18x6x2x96x96-testing-info.mat.gz",
			],
		},
	],
};

/// Official small NORB split selection.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum SmallnorbSplit {
	/// `training-*.gz` members (24,300 pairs).
	#[default]
	Train,
	/// `testing-*.gz` members (24,300 pairs).
	Test,
}

/// Load options for [`Smallnorb`][crate::image::smallnorb::Smallnorb].
#[derive(Clone, Debug)]
pub struct SmallnorbConfig {
	/// Which official split to materialize.
	pub split: SmallnorbSplit,
	/// Scale pixels into `[0, 1]`; `false` keeps raw `0..=255`.
	pub normalize: bool,
	/// 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 SmallnorbConfig {
	fn default() -> Self {
		Self {
			split: SmallnorbSplit::Train,
			normalize: true,
			cache_dir: None,
		}
	}
}

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

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