Skip to content

Commit 083bae6

Browse files
committed
Fix clippy issues.
1 parent e613152 commit 083bae6

File tree

17 files changed

+44
-47
lines changed

17 files changed

+44
-47
lines changed

Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@ exclude = [
1414
"docs/*",
1515
]
1616

17-
[lib]
18-
name = "ffsvm"
19-
path = "src/lib.rs"
20-
crate-type = ["rlib"]
21-
2217
[dependencies]
2318
simd_aligned = "0.6.1"
2419
#simd_aligned = { path = "../simd_aligned" }
2520

2621
[dev-dependencies]
2722
rand = "0.8.5"
2823

29-
[profile.release]
30-
opt-level = 3
31-
lto = true

benches/svm_dense.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod svm_dense {
2424
problem_mut[i as usize] = i as f32;
2525
}
2626

27-
move || (&svm).predict_value(&mut problem).expect("This should work")
27+
move || svm.predict_value(&mut problem).expect("This should work")
2828
}
2929

3030
// RBF

benches/svm_sparse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod svm_sparse {
2424
problem_mut[i as usize] = i as f32;
2525
}
2626

27-
move || (&svm).predict_value(&mut problem).expect("This should work")
27+
move || svm.predict_value(&mut problem).expect("This should work")
2828
}
2929

3030
// RBF

