Skip to content

Commit

Permalink
Running cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpryce committed Jan 8, 2025
1 parent 74a3f12 commit 2eeda07
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 22 deletions.
3 changes: 1 addition & 2 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
fn_args_layout = "vertical"
empty_item_single_line = false
fn_params_layout = "vertical"

3 changes: 1 addition & 2 deletions packages/network_partitions/src/clustering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ impl Clustering {
&self,
node: usize,
) -> Result<usize, CoreError> {
self
.node_to_cluster_mapping
self.node_to_cluster_mapping
.get_or_err(node, CoreError::ClusterIndexingError)
}

Expand Down
4 changes: 3 additions & 1 deletion packages/network_partitions/src/leiden/leiden_clustering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ fn initial_clustering_for_induced(
) -> Clustering {
// Create an initial clustering for the induced network based on the non-refined clustering
let mut clusters_induced_network: Vec<usize> = Vec::with_capacity(num_nodes);
for (num_nodes_per_induced_cluster_index, repetitions) in num_nodes_per_cluster_induced_network.iter().enumerate() {
for (num_nodes_per_induced_cluster_index, repetitions) in
num_nodes_per_cluster_induced_network.iter().enumerate()
{
// fill num_nodes_per_induced_cluster_index into positions from clusters_induced_network_index to clusters_induced_network_index + num_nodes_per_cluster_reduced_network[num_nodes_per_induced_cluster_index]
clusters_induced_network
.extend(iter::repeat(num_nodes_per_induced_cluster_index).take(*repetitions));
Expand Down
3 changes: 1 addition & 2 deletions packages/network_partitions/src/leiden/subnetwork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ fn node_can_move(
) -> bool {
let connectivity_threshold: f64 =
cluster_weights[node] * (total_node_weight - cluster_weights[node]) * adjusted_resolution;
singleton_clusters[node]
&& external_edge_weight_per_cluster[node] >= connectivity_threshold
singleton_clusters[node] && external_edge_weight_per_cluster[node] >= connectivity_threshold
}

fn node_reset(
Expand Down
12 changes: 7 additions & 5 deletions packages/network_partitions/src/network/compact_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ impl CompactNetwork {

pub fn total_edge_weight_per_node(&self) -> Vec<f64> {
// when using modularity, this should return the exact same as node_weights.
self
.nodes
self.nodes
.iter()
.map(|(_, node_id)| {
self.neighbors_for(*node_id)
Expand Down Expand Up @@ -279,7 +278,11 @@ impl CompactNetwork {
let mut cluster_nodes: Vec<CompactNode> = Vec::with_capacity(clustering.next_cluster_id());
let mut cluster_neighbors: Vec<CompactNeighbor> = Vec::new();

for (cluster, cluster_weight) in cluster_weights.iter().take(clustering.next_cluster_id()).enumerate() {
for (cluster, cluster_weight) in cluster_weights
.iter()
.take(clustering.next_cluster_id())
.enumerate()
{
cluster_nodes.push((*cluster_weight, cluster_neighbors.len()));
let mut neighbors: Vec<(&usize, &f64)> = cluster_to_cluster_edges
.entry(cluster)
Expand Down Expand Up @@ -317,8 +320,7 @@ impl NetworkDetails for CompactNetwork {
}

fn total_edge_weight(&self) -> f64 {
self
.neighbors
self.neighbors
.iter()
.map(|neighbor| neighbor.1)
.sum::<f64>()
Expand Down
2 changes: 1 addition & 1 deletion packages/network_partitions/src/network/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Identifier<T> {
impl<T> Default for Identifier<T>
where
T: Clone + Hash + Eq,
{
{
fn default() -> Self {
Self::new()
}
Expand Down
9 changes: 3 additions & 6 deletions packages/network_partitions/src/network/labeled_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct LabeledNetworkBuilder<T> {
impl<T> Default for LabeledNetworkBuilder<T>
where
T: Clone + Eq + Hash + PartialEq + std::cmp::PartialEq,
{
{
fn default() -> Self {
Self::new()
}
Expand Down Expand Up @@ -117,11 +117,8 @@ where
let mut total_self_links_edge_weight: f64 = 0_f64;
for node_id in 0..id_to_labels.len() {
let mut node_weight: f64 = 0_f64; // we are going to set the node_weight as the summation of edge weights regardless of whether we're using modularity or CPM, but if we are using CPM we won't bother to use it.
let mut node_neighbors: Vec<(&CompactNodeId, &f64)> = node_to_neighbors
.get(&node_id)
.unwrap()
.iter()
.collect();
let mut node_neighbors: Vec<(&CompactNodeId, &f64)> =
node_to_neighbors.get(&node_id).unwrap().iter().collect();
let neighbor_start: usize = neighbors.len();
node_neighbors.sort_by(|a, b| a.0.cmp(b.0));
for (neighbor_id, edge_weight) in node_neighbors {
Expand Down
5 changes: 4 additions & 1 deletion packages/pyo3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ fn modularity(
/// graspologic_native currently supports global network partitioning via the Leiden University
/// algorithm described by https://arxiv.org/abs/1810.08473
#[pymodule]
fn graspologic_native(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> {
fn graspologic_native(
py: Python<'_>,
module: &Bound<'_, PyModule>,
) -> PyResult<()> {
module.add_class::<HierarchicalCluster>()?;
module.add_wrapped(wrap_pyfunction!(leiden))?;
module.add_wrapped(wrap_pyfunction!(hierarchical_leiden))?;
Expand Down
2 changes: 0 additions & 2 deletions packages/pyo3/src/mediator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub fn leiden(
seed: Option<u64>,
trials: u64,
) -> Result<(f64, HashMap<String, usize>), PyLeidenError> {

let mut builder: LabeledNetworkBuilder<String> = LabeledNetworkBuilder::new();
let labeled_network: LabeledNetwork<String> = builder.build(edges.into_iter(), use_modularity);

Expand Down Expand Up @@ -102,7 +101,6 @@ pub fn hierarchical_leiden(
max_cluster_size: u32,
seed: Option<u64>,
) -> Result<Vec<HierarchicalCluster>, PyLeidenError> {

let mut builder: LabeledNetworkBuilder<String> = LabeledNetworkBuilder::new();
let labeled_network: LabeledNetwork<String> = builder.build(edges.into_iter(), use_modularity);

Expand Down
242 changes: 242 additions & 0 deletions packages/pyo3/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2eeda07

Please sign in to comment.