Skip to content

Commit 4489d22

Browse files
committed
FIX: Cargo check warnings and some clippy lints
Clippy lints cannot be fixed by the packages that import the library reiimplementations directly, this is a known problem. See rust-lang/rust-clippy#3025.
1 parent 5ee7e6b commit 4489d22

8 files changed

+20
-12
lines changed

coders/src/hierarchical_coders.rs

-3
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ impl Encoder<Array3<ImagePrecision>> for MeanScaleHierarchicalEncoder {
161161
let hyperlatents = self.hyperlatent_encoder.forward_pass(&latents);
162162
let latent_parameters = self.hyperlatent_decoder.forward_pass(&hyperlatents);
163163

164-
let latent_length = latents.len();
165-
166164
// If we give in an uneven latent shape, then the latent parameters will
167165
// have even shape and the naive comparison doesn't work
168166
debug_assert_eq!(
@@ -256,7 +254,6 @@ impl Decoder<Array3<ImagePrecision>> for MeanScaleHierarchicalDecoder {
256254
make_even(side_info[4] as usize) as usize,
257255
make_even(side_info[5] as usize) as usize,
258256
);
259-
let latents_len = latents_shape.0 * latents_shape.1 * latents_shape.2;
260257
let mut coder = DefaultAnsCoder::from_compressed(encoded_data.main_info).unwrap();
261258

262259
let mut hyperlatents = Array::zeros(hyperlatents_shape);

ml/src/activation_functions.rs

+2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ pub fn igdn(
8686
}
8787

8888
/// Leaky relu implementation
89+
#[allow(dead_code)]
8990
pub fn leaky_relu<D: Dimension>(data: &Array<ImagePrecision, D>) -> Array<ImagePrecision, D> {
9091
data.mapv(|x| if x > 0. { x } else { 0.01 * x })
9192
}
9293

9394
/// Relu implementation
95+
#[allow(dead_code)]
9496
pub fn relu<D: Dimension>(data: &Array<ImagePrecision, D>) -> Array<ImagePrecision, D> {
9597
data.mapv(|x| if x > 0. { x } else { 0. })
9698
}

ml/src/models.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
//! This module provides the hierarchical models used in the encoding and decoding process.
12
// This file has been automatically generated by Jinja2 via the
2-
// script generate_models.py.
3+
// script ./generate_models.py.
34
// Please do not change this file by hand.
45
use crate::{
56
activation_functions::{GdnLayer, IgdnLayer, ReluLayer},
@@ -69,6 +70,7 @@ pub struct MinnenEncoder {
6970
}
7071

7172
impl CodingModel for MinnenEncoder {
73+
#[allow(clippy::let_and_return)]
7274
fn forward_pass(&self, input: &InternalDataRepresentation) -> InternalDataRepresentation {
7375
let x = input.clone();
7476

@@ -197,6 +199,7 @@ pub struct JohnstonDecoder {
197199
}
198200

199201
impl CodingModel for JohnstonDecoder {
202+
#[allow(clippy::let_and_return)]
200203
fn forward_pass(&self, input: &InternalDataRepresentation) -> InternalDataRepresentation {
201204
let x = input.clone();
202205

@@ -339,6 +342,7 @@ pub struct MinnenHyperEncoder {
339342
}
340343

341344
impl CodingModel for MinnenHyperEncoder {
345+
#[allow(clippy::let_and_return)]
342346
fn forward_pass(&self, input: &InternalDataRepresentation) -> InternalDataRepresentation {
343347
let x = input.clone();
344348

@@ -404,6 +408,7 @@ pub struct JohnstonHyperDecoder {
404408
}
405409

406410
impl CodingModel for JohnstonHyperDecoder {
411+
#[allow(clippy::let_and_return)]
407412
fn forward_pass(&self, input: &InternalDataRepresentation) -> InternalDataRepresentation {
408413
let x = input.clone();
409414

@@ -457,7 +462,9 @@ impl JohnstonHyperDecoder {
457462
}
458463

459464
mod tests {
465+
#[allow(unused_imports)]
460466
use super::*;
467+
#[allow(unused_imports)]
461468
use crate::weight_loader::NpzWeightLoader;
462469

463470
#[test]

ml/src/weight_loader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl WeightLoader for JsonWeightLoader {
7474
let raw_arr = self
7575
.content
7676
.get(param_name)
77-
.ok_or(WeightError::WeightKeyError(param_name.to_string()))?;
77+
.ok_or_else(|| WeightError::WeightKeyError(param_name.to_string()))?;
7878

7979
let raw_value_vector = match raw_arr {
8080
Value::Array(v) => v,
@@ -167,7 +167,7 @@ where
167167
Err(_) => {
168168
let arr_flat: Array1<_> = reader.by_name(param_name)?;
169169
let arr_reshaped =
170-
Array::from_shape_vec(shape, arr_flat.iter().map(|x| *x).collect())?;
170+
Array::from_shape_vec(shape, arr_flat.iter().copied().collect())?;
171171
arr_reshaped
172172
}
173173
})

scripts/generate_models.py

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
import jinja2
33
import os
44
import json

scripts/generate_tests.py

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
import jinja2
33
import numpy as np
44
import itertools

scripts/templates/models_template.rs

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ impl CodingModel for ReluLayer {
6969
}
7070

7171
impl CodingModel for {{m.name}} {
72+
{# Have to allow since the last let might be extraneous due to model generation #}
73+
#[allow(clippy::let_and_return)]
7274
fn forward_pass(&self, input: &InternalDataRepresentation) -> InternalDataRepresentation {
7375
let x = input.clone();
7476
{% for l in m.layers %}
@@ -117,7 +119,9 @@ impl CodingModel for ReluLayer {
117119
{% endfor %}
118120

119121
mod tests {
122+
#[allow(unused_imports)]
120123
use crate::weight_loader::NpzWeightLoader;
124+
#[allow(unused_imports)]
121125
use super::*;
122126

123127
{% for m in models %}

zipnet/src/main.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
//! This crate ties in all the parts of the projects and provides a clean command line interface
22
//! to make encoding/decoding images feasible.
33
4-
use bincode::serialize;
54
use coders::{
65
dummy_coders::DummyCoder,
76
hierarchical_coders::{MeanScaleHierarchicalDecoder, MeanScaleHierarchicalEncoder},
87
statistics::Statistics,
98
Decoder, Encoder,
109
};
10+
use image::io::Reader as ImageReader;
1111
use image::RgbImage;
12-
use image::{io::Reader as ImageReader, DynamicImage};
1312
use ndarray::{Array, Array3};
14-
use ndarray_npy::{read_npy, NpzReader};
13+
use ndarray_npy::read_npy;
1514
use nshare::ToNdarray3;
1615
use quicli::prelude::*;
1716
use std::{
18-
array,
1917
ffi::OsStr,
2018
fs,
2119
io::{Read, Write},

0 commit comments

Comments
 (0)