Skip to content

Commit

Permalink
Merge branch 'main' into smarter-boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIsCoding authored Nov 15, 2024
2 parents ef6744f + d9fbe83 commit 06a4274
Show file tree
Hide file tree
Showing 15 changed files with 626 additions and 60 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
strategy:
matrix:
rust: [stable]
python-version: [3.9, "3.10", "3.11", "3.12"]
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
platform: [
{ os: "macOS-13", python-architecture: "x64", rust-target: "x86_64-apple-darwin" },
{ os: "macOS-14", python-architecture: "arm64", rust-target: "aarch64-apple-darwin" },
Expand All @@ -73,7 +73,7 @@ jobs:
msrv: "MSRV"
# Test future versions of Rust and Python
- rust: beta
python-version: "3.13-dev"
python-version: "3.13" # upgrade to 3.14-dev when the release candidate is available
platform: { os: "ubuntu-latest", python-architecture: "x64", rust-target: "x86_64-unknown-linux-gnu" }
msrv: "Beta"
# Exclude python 3.9 on arm64 until actions/setup-python#808 is resolved
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9, "3.10", "3.11", "3.12"]
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.17.0
python -m pip install cibuildwheel==2.21.3
- name: Build wheels
run: |
python -m cibuildwheel --output-dir wheelhouse
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
platforms: all
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.17.0
python -m pip install cibuildwheel==2.21.3
- name: Build wheels
run: |
python -m cibuildwheel --output-dir wheelhouse
Expand Down Expand Up @@ -143,7 +143,7 @@ jobs:
platforms: all
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.17.0
python -m pip install cibuildwheel==2.21.3
- name: Build wheels
run: |
python -m cibuildwheel --output-dir wheelhouse
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
platforms: all
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.17.0
python -m pip install cibuildwheel==2.21.3
- name: Build wheels
run: |
python -m cibuildwheel --output-dir wheelhouse
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
platforms: all
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.17.0
python -m pip install cibuildwheel==2.21.3
- name: Build wheels
run: |
python -m cibuildwheel --output-dir wheelhouse
Expand Down Expand Up @@ -253,7 +253,7 @@ jobs:
run: rustup default stable-i686-pc-windows-msvc
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel==2.17.0
python -m pip install cibuildwheel==2.21.3
- name: Build wheels
run: |
python -m cibuildwheel --output-dir wheelhouse
Expand Down
56 changes: 9 additions & 47 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ features = ["abi3-py39", "extension-module", "hashbrown", "num-bigint", "num-com

[dependencies.sprs]
version = "^0.11"
default-features = false
features = ["multi_thread"]

[profile.release]
Expand Down
3 changes: 1 addition & 2 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
decorator==4.4.2
pillow<10.0.0;python_version<'3.13'
pillow>=10.1
lxml==5.1.1
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

def install_rustworkx(session):
session.install(*deps)
session.install(".", "-c", "constraints.txt")
session.install(".[all]", "-c", "constraints.txt")

# We define a common base such that -e test triggers a test with the current
# Python version of the interpreter and -e test_with_version launches
Expand Down
14 changes: 14 additions & 0 deletions releasenotes/notes/karate-club-35708b3838689a0b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
features:
- |
Added a new function, :func:`~rustworkx.generators.karate_club_graph` that
returns Zachary's Karate Club graph, commonly found in social network examples.
.. jupyter-execute::
import rustworkx.generators
from rustworkx.visualization import mpl_draw
graph = rustworkx.generators.karate_club_graph()
layout = rustworkx.circular_layout(graph)
mpl_draw(graph, pos=layout)
126 changes: 126 additions & 0 deletions rustworkx-core/src/generators/karate_club.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

use std::hash::Hash;

use petgraph::data::{Build, Create};
use petgraph::visit::{Data, NodeIndexable};

/// Generates Zachary's Karate Club graph.
///
/// Zachary's Karate Club graph is a well-known social network that represents
/// the relations between 34 members of a karate club.
/// Arguments:
///
/// * `default_node_weight` - A callable that will receive a boolean, indicating
/// if a node is part of Mr Hi's faction (True) or the Officer's faction (false).
/// It shoudl return the node weight according to the desired type.
/// * `default_edge_weight` - A callable that will receive the integer representing
/// the strenght of the relation between two nodes. It should return the edge
/// weight according to the desired type.
///
pub fn karate_club_graph<G, T, F, H, M>(mut default_node_weight: F, mut default_edge_weight: H) -> G
where
G: Build + Create + Data<NodeWeight = T, EdgeWeight = M> + NodeIndexable,
F: FnMut(bool) -> T,
H: FnMut(usize) -> M,
G::NodeId: Eq + Hash,
{
const N: usize = 34;
const M: usize = 78;
let mr_hi_members: [u8; 17] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 16, 17, 19, 21];
let membership: std::collections::HashSet<u8> = mr_hi_members.into_iter().collect();

let adjacency_list: Vec<Vec<(usize, usize)>> = vec![
vec![],
vec![(0, 4)],
vec![(0, 5), (1, 6)],
vec![(0, 3), (1, 3), (2, 3)],
vec![(0, 3)],
vec![(0, 3)],
vec![(0, 3), (4, 2), (5, 5)],
vec![(0, 2), (1, 4), (2, 4), (3, 3)],
vec![(0, 2), (2, 5)],
vec![(2, 1)],
vec![(0, 2), (4, 3), (5, 3)],
vec![(0, 3)],
vec![(0, 1), (3, 3)],
vec![(0, 3), (1, 5), (2, 3), (3, 3)],
vec![],
vec![],
vec![(5, 3), (6, 3)],
vec![(0, 2), (1, 1)],
vec![],
vec![(0, 2), (1, 2)],
vec![],
vec![(0, 2), (1, 2)],
vec![],
vec![],
vec![],
vec![(23, 5), (24, 2)],
vec![],
vec![(2, 2), (23, 4), (24, 3)],
vec![(2, 2)],
vec![(23, 3), (26, 4)],
vec![(1, 2), (8, 3)],
vec![(0, 2), (24, 2), (25, 7), (28, 2)],
vec![
(2, 2),
(8, 3),
(14, 3),
(15, 3),
(18, 1),
(20, 3),
(22, 2),
(23, 5),
(29, 4),
(30, 3),
(31, 4),
],
vec![
(8, 4),
(9, 2),
(13, 3),
(14, 2),
(15, 4),
(18, 2),
(19, 1),
(20, 1),
(23, 4),
(26, 2),
(27, 4),
(28, 2),
(29, 2),
(30, 3),
(31, 4),
(32, 5),
(22, 3),
],
];

let mut graph = G::with_capacity(N, M);

let mut node_indices = Vec::with_capacity(N);
for (row, neighbors) in adjacency_list.into_iter().enumerate() {
let node_id = graph.add_node(default_node_weight(membership.contains(&(row as u8))));
node_indices.push(node_id);

for (neighbor, weight) in neighbors.into_iter() {
graph.add_edge(
node_indices[neighbor],
node_indices[row],
default_edge_weight(weight),
);
}
}
graph
}
Loading

0 comments on commit 06a4274

Please sign in to comment.