Run: cargo clippy --fix -Z unstable-options and cargo fmt
This commit is contained in:
@@ -50,8 +50,8 @@ impl<T: RealNumber> BBDTree<T> {
|
||||
}
|
||||
|
||||
let mut tree = BBDTree {
|
||||
nodes: nodes,
|
||||
index: index,
|
||||
nodes,
|
||||
index,
|
||||
root: 0,
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ impl<T: RealNumber> BBDTree<T> {
|
||||
}
|
||||
}
|
||||
|
||||
if !self.nodes[node].lower.is_none() {
|
||||
if self.nodes[node].lower.is_some() {
|
||||
let mut new_candidates = vec![0; k];
|
||||
let mut newk = 0;
|
||||
|
||||
@@ -152,7 +152,7 @@ impl<T: RealNumber> BBDTree<T> {
|
||||
}
|
||||
|
||||
for i in 0..d {
|
||||
sums[closest][i] = sums[closest][i] + self.nodes[node].sum[i];
|
||||
sums[closest][i] += self.nodes[node].sum[i];
|
||||
}
|
||||
|
||||
counts[closest] += self.nodes[node].count;
|
||||
@@ -184,11 +184,11 @@ impl<T: RealNumber> BBDTree<T> {
|
||||
let mut rhs = T::zero();
|
||||
for i in 0..d {
|
||||
let diff = test[i] - best[i];
|
||||
lhs = lhs + diff * diff;
|
||||
lhs += diff * diff;
|
||||
if diff > T::zero() {
|
||||
rhs = rhs + (center[i] + radius[i] - best[i]) * diff;
|
||||
rhs += (center[i] + radius[i] - best[i]) * diff;
|
||||
} else {
|
||||
rhs = rhs + (center[i] - radius[i] - best[i]) * diff;
|
||||
rhs += (center[i] - radius[i] - best[i]) * diff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ impl<T: RealNumber> BBDTree<T> {
|
||||
if end > begin + 1 {
|
||||
let len = end - begin;
|
||||
for i in 0..d {
|
||||
node.sum[i] = node.sum[i] * T::from(len).unwrap();
|
||||
node.sum[i] *= T::from(len).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,9 +261,7 @@ impl<T: RealNumber> BBDTree<T> {
|
||||
let mut i2_good = data.get(self.index[i2], split_index) >= split_cutoff;
|
||||
|
||||
if !i1_good && !i2_good {
|
||||
let temp = self.index[i1];
|
||||
self.index[i1] = self.index[i2];
|
||||
self.index[i2] = temp;
|
||||
self.index.swap(i1, i2);
|
||||
i1_good = true;
|
||||
i2_good = true;
|
||||
}
|
||||
@@ -302,7 +300,7 @@ impl<T: RealNumber> BBDTree<T> {
|
||||
let mut scatter = T::zero();
|
||||
for i in 0..d {
|
||||
let x = (node.sum[i] / T::from(node.count).unwrap()) - center[i];
|
||||
scatter = scatter + x * x;
|
||||
scatter += x * x;
|
||||
}
|
||||
node.cost + T::from(node.count).unwrap() * scatter
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ impl<T, F: RealNumber, D: Distance<T, F>> PartialEq for CoverTree<T, F, D> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,11 +84,11 @@ impl<T: Debug + PartialEq, F: RealNumber, D: Distance<T, F>> CoverTree<T, F, D>
|
||||
scale: 0,
|
||||
};
|
||||
let mut tree = CoverTree {
|
||||
base: base,
|
||||
base,
|
||||
inv_log_base: F::one() / base.ln(),
|
||||
distance: distance,
|
||||
root: root,
|
||||
data: data,
|
||||
distance,
|
||||
root,
|
||||
data,
|
||||
identical_excluded: false,
|
||||
};
|
||||
|
||||
@@ -147,10 +147,11 @@ impl<T: Debug + PartialEq, F: RealNumber, D: Distance<T, F>> CoverTree<T, F, D>
|
||||
*heap.peek()
|
||||
};
|
||||
if d <= (upper_bound + child.max_dist) {
|
||||
if c > 0 && d < upper_bound {
|
||||
if !self.identical_excluded || self.get_data_value(child.idx) != p {
|
||||
heap.add(d);
|
||||
}
|
||||
if c > 0
|
||||
&& d < upper_bound
|
||||
&& (!self.identical_excluded || self.get_data_value(child.idx) != p)
|
||||
{
|
||||
heap.add(d);
|
||||
}
|
||||
|
||||
if !child.children.is_empty() {
|
||||
@@ -234,7 +235,7 @@ impl<T: Debug + PartialEq, F: RealNumber, D: Distance<T, F>> CoverTree<T, F, D>
|
||||
|
||||
fn new_leaf(&self, idx: usize) -> Node<F> {
|
||||
Node {
|
||||
idx: idx,
|
||||
idx,
|
||||
max_dist: F::zero(),
|
||||
parent_dist: F::zero(),
|
||||
children: Vec::new(),
|
||||
@@ -298,7 +299,7 @@ impl<T: Debug + PartialEq, F: RealNumber, D: Distance<T, F>> CoverTree<T, F, D>
|
||||
idx: p,
|
||||
max_dist: F::zero(),
|
||||
parent_dist: F::zero(),
|
||||
children: children,
|
||||
children,
|
||||
scale: 100,
|
||||
}
|
||||
} else {
|
||||
@@ -368,7 +369,7 @@ impl<T: Debug + PartialEq, F: RealNumber, D: Distance<T, F>> CoverTree<T, F, D>
|
||||
idx: p,
|
||||
max_dist: self.max(consumed_set),
|
||||
parent_dist: F::zero(),
|
||||
children: children,
|
||||
children,
|
||||
scale: (top_scale - max_scale),
|
||||
}
|
||||
}
|
||||
@@ -442,7 +443,7 @@ impl<T: Debug + PartialEq, F: RealNumber, D: Distance<T, F>> CoverTree<T, F, D>
|
||||
max = n.dist[n.dist.len() - 1];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
max
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ impl<T, F: RealNumber, D: Distance<T, F>> LinearKNNSearch<T, F, D> {
|
||||
/// * `distance` - distance metric to use for searching. This function should extend [`Distance`](../../../math/distance/index.html) interface.
|
||||
pub fn new(data: Vec<T>, distance: D) -> Result<LinearKNNSearch<T, F, D>, Failed> {
|
||||
Ok(LinearKNNSearch {
|
||||
data: data,
|
||||
distance: distance,
|
||||
data,
|
||||
distance,
|
||||
f: PhantomData,
|
||||
})
|
||||
}
|
||||
@@ -157,7 +157,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(|v| v.0)
|
||||
.collect();
|
||||
found_idxs1.sort();
|
||||
found_idxs1.sort_unstable();
|
||||
|
||||
assert_eq!(vec!(0, 1, 2), found_idxs1);
|
||||
|
||||
@@ -167,7 +167,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(|v| *v.2)
|
||||
.collect();
|
||||
found_idxs1.sort();
|
||||
found_idxs1.sort_unstable();
|
||||
|
||||
assert_eq!(vec!(2, 3, 4, 5, 6, 7, 8), found_idxs1);
|
||||
|
||||
@@ -187,7 +187,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(|v| v.0)
|
||||
.collect();
|
||||
found_idxs2.sort();
|
||||
found_idxs2.sort_unstable();
|
||||
|
||||
assert_eq!(vec!(1, 2, 3), found_idxs2);
|
||||
}
|
||||
|
||||
@@ -66,10 +66,10 @@ impl KNNAlgorithmName {
|
||||
) -> Result<KNNAlgorithm<T, D>, Failed> {
|
||||
match *self {
|
||||
KNNAlgorithmName::LinearSearch => {
|
||||
LinearKNNSearch::new(data, distance).map(|a| KNNAlgorithm::LinearSearch(a))
|
||||
LinearKNNSearch::new(data, distance).map(KNNAlgorithm::LinearSearch)
|
||||
}
|
||||
KNNAlgorithmName::CoverTree => {
|
||||
CoverTree::new(data, distance).map(|a| KNNAlgorithm::CoverTree(a))
|
||||
CoverTree::new(data, distance).map(KNNAlgorithm::CoverTree)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub struct HeapSelection<T: PartialOrd + Debug> {
|
||||
impl<'a, T: PartialOrd + Debug> HeapSelection<T> {
|
||||
pub fn with_capacity(k: usize) -> HeapSelection<T> {
|
||||
HeapSelection {
|
||||
k: k,
|
||||
k,
|
||||
n: 0,
|
||||
sorted: false,
|
||||
heap: Vec::new(),
|
||||
@@ -51,7 +51,7 @@ impl<'a, T: PartialOrd + Debug> HeapSelection<T> {
|
||||
|
||||
pub fn peek(&self) -> &T {
|
||||
if self.sorted {
|
||||
return &self.heap[0];
|
||||
&self.heap[0]
|
||||
} else {
|
||||
&self
|
||||
.heap
|
||||
@@ -62,11 +62,11 @@ impl<'a, T: PartialOrd + Debug> HeapSelection<T> {
|
||||
}
|
||||
|
||||
pub fn peek_mut(&mut self) -> &mut T {
|
||||
return &mut self.heap[0];
|
||||
&mut self.heap[0]
|
||||
}
|
||||
|
||||
pub fn get(self) -> Vec<T> {
|
||||
return self.heap;
|
||||
self.heap
|
||||
}
|
||||
|
||||
fn sift_down(&mut self, k: usize, n: usize) {
|
||||
|
||||
Reference in New Issue
Block a user