src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ pub enum Error {
5151
// }
5252

5353
impl From<ParseFloatError> for Error {
54-
fn from(_e: ParseFloatError) -> Self { Error::Parsing("ParseFloatError".to_owned()) }
54+
fn from(_e: ParseFloatError) -> Self { Self::Parsing("ParseFloatError".to_owned()) }
5555
}
5656

5757
impl From<ParseIntError> for Error {
58-
fn from(_: ParseIntError) -> Self { Error::Parsing("ParseIntError".to_owned()) }
58+
fn from(_: ParseIntError) -> Self { Self::Parsing("ParseIntError".to_owned()) }
5959
}

src/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'a> TryFrom<&'a str> for ModelFile<'a> {
127127
for line in input.lines() {
128128
let tokens = line.split_whitespace().collect::<Vec<_>>();
129129

130-
match tokens.get(0) {
130+
match tokens.first() {
131131
// Single value headers
132132
//
133133
// svm_type c_svc
@@ -190,7 +190,7 @@ impl<'a> TryFrom<&'a str> for ModelFile<'a> {
190190
let split = x.split(':').collect::<Vec<&str>>();
191191

192192
Some(Attribute {
193-
index: split.get(0)?.parse::<u32>().ok()?,
193+
index: split.first()?.parse::<u32>().ok()?,
194194
value: split.get(1)?.parse::<f32>().ok()?,
195195
})
196196
})

src/sparse.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ impl<T> SparseVector<T>
2121
where
2222
T: Clone + Copy + Default,
2323
{
24-
pub fn new() -> Self { Self { entries: Vec::new() } }
24+
pub const fn new() -> Self { Self { entries: Vec::new() } }
2525

2626
pub fn clear(&mut self) { self.entries.clear(); }
2727

28-
pub fn iter(&self) -> SparseVectorIter<'_, T> { SparseVectorIter { vector: self, index: 0 } }
28+
pub const fn iter(&self) -> SparseVectorIter<'_, T> { SparseVectorIter { vector: self, index: 0 } }
2929
}
3030

3131
/// Basic iterator struct to go over matrix
@@ -41,7 +41,7 @@ where
4141
pub(crate) index: usize,
4242
}
4343

44-
impl<'a, T> Iterator for SparseVectorIter<'a, T>
44+
impl<T> Iterator for SparseVectorIter<'_, T>
4545
where
4646
T: Clone + Copy + Default,
4747
{
@@ -86,10 +86,7 @@ where
8686
fn index_mut(&mut self, index: usize) -> &mut T {
8787
// TODO: Beautify me
8888

89-
let highest_so_far: i32 = match self.entries.last() {
90-
None => -1,
91-
Some(x) => x.index as i32,
92-
};
89+
let highest_so_far: i32 = self.entries.last().map_or(-1, |x| x.index as i32);
9390

9491
if index as i32 <= highest_so_far {
9592
unimplemented!("We still need to implement unsorted insertion. As of today, you need to insert element in strictly ascending order.");
@@ -126,7 +123,7 @@ where
126123
pub fn row(&self, row: usize) -> &SparseVector<T> { &self.vectors[row] }
127124

128125
#[inline]
129-
pub fn row_iter(&self) -> SparseMatrixIter<'_, T> { SparseMatrixIter { matrix: self, index: 0 } }
126+
pub const fn row_iter(&self) -> SparseMatrixIter<'_, T> { SparseMatrixIter { matrix: self, index: 0 } }
130127
}
131128

132129
impl<T> Index<(usize, usize)> for SparseMatrix<T>

src/svm/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use simd_aligned::{
77
/// Represents one class of the SVM model.
88
#[derive(Clone, Debug)]
99
#[doc(hidden)]
10-
pub(crate) struct Class<M32> {
10+
pub struct Class<M32> {
1111
/// The label of this class
1212
pub(crate) label: i32,
1313

src/svm/core/dense.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl DenseSVM {
6060
///
6161
/// If the label was found its index returned in the [`Option`], otherwise `None`
6262
/// is returned.
63-
pub fn class_index_for_label(&self, label: i32) -> Option<usize> {
63+
#[must_use] pub fn class_index_for_label(&self, label: i32) -> Option<usize> {
6464
for (i, class) in self.classes.iter().enumerate() {
6565
if class.label != label {
6666
continue;
@@ -84,7 +84,7 @@ impl DenseSVM {
8484
///
8585
/// If the index was found it is returned in the [`Option`], otherwise `None`
8686
/// is returned.
87-
pub fn class_label_for_index(&self, index: usize) -> Option<i32> {
87+
#[must_use] pub fn class_label_for_index(&self, index: usize) -> Option<i32> {
8888
if index >= self.classes.len() {
8989
None
9090
} else {
@@ -132,10 +132,10 @@ impl DenseSVM {
132132
}
133133

134134
/// Returns number of attributes, reflecting the libSVM model.
135-
pub const fn attributes(&self) -> usize { self.num_attributes }
135+
#[must_use] pub const fn attributes(&self) -> usize { self.num_attributes }
136136

137137
/// Returns number of classes, reflecting the libSVM model.
138-
pub fn classes(&self) -> usize { self.classes.len() }
138+
#[must_use] pub fn classes(&self) -> usize { self.classes.len() }
139139
}
140140

141141
impl Predict<VecSimd<f32x8>> for DenseSVM {
@@ -173,7 +173,7 @@ impl<'a> TryFrom<&'a str> for DenseSVM {
173173
}
174174
}
175175

176-
impl<'a, 'b> TryFrom<&'a ModelFile<'b>> for DenseSVM {
176+
impl<'a> TryFrom<&'a ModelFile<'_>> for DenseSVM {
177177
type Error = Error;
178178

179179
fn try_from(raw_model: &'a ModelFile<'_>) -> Result<Self, Error> {

src/svm/core/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ macro_rules! compute_multiclass_probabilities_impl {
154154
let diff = (-qp[t] + pqp) / q[(t, t)];
155155

156156
probabilities[t] += diff;
157-
pqp = (pqp + diff * (diff * q[(t, t)] + 2.0 * qp[t])) / (1.0 + diff) / (1.0 + diff);
157+
pqp = diff.mul_add(diff.mul_add(q[(t, t)], 2.0 * qp[t]), pqp) / (1.0 + diff) / (1.0 + diff);
158158

159159
for j in 0 .. num_classes {
160-
qp[j] = (qp[j] + diff * q[(t, j)]) / (1.0 + diff);
160+
qp[j] = diff.mul_add(q[(t, j)], qp[j]) / (1.0 + diff);
161161
probabilities[j] /= 1.0 + diff;
162162
}
163163
}

src/svm/core/sparse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Predict<SparseVector<f32>> for SparseSVM {
171171
fn predict_probability(&self, problem: &mut FeatureVector<SparseVector<f32>>) -> Result<(), Error> { predict_probability_impl!(self, problem) }
172172
}
173173

174-
impl<'a, 'b> TryFrom<&'a str> for SparseSVM {
174+
impl<'a> TryFrom<&'a str> for SparseSVM {
175175
type Error = Error;
176176

177177
fn try_from(input: &'a str) -> Result<Self, Error> {

0 commit comments

Comments
 (0)