cargo clippy

This commit is contained in:
lluni 2023-02-01 16:10:56 +01:00
parent 2f3745a31c
commit a8270914e0
Signed by: lluni
GPG key ID: ACEEB468BC325D35
5 changed files with 15 additions and 15 deletions

View file

@ -96,7 +96,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.draw_series(LineSeries::new(data1, &RED))
.unwrap()
.label("true values")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 1, y)], &RED));
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 1, y)], RED));
// add the second plot
let data2: Vec<(f64, f64)> = x_test
@ -108,7 +108,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.draw_series(LineSeries::new(data2, &BLUE))
.unwrap()
.label("predicted values")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 1, y)], &BLUE));
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 1, y)], BLUE));
Ok(())
}

View file

@ -55,6 +55,6 @@ fn main() {
let mut prediction = y_test.get(i).unwrap().to_owned();
// comment the following line to see the exact predictions
prediction.map_mut(|x| *x = x.round());
print!("prediction: {}\n", prediction);
println!("prediction: {prediction}");
}
}

View file

@ -9,12 +9,12 @@ pub enum Type {
LeakyRelu,
}
pub fn parse_type(
t: Type,
) -> (
type ActFuncTuple = (
fn(&Array1<f64>) -> Array1<f64>,
fn(&Array1<f64>) -> Array1<f64>,
) {
);
pub fn parse_type(t: Type) -> ActFuncTuple {
match t {
Type::Identity => (identity, identity_prime),
Type::Logistic => (logistic, logistic_prime),
@ -67,7 +67,7 @@ pub fn tanh(matrix: &Array1<f64>) -> Array1<f64> {
pub fn tanh_prime(matrix: &Array1<f64>) -> Array1<f64> {
let mut result = matrix.clone();
for x in result.iter_mut() {
*x = 1.0 as f64 - (*x).tanh().pow(2);
*x = 1.0 - (*x).tanh().pow(2);
}
result
}

View file

@ -5,12 +5,12 @@ pub enum Type {
MAE,
}
pub fn parse_type(
t: Type,
) -> (
type LossFuncTuple = (
fn(ArrayView1<f64>, ArrayView1<f64>) -> f64,
fn(ArrayView1<f64>, ArrayView1<f64>) -> Array1<f64>,
) {
);
pub fn parse_type(t: Type) -> LossFuncTuple {
match t {
Type::MSE => (mse, mse_prime),
Type::MAE => (mae, mae_prime),

View file

@ -26,12 +26,12 @@ impl Network {
}
pub fn predict(&mut self, inputs: Vec<Array1<f64>>) -> Vec<Array1<f64>> {
assert!(inputs.len() > 0);
assert!(!inputs.is_empty());
let mut result = vec![];
for input in inputs.iter() {
let mut output = Array1::default(inputs[0].raw_dim());
output.assign(&input);
output.assign(input);
for layer in &mut self.layers {
output = layer.forward_pass(output.view());
}
@ -49,7 +49,7 @@ impl Network {
learning_rate: f64,
trivial_optimize: bool,
) {
assert!(x_train.len() > 0);
assert!(!x_train.is_empty());
assert!(x_train.len() == y_train.len());
let num_samples = x_train.len();