Skip to content

Commit

Permalink
Fix clippy (#1217)
Browse files Browse the repository at this point in the history
Currently CI is broken because Clippy introduced new lints in the 1.79 update. This PR fixes that
  • Loading branch information
IvanIsCoding authored Jun 18, 2024
1 parent 70b7126 commit cdb2b2f
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion rustworkx-core/src/connectivity/biconnected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use petgraph::{

use crate::traversal::{depth_first_search, DfsEvent};

const NULL: usize = std::usize::MAX;
const NULL: usize = usize::MAX;

type Edge<G> = (<G as GraphBase>::NodeId, <G as GraphBase>::NodeId);

Expand Down
2 changes: 1 addition & 1 deletion rustworkx-core/src/connectivity/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
None => graph.node_identifiers().collect(),
};

let mut parent = vec![std::usize::MAX; graph.node_bound()];
let mut parent = vec![usize::MAX; graph.node_bound()];
let mut back_edges: HashMap<G::NodeId, Vec<G::NodeId>> = HashMap::new();

// depth-first-index (DFI) ordered nodes.
Expand Down
6 changes: 3 additions & 3 deletions rustworkx-core/src/generators/random_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where
}

if probability > 0.0 {
if (probability - 1.0).abs() < std::f64::EPSILON {
if (probability - 1.0).abs() < f64::EPSILON {
for u in 0..num_nodes {
let start_node = if directed { 0 } else { u + 1 };
for v in start_node..num_nodes {
Expand Down Expand Up @@ -433,7 +433,7 @@ fn symmetric_array<T: std::cmp::PartialEq>(mat: &ArrayView2<T>) -> bool {

#[inline]
fn pnorm(x: f64, p: f64) -> f64 {
if p == 1.0 || p == std::f64::INFINITY {
if p == 1.0 || p == f64::INFINITY {
x.abs()
} else if p == 2.0 {
x * x
Expand All @@ -445,7 +445,7 @@ fn pnorm(x: f64, p: f64) -> f64 {
fn distance(x: &[f64], y: &[f64], p: f64) -> f64 {
let it = x.iter().zip(y.iter()).map(|(xi, yi)| pnorm(xi - yi, p));

if p == std::f64::INFINITY {
if p == f64::INFINITY {
it.fold(-1.0, |max, x| if x > max { x } else { max })
} else {
it.sum()
Expand Down
2 changes: 1 addition & 1 deletion rustworkx-core/src/planar/lr_planar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ where
(Some(l_low), Some(r_low)) => lr_state.lowpt[l_low].min(lr_state.lowpt[r_low]),
(Some(l_low), None) => lr_state.lowpt[l_low],
(None, Some(r_low)) => lr_state.lowpt[r_low],
(None, None) => std::usize::MAX,
(None, None) => usize::MAX,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rustworkx-core/src/steiner_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ where
distance.swap_remove(&dummy);

// ``partition[u]`` holds the terminal node closest to node ``u``.
let mut partition: Vec<usize> = vec![std::usize::MAX; graph.node_bound()];
let mut partition: Vec<usize> = vec![usize::MAX; graph.node_bound()];
for (u, path) in paths.iter() {
let u = NodeIndexable::to_index(&in_graph, reverse_node_map[u]);
partition[u] = NodeIndexable::to_index(&in_graph, reverse_node_map[&path[1]]);
Expand Down
2 changes: 1 addition & 1 deletion src/connectivity/johnson_simple_cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl SimpleCycleIter {
closed: HashSet::new(),
block: HashMap::new(),
stack: Vec::new(),
start_node: NodeIndex::new(std::u32::MAX as usize),
start_node: NodeIndex::new(u32::MAX as usize),
node_map: HashMap::new(),
reverse_node_map: HashMap::new(),
subgraph: StableDiGraph::new(),
Expand Down
2 changes: 1 addition & 1 deletion src/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ macro_rules! custom_vec_iter_impl {
Err(PyIndexError::new_err(format!("Invalid index, {}", idx)))
} else if idx < 0 {
let len = self.$data.len();
Ok(self.$data[len - idx.abs() as usize].clone().into_py(py))
Ok(self.$data[len - idx.unsigned_abs()].clone().into_py(py))
} else {
Ok(self.$data[idx as usize].clone().into_py(py))
}
Expand Down
6 changes: 3 additions & 3 deletions src/layout/spring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl AdaptiveCoolingScheme {
AdaptiveCoolingScheme {
_step: step,
_tau: 0.9,
_cost: std::f64::INFINITY,
_cost: f64::INFINITY,
_progress: 0,
}
}
Expand Down Expand Up @@ -184,7 +184,7 @@ pub fn rescale(pos: &mut [Point], scale: Nt, indices: Vec<usize>) {
mu[1] /= n as Nt;

// substract mean and find max coordinate for all axes
let mut lim = std::f64::NEG_INFINITY;
let mut lim = f64::NEG_INFINITY;
for n in indices {
let [px, py] = pos.get_mut(n).unwrap();
*px -= mu[0];
Expand Down Expand Up @@ -232,7 +232,7 @@ where
Fr: Force,
C: CoolingScheme,
{
let mut step = cs.update_step(std::f64::INFINITY);
let mut step = cs.update_step(f64::INFINITY);

for _ in 0..num_iter {
let mut energy = 0.0;
Expand Down
4 changes: 2 additions & 2 deletions src/random_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub fn undirected_sbm_random_graph<'p>(

#[inline]
fn pnorm(x: f64, p: f64) -> f64 {
if p == 1.0 || p == std::f64::INFINITY {
if p == 1.0 || p == f64::INFINITY {
x.abs()
} else if p == 2.0 {
x * x
Expand All @@ -399,7 +399,7 @@ fn pnorm(x: f64, p: f64) -> f64 {
fn distance(x: &[f64], y: &[f64], p: f64) -> f64 {
let it = x.iter().zip(y.iter()).map(|(xi, yi)| pnorm(xi - yi, p));

if p == std::f64::INFINITY {
if p == f64::INFINITY {
it.fold(-1.0, |max, x| if x > max { x } else { max })
} else {
it.sum()
Expand Down
2 changes: 1 addition & 1 deletion src/shortest_path/floyd_warshall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn floyd_warshall_numpy<Ty: EdgeType>(
) -> PyResult<(Array2<f64>, Option<Array2<usize>>)> {
let n = graph.node_count();
// Allocate empty matrix
let mut mat = Array2::<f64>::from_elem((n, n), std::f64::INFINITY);
let mut mat = Array2::<f64>::from_elem((n, n), f64::INFINITY);
let mut next = if generate_successors {
let mut next = Array2::<usize>::from_elem((n, n), 0);

Expand Down
12 changes: 6 additions & 6 deletions src/shortest_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,19 +1476,19 @@ pub fn digraph_unweighted_average_shortest_path_length(
) -> f64 {
let n = graph.node_count();
if n <= 1 {
return std::f64::NAN;
return f64::NAN;
}

let (sum, conn_pairs) =
average_length::compute_distance_sum(&graph.graph, parallel_threshold, as_undirected);

let tot_pairs = n * (n - 1);
if disconnected && conn_pairs == 0 {
return std::f64::NAN;
return f64::NAN;
}

if !disconnected && conn_pairs < tot_pairs {
return std::f64::INFINITY;
return f64::INFINITY;
}

(sum as f64) / (conn_pairs as f64)
Expand Down Expand Up @@ -1539,19 +1539,19 @@ pub fn graph_unweighted_average_shortest_path_length(
) -> f64 {
let n = graph.node_count();
if n <= 1 {
return std::f64::NAN;
return f64::NAN;
}

let (sum, conn_pairs) =
average_length::compute_distance_sum(&graph.graph, parallel_threshold, true);

let tot_pairs = n * (n - 1);
if disconnected && conn_pairs == 0 {
return std::f64::NAN;
return f64::NAN;
}

if !disconnected && conn_pairs < tot_pairs {
return std::f64::INFINITY;
return f64::INFINITY;
}

(sum as f64) / (conn_pairs as f64)
Expand Down

0 comments on commit cdb2b2f

Please sign in to comment.