extern crate smyl; use std::fs::File; use std::io::{BufWriter, Write}; use std::time::Instant; use rand::seq::SliceRandom; use rand::thread_rng; use smyl::prelude::*; const IMAGE_HEIGHT: usize = 28; const IMAGE_WIDTH: usize = 28; #[derive(Debug, Copy, Clone)] struct Label(u8); #[derive(Debug, Copy, Clone)] struct Image([u8; IMAGE_HEIGHT * IMAGE_WIDTH]); impl Read for Image { fn read(reader: &mut Reader) -> std::io::Result { let mut pixels = [0; IMAGE_HEIGHT * IMAGE_WIDTH]; reader.read_buf(&mut pixels)?; Ok(Self(pixels)) } } impl Idx for Image { #[allow(clippy::cast_possible_truncation)] const EXPECTED_DIMENSIONS: &'static [u32] = &[IMAGE_HEIGHT as u32, IMAGE_WIDTH as u32]; const MAGIC_WORD: u32 = 0x0000_0803; } impl Read for Label { fn read(reader: &mut Reader) -> std::io::Result { Ok(Self(reader.read_other()?)) } } impl Idx for Label { const EXPECTED_DIMENSIONS: &'static [u32] = &[]; const MAGIC_WORD: u32 = 0x0000_0801; } const LEARNING_RATE: f64 = 0.01; const BATCH: usize = 1; struct MNISTDataset { train_labels: Vec>, train_inputs: Vec>, test_labels: Vec>, test_inputs: Vec>, } impl MNISTDataset { const TESTING_SAMPLE_COUNT: usize = 10_000; const TRAINING_SAMPLE_COUNT: usize = 60_000; pub fn read() -> std::io::Result { let mut train_labels = Vec::with_capacity(Self::TRAINING_SAMPLE_COUNT); let mut train_inputs = Vec::with_capacity(Self::TRAINING_SAMPLE_COUNT); let mut test_labels = Vec::with_capacity(Self::TESTING_SAMPLE_COUNT); let mut test_inputs = Vec::with_capacity(Self::TESTING_SAMPLE_COUNT); let mut train_labels_reader: Reader