Skip to content

Commit 6b1492f

Browse files
committed
cargo fix clippy and fmt
1 parent ab24ea2 commit 6b1492f

7 files changed

Lines changed: 34 additions & 37 deletions

File tree

examples/mnist/cpu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use flate2::read::GzDecoder;
22
use meuron::activation::{ReLU, Softmax};
33
use meuron::cost::CrossEntropy;
4+
use meuron::initializer::{HeNormal, XavierUniform, Zeros};
45
use meuron::layer::DenseLayer;
56
use meuron::metric::classification::accuracy;
67
use meuron::optimizer::SGD;
7-
use meuron::initializer::{HeNormal, Zeros, XavierUniform};
88
use meuron::train::TrainOptions;
99
use meuron::{Layers, NetworkType, NeuralNetwork};
1010
use ndarray::Array2;

examples/mnist/draw.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ const FILES: &[&str] = &[
2828
"t10k-labels-idx1-ubyte.gz",
2929
];
3030

31-
type MnistNet = NeuralNetwork<
32-
NetworkType![DenseLayer<ReLU>, DenseLayer<Softmax>],
33-
CrossEntropy,
34-
>;
31+
type MnistNet = NeuralNetwork<NetworkType![DenseLayer<ReLU>, DenseLayer<Softmax>], CrossEntropy>;
3532

3633
#[derive(Clone)]
3734
struct TrainConfig {
@@ -393,9 +390,11 @@ fn draw_idle(ui: &mut egui::Ui, app: &mut App) {
393390
if PathBuf::from(MODEL_PATH).exists() {
394391
ui.add_space(10.0);
395392
ui.label(
396-
RichText::new("A saved model exists and will be overwritten on the next training run.")
397-
.size(11.0)
398-
.color(Color32::from_gray(95)),
393+
RichText::new(
394+
"A saved model exists and will be overwritten on the next training run.",
395+
)
396+
.size(11.0)
397+
.color(Color32::from_gray(95)),
399398
);
400399
}
401400
});
@@ -479,9 +478,12 @@ fn draw_training(ui: &mut egui::Ui, app: &mut App) {
479478

480479
if has_val && !val_pts.is_empty() {
481480
plot_ui.line(
482-
egui_plot::Line::new("Validation", egui_plot::PlotPoints::from(val_pts))
483-
.color(Color32::from_rgb(255, 160, 50))
484-
.width(2.0),
481+
egui_plot::Line::new(
482+
"Validation",
483+
egui_plot::PlotPoints::from(val_pts),
484+
)
485+
.color(Color32::from_rgb(255, 160, 50))
486+
.width(2.0),
485487
);
486488
}
487489
});

