Skip to content

Commit

Permalink
Fixing clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellewell14 committed Feb 26, 2024
1 parent b1e4584 commit fc450d4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/dspsa.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use rand::Rng;

pub fn phi(v: &Vec<f64>) -> Vec<f64> {
pub fn phi(v: &[f64]) -> Vec<f64> {
v.iter().enumerate().map(|(i, value)| {
if i == 0 || value.lt(&0.0) {
0.0
} else if value.gt(&(i as f64)) {
(i as f64) - 0.001
} else {
*value as f64
*value
}
}).collect()
}

pub fn piv(v: &Vec<f64>) -> Vec<f64> {
pub fn piv(v: &[f64]) -> Vec<f64> {
let mut pivec: Vec<f64> = phi(v).iter().map(|el| el.floor() + 0.5).collect();
pivec[0] = 0.0;
pivec
Expand Down
8 changes: 3 additions & 5 deletions src/gen_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,17 @@ pub fn char_to_mutation(e: &char) -> Mutation {
// }

pub fn combine_lists(
seq1: &Vec<Mutation>,
seq2: &Vec<Mutation>,
seq1: &[Mutation],
seq2: &[Mutation],
branchlengths: (f64, f64),
rate_matrix: &na::Matrix4<f64>,
) -> Vec<Mutation> {

let mut out: Vec<Mutation> = Vec::new();

// Probability matrices
let p1 = na::Matrix::exp(&(rate_matrix * branchlengths.0));
let p2 = na::Matrix::exp(&(rate_matrix * branchlengths.1));

out = seq1.iter()
let out: Vec<Mutation> = seq1.iter()
.zip(seq2.iter())
.map(|(b1, b2)| b1.child_log_likelihood(&p1)
.sum(b2.child_log_likelihood(&p2)))
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn main() {

let ak = a / (1.0 + A + k as f64).powf(alpha);

theta = theta.iter().zip(ghat.iter()).map(|(theta, g)| *theta as f64 - ak * g).collect();
theta = theta.iter().zip(ghat.iter()).map(|(theta, g)| *theta - ak * g).collect();

llvec.push(x1);

Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl Tree {
pub fn update_likelihood(&mut self, rate_matrix: &na::Matrix4<f64>) {

if self.changes.is_empty() {
return ()
return
}

let max_depth: usize = *self.changes.keys().max().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/phylo2vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rand::{seq::SliceRandom, thread_rng, Rng};
pub fn phylo2vec_quad(v: Vec<usize>) -> Tree {
let mut tree = Tree::new(v);
let k = tree.tree_vec.len();
let mut not_processed = vec![true].repeat(k);
let mut not_processed = [true].repeat(k);
let mut M = Array2::<usize>::zeros((k, 3));
let mut labels = Array2::<usize>::zeros((k + 1, k + 1));

Expand Down
17 changes: 2 additions & 15 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ impl Tree {
.collect();

for i in &x {
match temp.get(&i) {
Some(_) => temp.remove(&i),
match temp.get(i) {
Some(_) => temp.remove(i),
None => temp.insert(*i),
};
};
Expand Down Expand Up @@ -360,19 +360,6 @@ impl<'a> Iterator for Preorder<'a> {
None => None,
Some(node) => node,
};
if self.next_node.is_some() {
match self.next_node.unwrap().parent {
Some(x) if x == output.unwrap().index => {
},
Some(x) => {
},
None => {

}
}
} else {

}
}
_ => {
panic!("Iterator has found a node with only a right child")
Expand Down

0 comments on commit fc450d4

Please sign in to comment.