Skip to content

Commit 2d85f21

Browse files
Resolved more code smells
1 parent 2b4fc2b commit 2d85f21

File tree

14 files changed

+842
-1074
lines changed

14 files changed

+842
-1074
lines changed

bindings/python/src/auto_generated_bindings.rs

Lines changed: 800 additions & 1029 deletions
Large diffs are not rendered by default.

bindings/python/src/basic_siamese_model_binding.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl TransE {
161161
/// graph: Graph
162162
/// The graph to embed.
163163
fn fit_transform(&self, graph: &Graph) -> PyResult<Vec<Py<PyAny>>> {
164-
Ok(self.inner.fit_transform(graph)?)
164+
self.inner.fit_transform(graph)
165165
}
166166
}
167167

@@ -298,6 +298,6 @@ impl StructuredEmbedding {
298298
/// graph: Graph
299299
/// The graph to embed.
300300
fn fit_transform(&self, graph: &Graph) -> PyResult<Vec<Py<PyAny>>> {
301-
Ok(self.inner.fit_transform(graph)?)
301+
self.inner.fit_transform(graph)
302302
}
303303
}

bindings/python/src/edge_prediction_perceptron.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl EdgePredictionPerceptron {
9090
.collect::<Result<Vec<_>>>())
9191
.transpose()
9292
)?
93-
.unwrap_or_else(|| Vec::new()),
93+
.unwrap_or_else(Vec::new),
9494
pe!(
9595
extract_value_rust_result!(kwargs, "edge_features", Vec<String>)
9696
.map(|names| {
@@ -101,7 +101,7 @@ impl EdgePredictionPerceptron {
101101
})
102102
.transpose()
103103
)?
104-
.unwrap_or_else(|| Vec::new()),
104+
.unwrap_or_else(Vec::new),
105105
cpu_models::Adam::new(
106106
extract_value_rust_result!(kwargs, "learning_rate", f32),
107107
extract_value_rust_result!(kwargs, "first_order_decay_factor", f32),

bindings/python/src/from_pd.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,22 @@ impl Graph {
191191
)
192192
}))
193193
.enumerate()
194-
.map(|x| Ok(x)),
194+
.map(Ok),
195195
)
196196
} else {
197197
Box::new(
198198
nodes_iterator
199199
.zip(node_type_iterator.map(|x| Some(vec![x.unwrap().to_string()])))
200200
.enumerate()
201-
.map(|x| Ok(x)),
201+
.map(Ok),
202202
)
203203
}
204204
} else {
205205
Box::new(
206206
nodes_iterator
207207
.zip(std::iter::repeat(None))
208208
.enumerate()
209-
.map(|x| Ok(x)),
209+
.map(Ok),
210210
)
211211
},
212212
))
@@ -241,7 +241,7 @@ impl Graph {
241241
)
242242
})
243243
.enumerate()
244-
.map(|x| Ok(x)),
244+
.map(Ok),
245245
)
246246
}
247247
(Some(et), None) => {
@@ -252,7 +252,7 @@ impl Graph {
252252
.zip(et_iter)
253253
.map(|((src, dst), edge_type)| (src, dst, Some(edge_type), 1.0))
254254
.enumerate()
255-
.map(|x| Ok(x)),
255+
.map(Ok),
256256
)
257257
}
258258
(None, Some(ew)) => {
@@ -265,15 +265,15 @@ impl Graph {
265265
(src, dst, None, weight.parse::<WeightT>().unwrap())
266266
})
267267
.enumerate()
268-
.map(|x| Ok(x)),
268+
.map(Ok),
269269
)
270270
}
271271
(None, None) => Box::new(
272272
src_iterator
273273
.zip(dst_iterator)
274274
.map(|(src, dst)| (src, dst, None, 1.0))
275275
.enumerate()
276-
.map(|x| Ok(x)),
276+
.map(Ok),
277277
),
278278
};
279279

