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 FASHION_MNIST_PACK: Pack = Pack {
	name: "fashion_mnist",
	version: "1.0.0",
	license: "MIT",
	files: &[
		PackFile {
			name: "train-images-idx3-ubyte.gz",
			size: 26_421_880,
			shake256: "287217197fbade1cabc218dbc30a6ba2da0e6a3af5b4aa4185f3fd24f94ddabf",
			urls: &[
				"http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz",
				"https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz",
			],
		},
		PackFile {
			name: "train-labels-idx1-ubyte.gz",
			size: 29_515,
			shake256: "8acdf6a86fbee77624e8f5746b475a5bf3f387f76370df41cd7d6b63cea2fa21",
			urls: &[
				"http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz",
				"https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz",
			],
		},
		PackFile {
			name: "t10k-images-idx3-ubyte.gz",
			size: 4_422_102,
			shake256: "897f33e93438e9eb054bd6103c0396f009a7d1035be8c726ef28ca3bd8dfabed",
			urls: &[
				"http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz",
				"https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz",
			],
		},
		PackFile {
			name: "t10k-labels-idx1-ubyte.gz",
			size: 5_148,
			shake256: "16a6ca6f5f7f62ce4ba3d742a4fa9444a73b82bd5e5df971edd4ea468f6d77cf",
			urls: &[
				"http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz",
				"https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz",
			],
		},
	],
};

/// Official Fashion-MNIST split selection.
pub type FashionMnistSplit = IdxSplit;

/// Load options for [`FashionMnist`][crate::image::fashion_mnist::FashionMnist].
#[derive(Clone, Debug)]
pub struct FashionMnistConfig {
	/// Which official split to materialize.
	pub split: FashionMnistSplit,
	/// 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 FashionMnistConfig {
	fn default() -> Self {
		Self {
			split: FashionMnistSplit::Train,
			cache_dir: None,
			normalize: true,
		}
	}
}

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

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