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

Method read_labels

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

Source from the content-addressed store, hash-verified

75 }
76
77 fn read_labels(fname: &str) -> Result<Vec<u8>, &'static str> {
78
79 let mut data = try!(GzipData::from_file(fname));
80
81 if try!(MnistDigits::read_u32(&mut data)) != 8 * 256 + 1 {
82 return Err("Invalid magic number.");
83 }
84
85 let n = try!(MnistDigits::read_u32(&mut data));
86
87 let l: Vec<u8> = data.iter().cloned().collect();
88 if l.len() != n as usize {
89 return Err("Invalid number of items.");
90 }
91
92 if !l.iter().all(|&x| x <= 9) {
93 return Err("Found invalid values for labels.");
94 }
95
96 Ok(l)
97 }
98
99 fn read_examples(fname: &str) -> Result<Vec<u8>, &'static str> {
100

Callers

nothing calls this directly

Calls 3

from_fileFunction · 0.85
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected