MCPcopy Create free account
hub / github.com/daniel-e/rustml / read_examples

Method read_examples

src/datasets.rs:99–121  ·  view source on GitHub ↗
(fname: &str)

Source from the content-addressed store, hash-verified

97 }
98
99 fn read_examples(fname: &str) -> Result<Vec<u8>, &'static str> {
100
101 let mut data = try!(GzipData::from_file(fname));
102
103 if try!(MnistDigits::read_u32(&mut data)) != 8 * 256 + 3 {
104 return Err("Invalid magic number.");
105 }
106
107 let n = try!(MnistDigits::read_u32(&mut data));
108
109 let rows = try!(MnistDigits::read_u32(&mut data));
110 let cols = try!(MnistDigits::read_u32(&mut data));
111 if rows != 28 || cols != 28 {
112 return Err("Invalid number of rows or columns.");
113 }
114
115 let v = data.buf();
116 if v.len() != (n * 28 * 28) as usize {
117 return Err("Could not read data.");
118 }
119
120 Ok(v.to_vec())
121 }
122
123 pub fn from(vectors_fname: &str, labels_fname: &str) -> Result<(Matrix<u8>, Vec<u8>), &'static str> {
124

Callers

nothing calls this directly

Calls 4

from_fileFunction · 0.85
bufMethod · 0.45
lenMethod · 0.45
to_vecMethod · 0.45

Tested by

no test coverage detected