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 MOVING_MNIST_PACK: Pack = Pack {
	name: "moving_mnist",
	version: "1.0.0",
	license: "CC-BY-SA-3.0",
	files: &[PackFile {
		name: "mnist_test_seq.npy",
		size: 819_200_096,
		shake256: "44136c19911ddfc9a8d6353aee5bb7ba42e359e5bfb24a8ea7fe03ec6f4ca6ce",
		urls: &[
			"https://www.cs.toronto.edu/~nitish/unsupervised_video/mnist_test_seq.npy",
			"http://www.cs.toronto.edu/~nitish/unsupervised_video/mnist_test_seq.npy",
		],
	}],
};

/// Load options for [`MovingMnist`][crate::video::moving_mnist::MovingMnist].
#[derive(Clone, Debug)]
pub struct MovingMnistConfig {
	/// Bound the number of materialized sequences; `None` decodes all
	/// 10,000.
	pub count: Option<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 pixels into `[0, 1]`. `false` keeps raw `0..=255` values.
	pub normalize: bool,
}

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

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

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