examples/mnist/gpu.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use flate2::read::GzDecoder;
22
use meuron::activation::{ReLU, Softmax};
33
use meuron::cost::CrossEntropy;
4+
use meuron::initializer::{HeNormal, XavierUniform, Zeros};
45
use meuron::layer::DenseLayer;
56
use meuron::metric::classification::accuracy;
67
use meuron::optimizer::SGDMomentum;
7-
use meuron::initializer::{HeNormal, Zeros, XavierUniform};
88
use meuron::train::TrainOptions;
99
use meuron::{Layers, NetworkType, NeuralNetwork};
1010
use ndarray::Array2;
@@ -109,7 +109,7 @@ fn main() {
109109

110110
let mut nn: MnistNetwork = if PathBuf::from(model_path).exists() {
111111
println!("Loading existing model...");
112-
NeuralNetwork::load(model_path, MSE).expect("Failed to load model")
112+
NeuralNetwork::load(model_path, CrossEntropy).expect("Failed to load model")
113113
} else {
114114
println!("Creating new model...");
115115
NeuralNetwork::new(

src/backend/gpu/backend.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,12 @@ impl Backend for GPUBackend {
4747
}
4848

4949
fn random_uniform<D: Dimension>(shape: D, low: f32, high: f32) -> GpuTensor<D> {
50-
let arr = ndarray::Array::random(
51-
shape,
52-
Uniform::new(low, high).unwrap(),
53-
);
50+
let arr = ndarray::Array::random(shape, Uniform::new(low, high).unwrap());
5451
GpuTensor::upload(arr, GpuContext::global())
5552
}
5653

5754
fn random_normal<D: Dimension>(shape: D, mean: f32, std: f32) -> GpuTensor<D> {
58-
let arr = ndarray::Array::random(
59-
shape,
60-
Normal::new(mean, std).unwrap(),
61-
);
55+
let arr = ndarray::Array::random(shape, Normal::new(mean, std).unwrap());
6256
GpuTensor::upload(arr, GpuContext::global())
6357
}
6458

src/initializer/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::backend::Backend;
22
use ndarray::Dimension;
33

4-
pub mod zeros;
5-
pub mod xavier_uniform;
6-
pub mod he_normal;
74
pub mod constant;
5+
pub mod he_normal;
6+
pub mod xavier_uniform;
7+
pub mod zeros;
88

9-
pub use zeros::Zeros;
10-
pub use xavier_uniform::XavierUniform;
11-
pub use he_normal::HeNormal;
129
pub use constant::Constant;
10+
pub use he_normal::HeNormal;
11+
pub use xavier_uniform::XavierUniform;
12+
pub use zeros::Zeros;
1313

1414
pub trait Initializer<B: Backend> {
1515
fn init<D: Dimension>(&self, shape: D) -> B::Tensor<D>;

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
pub mod activation;
22
pub mod backend;
33
pub mod cost;
4+
pub mod initializer;
45
pub mod layer;
56
pub mod metric;
67
pub mod optimizer;
7-
pub mod initializer;
88
pub mod serialization;
99
pub mod train;
1010

1111
pub use activation::{ReLU, Sigmoid, Softmax, Tanh};
1212
pub use backend::DefaultBackend;
1313
pub use cost::{BinaryCrossEntropy, CrossEntropy, MSE};
14+
pub use initializer::{Constant, HeNormal, Initializer, XavierUniform, Zeros};
1415
pub use layer::DenseLayer;
1516
pub use metric::classification::accuracy;
1617
pub use optimizer::{SGD, SGDMomentum};
1718
pub use train::{PrintCallback, TrainCallback, TrainOptions};
18-
pub use initializer::{Constant, HeNormal, Initializer, XavierUniform, Zeros};
1919

2020
use crate::backend::Backend;
2121
use crate::layer::Layer;

tests/integration.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use common::assert_close;
66
use meuron::activation::{ReLU, Softmax};
77
use meuron::backend::{Backend, CPUBackend, GPUBackend, unary_ops};
88
use meuron::cost::{Cost, CrossEntropy};
9+
use meuron::initializer::{HeNormal, XavierUniform, Zeros};
910
use meuron::layer::{DenseLayer, Layer};
1011
use meuron::optimizer::{SGD, SGDMomentum};
1112
use meuron::{Layers, NetworkType, NeuralNetwork};
@@ -65,11 +66,11 @@ fn dense_forward_parity() {
6566
let b = arr1(&[0.1_f32, -0.2, 0.3]);
6667
let x = arr2(&[[1.0_f32, 0.5, -0.3, 0.2], [0.0, 1.0, 0.0, -1.0]]);
6768

68-
let mut cpu_l = DenseLayer::<ReLU, CPUBackend>::new(4, 3, ReLU);
69+
let mut cpu_l = DenseLayer::<ReLU, CPUBackend>::new(4, 3, ReLU, HeNormal, Zeros);
6970
CPUBackend::assign(&mut cpu_l.weights, CPUBackend::from_array(w.clone()));
7071
CPUBackend::assign(&mut cpu_l.biases, CPUBackend::from_array(b.clone()));
7172

72-
let mut gpu_l = DenseLayer::<ReLU, GPUBackend>::new(4, 3, ReLU);
73+
let mut gpu_l = DenseLayer::<ReLU, GPUBackend>::new(4, 3, ReLU, HeNormal, Zeros);
7374
GPUBackend::assign(&mut gpu_l.weights, GPUBackend::from_array(w));
7475
GPUBackend::assign(&mut gpu_l.biases, GPUBackend::from_array(b));
7576

@@ -91,11 +92,11 @@ fn dense_backward_parity() {
9192
let x = arr2(&[[1.0_f32, 0.5, -0.3], [0.0, 1.0, 0.0]]);
9293
let g = arr2(&[[0.3_f32, -0.1], [-0.2, 0.4]]);
9394

94-
let mut cpu_l = DenseLayer::<ReLU, CPUBackend>::new(3, 2, ReLU);
95+
let mut cpu_l = DenseLayer::<ReLU, CPUBackend>::new(3, 2, ReLU, HeNormal, Zeros);
9596
CPUBackend::assign(&mut cpu_l.weights, CPUBackend::from_array(w.clone()));
9697
CPUBackend::assign(&mut cpu_l.biases, CPUBackend::from_array(b.clone()));
9798

98-
let mut gpu_l = DenseLayer::<ReLU, GPUBackend>::new(3, 2, ReLU);
99+
let mut gpu_l = DenseLayer::<ReLU, GPUBackend>::new(3, 2, ReLU, HeNormal, Zeros);
99100
GPUBackend::assign(&mut gpu_l.weights, GPUBackend::from_array(w));
100101
GPUBackend::assign(&mut gpu_l.biases, GPUBackend::from_array(b));
101102

@@ -158,15 +159,15 @@ type TwoLayerGpu = NeuralNetwork<
158159
fn cpu_gpu_pair() -> (TwoLayerCpu, TwoLayerGpu) {
159160
let cpu = NeuralNetwork::new(
160161
Layers![
161-
DenseLayer::<ReLU, CPUBackend>::new(4, 5, ReLU),
162-
DenseLayer::<Softmax, CPUBackend>::new(5, 3, Softmax)
162+
DenseLayer::<ReLU, CPUBackend>::new(4, 5, ReLU, HeNormal, Zeros),
163+
DenseLayer::<Softmax, CPUBackend>::new(5, 3, Softmax, XavierUniform, Zeros)
163164
],
164165
CrossEntropy,
165166
);
166167
let mut gpu = NeuralNetwork::new(
167168
Layers![
168-
DenseLayer::<ReLU, GPUBackend>::new(4, 5, ReLU),
169-
DenseLayer::<Softmax, GPUBackend>::new(5, 3, Softmax)
169+
DenseLayer::<ReLU, GPUBackend>::new(4, 5, ReLU, HeNormal, Zeros),
170+
DenseLayer::<Softmax, GPUBackend>::new(5, 3, Softmax, XavierUniform, Zeros)
170171
],
171172
CrossEntropy,
172173
);

0 commit comments

Comments
 (0)