bindings/python/src/graph_convolution.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,25 @@ impl GraphConvolution {
198198
let gil = Python::acquire_gil();
199199

200200
let node_features = node_features.as_ref(gil.python());
201-
if let Ok(node_features) = <&PyArray2<f32>>::extract(&node_features) {
201+
if let Ok(node_features) = <&PyArray2<f32>>::extract(node_features) {
202202
self._transform::<f32>(support, node_features, path, edge_ids_mask)
203-
} else if let Ok(node_features) = <&PyArray2<f64>>::extract(&node_features) {
203+
} else if let Ok(node_features) = <&PyArray2<f64>>::extract(node_features) {
204204
self._transform::<f64>(support, node_features, path, edge_ids_mask)
205-
} else if let Ok(node_features) = <&PyArray2<u8>>::extract(&node_features) {
205+
} else if let Ok(node_features) = <&PyArray2<u8>>::extract(node_features) {
206206
self._transform::<u8>(support, node_features, path, edge_ids_mask)
207-
} else if let Ok(node_features) = <&PyArray2<u16>>::extract(&node_features) {
207+
} else if let Ok(node_features) = <&PyArray2<u16>>::extract(node_features) {
208208
self._transform::<u16>(support, node_features, path, edge_ids_mask)
209-
} else if let Ok(node_features) = <&PyArray2<u32>>::extract(&node_features) {
209+
} else if let Ok(node_features) = <&PyArray2<u32>>::extract(node_features) {
210210
self._transform::<u32>(support, node_features, path, edge_ids_mask)
211-
} else if let Ok(node_features) = <&PyArray2<u64>>::extract(&node_features) {
211+
} else if let Ok(node_features) = <&PyArray2<u64>>::extract(node_features) {
212212
self._transform::<u64>(support, node_features, path, edge_ids_mask)
213-
} else if let Ok(node_features) = <&PyArray2<i8>>::extract(&node_features) {
213+
} else if let Ok(node_features) = <&PyArray2<i8>>::extract(node_features) {
214214
self._transform::<i8>(support, node_features, path, edge_ids_mask)
215-
} else if let Ok(node_features) = <&PyArray2<i16>>::extract(&node_features) {
215+
} else if let Ok(node_features) = <&PyArray2<i16>>::extract(node_features) {
216216
self._transform::<i16>(support, node_features, path, edge_ids_mask)
217-
} else if let Ok(node_features) = <&PyArray2<i32>>::extract(&node_features) {
217+
} else if let Ok(node_features) = <&PyArray2<i32>>::extract(node_features) {
218218
self._transform::<i32>(support, node_features, path, edge_ids_mask)
219-
} else if let Ok(node_features) = <&PyArray2<i64>>::extract(&node_features) {
219+
} else if let Ok(node_features) = <&PyArray2<i64>>::extract(node_features) {
220220
self._transform::<i64>(support, node_features, path, edge_ids_mask)
221221
} else {
222222
pe!(Err(concat!(

bindings/python/src/hyper_jaccard.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::*;
22
use cpu_models::HyperJaccard as HJ;
33
use hyperloglog_rs::prelude::*;
44
use serde::{Deserialize, Serialize};
5-
use serde_json;
65

76
#[derive(Serialize, Deserialize, Clone)]
87
/// HyperJaccard models.
@@ -73,7 +72,7 @@ impl InnerModel {
7372
(12, 5) => Ok(InnerModel::HJ12_5(HJ::new(number_of_hops)?)), // {python_generated}
7473
(12, 6) => Ok(InnerModel::HJ12_6(HJ::new(number_of_hops)?)), // {python_generated}
7574
_ => {
76-
return Err(format!(
75+
Err(format!(
7776
concat!(
7877
"The HyperJaccard model supports precisions ranging from 4 ",
7978
"to 16 and bits ranging from 4 to 6. ",

bindings/python/src/hyper_sketching.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use hyperloglog_rs::prelude::*;
77
use num_traits::Float;
88
use rayon::prelude::*;
99
use serde::{Deserialize, Serialize};
10-
use serde_json;
1110

1211
fn array_to_numpy_array1d<const N: usize>(array: [f32; N]) -> Result<Py<PyArray1<f32>>> {
1312
let gil = pyo3::Python::acquire_gil();
@@ -3639,7 +3638,7 @@ impl InnerModel {
36393638
dtype,
36403639
)?)), // {python_generated}
36413640
_ => {
3642-
return Err(format!(
3641+
Err(format!(
36433642
concat!(
36443643
"The HyperSketching model supports precisions ranging from 4 ",
36453644
"to 16 and bits ranging from 4 to 6, and hops from 1 to 10. ",
@@ -6115,7 +6114,7 @@ impl InnerModel {
61156114
// as we generally do not care about memory collisions.
61166115
pe!(self.compute_sketching_from_iterator::<I, f32>(
61176116
edge_features_ref,
6118-
&support,
6117+
support,
61196118
edge_iterator
61206119
))?;
61216120

bindings/python/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(adt_const_params)]
22
#![feature(impl_trait_in_assoc_type)]
3-
use numpy::{PyArray, PyArray1, PyArray2, PyArray3, PyArray4};
3+
use numpy::{PyArray, PyArray1, PyArray2, PyArray4};
44
use pyo3::exceptions::{PyAttributeError, PyTypeError, PyValueError};
55
use pyo3::prelude::*;
66
use pyo3::types::PyDict;

bindings/python/src/macros.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ pub fn build_walk_parameters_list<'a>(parameters: &[&'a str]) -> Vec<&'a str> {
109109
"walk_length",
110110
];
111111
default
112-
.into_iter()
113-
.chain(parameters.into_iter())
114-
.map(|x| *x)
112+
.iter()
113+
.chain(parameters).copied()
115114
.collect()
116115
}
117116

@@ -122,7 +121,7 @@ pub fn validate_kwargs(kwargs: &PyDict, columns: &[&str]) -> Result<(), String>
122121
.iter()
123122
.map(|v| v.extract::<String>().unwrap())
124123
.collect();
125-
let columns: HashSet<String> = columns.into_iter().map(|x| x.to_string()).collect();
124+
let columns: HashSet<String> = columns.iter().map(|x| x.to_string()).collect();
126125
if keys.is_subset(&columns) {
127126
return Ok(());
128127
}

bindings/python/src/mmap_numpy_npy/dtype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ impl TryFrom<NPY_TYPES> for Dtype {
8888
}
8989
}
9090

91-
impl Into<NPY_TYPES> for Dtype {
92-
fn into(self) -> NPY_TYPES {
91+
impl From<Dtype> for NPY_TYPES {
92+
fn from(val: Dtype) -> Self {
9393
use NPY_TYPES::*;
94-
match self {
94+
match val {
9595
Dtype::Bool => NPY_BOOL,
9696
Dtype::I8 => NPY_BYTE,
9797
Dtype::U8 => NPY_UBYTE,

0 commit comments

Comments
 (0)