Skip to content

Commit 95aa69b

Browse files
committed
style(everything): rustfmt everything
1 parent 9e40f7d commit 95aa69b

File tree

7 files changed

+238
-46
lines changed

7 files changed

+238
-46
lines changed

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
format_strings = false
22
reorder_imports = true
3+
max_width = 120

src/blob.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub struct Blob<T> {
22
data: Vec<T>,
33
diff: Vec<T>,
4-
shape: Vec<isize>
4+
shape: Vec<isize>,
55
}
66

77
impl <T> Blob<T> {
@@ -14,7 +14,7 @@ impl <T> Blob<T> {
1414
let mut blob = Blob {
1515
data: vec![],
1616
diff: vec![],
17-
shape: vec![0]
17+
shape: vec![0],
1818
};
1919
blob.reshape(new_shape);
2020

@@ -24,7 +24,8 @@ impl <T> Blob<T> {
2424
pub fn reshape(&mut self, new_shape: Vec<isize>) {
2525
let mut new_capacity = 1;
2626

27-
for dimension in new_shape.iter() { // not sure if dimension is a fitting description
27+
for dimension in new_shape.iter() {
28+
// not sure if dimension is a fitting description
2829
new_capacity *= *dimension;
2930
}
3031
self.shape = new_shape;

src/layer.rs

+39-10
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ use blob::Blob;
22
use math::*;
33

44
pub struct Layer {
5-
top: Vec<Layer>
5+
top: Vec<Layer>,
66
}
77

88
fn sigmoid(z: f32) -> f32 {
9-
return 1f32 / (1f32 + (-z).exp())
9+
1f32 / (1f32 + (-z).exp())
1010
}
1111

1212
fn sigmoid_prime(z: f32) -> f32 {
13-
return sigmoid_prime_precalc(sigmoid(z))
13+
sigmoid_prime_precalc(sigmoid(z))
1414
}
1515

1616
fn sigmoid_prime_precalc(sigmoid_z: f32) -> f32 {
17-
return sigmoid_z * (1f32 - sigmoid_z)
17+
sigmoid_z * (1f32 - sigmoid_z)
1818
}
1919

2020
impl Layer {
@@ -38,11 +38,11 @@ impl Layer {
3838

3939
// Unlock();
4040

41-
return loss
41+
loss
4242
}
4343

4444
// forward_cpu for sigmoid layer
45-
pub fn forward_cpu(&self, bottom: &Vec<Box<Blob<f32>>>, top: &mut Vec<Box<Blob<f32>>>){
45+
pub fn forward_cpu(&self, bottom: &Vec<Box<Blob<f32>>>, top: &mut Vec<Box<Blob<f32>>>) {
4646
let bottom_data = bottom[0].cpu_data();
4747
let top_data = top[0].mutable_cpu_data();
4848

@@ -52,7 +52,10 @@ impl Layer {
5252
}
5353

5454
// backward_cpu for sigmoid layer
55-
pub fn backward_cpu(&self, top: &Vec<Box<Blob<f32>>>, propagate_down: &Vec<bool>, bottom: &mut Vec<Box<Blob<f32>>>) {
55+
pub fn backward_cpu(&self,
56+
top: &Vec<Box<Blob<f32>>>,
57+
propagate_down: &Vec<bool>,
58+
bottom: &mut Vec<Box<Blob<f32>>>) {
5659
if propagate_down[0] {
5760
let top_data = top[0].cpu_data();
5861
let top_diff = top[0].cpu_diff();
@@ -66,6 +69,16 @@ impl Layer {
6669
}
6770
}
6871
}
72+
73+
pub fn auto_top_blobs(&self) -> bool {
74+
false
75+
}
76+
pub fn min_top_blobs(&self) -> usize {
77+
0
78+
}
79+
pub fn exact_num_top_blobs(&self) -> usize {
80+
0
81+
}
6982
}
7083

7184
pub struct LayerConfig {
@@ -75,10 +88,26 @@ pub struct LayerConfig {
7588
bottoms: Vec<String>, // the name of each bottom blob; called bottom in Caffe
7689
tops: Vec<String>, // the name of each top blob; called top in Caffe
7790

78-
// minimal, a lot of Caffe not ported yet
91+
// Specifies on which bottoms the backpropagation should be skipped.
92+
// The size must be either 0 or equal to the number of bottoms.
93+
propagate_down: Vec<bool>, // minimal, a lot of Caffe not ported yet
7994
}
8095

8196
impl LayerConfig {
82-
pub fn top(&self, top_id: usize) -> Option<&String> { return self.tops.get(top_id); }
83-
pub fn bottom(&self, bottom_id: usize) -> Option<&String> { return self.bottoms.get(bottom_id); }
97+
pub fn top(&self, top_id: usize) -> Option<&String> {
98+
self.tops.get(top_id)
99+
}
100+
pub fn tops_len(&self) -> usize {
101+
self.tops.len()
102+
}
103+
pub fn bottom(&self, bottom_id: usize) -> Option<&String> {
104+
self.bottoms.get(bottom_id)
105+
}
106+
pub fn bottoms_len(&self) -> usize {
107+
self.bottoms.len()
108+
}
109+
110+
pub fn check_propagate_down_len(&self) -> bool {
111+
self.propagate_down.len() == 0 || self.propagate_down.len() == self.bottoms.len()
112+
}
84113
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
unstable_features,
99
unused_import_braces, unused_qualifications)]
1010

11+
#![feature(vec_resize)]
1112

1213
#[macro_use]
1314
extern crate log;

0 commit comments

Comments
 (0)