-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move complete_graph generator to rustworkx-core #772
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For historical reasons we have both the mesh_graph
and complete_graph
generators. complete_graph
is the name found in most libraries and it aliases to the implementation we had first. We need to keep this in mind when porting. it is okay to call the implementation from rustworkx-core
we just need to keep the functions being aliases of each other.
Pull Request Test Coverage Report for Build 3915862605
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some comments about aliasing mesh_graph
and directed_mesh_graph
to avoid code duplication. After the aliases are there I think it should be good to go
src/generators.rs
Outdated
if weights.is_none() && num_nodes.is_none() { | ||
return Err(PyIndexError::new_err( | ||
"num_nodes and weights list not specified", | ||
)); | ||
} | ||
let node_len = get_num_nodes(&num_nodes, &weights); | ||
if node_len == 0 { | ||
return Ok(graph::PyGraph { | ||
graph: StablePyGraph::<Undirected>::default(), | ||
node_removed: false, | ||
multigraph, | ||
attrs: py.None(), | ||
}); | ||
} | ||
let num_edges = (node_len * (node_len - 1)) / 2; | ||
let mut graph = StablePyGraph::<Undirected>::with_capacity(node_len, num_edges); | ||
match weights { | ||
Some(weights) => { | ||
for weight in weights { | ||
graph.add_node(weight); | ||
let default_fn = || py.None(); | ||
let graph: StablePyGraph<Undirected> = | ||
match core_generators::complete_graph(num_nodes, weights, default_fn, default_fn) { | ||
Ok(graph) => graph, | ||
Err(_) => { | ||
return Err(PyIndexError::new_err( | ||
"num_nodes and weights list not specified", | ||
)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace this with complete_graph(py, num_nodes, weights, multigraph)
to avoid duplicate code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Got it. It's on the way...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in af75626.
if weights.is_none() && num_nodes.is_none() { | ||
return Err(PyIndexError::new_err( | ||
"num_nodes and weights list not specified", | ||
)); | ||
} | ||
let node_len = get_num_nodes(&num_nodes, &weights); | ||
if node_len == 0 { | ||
return Ok(digraph::PyDiGraph { | ||
graph: StablePyGraph::<Directed>::default(), | ||
node_removed: false, | ||
check_cycle: false, | ||
cycle_state: algo::DfsSpace::default(), | ||
multigraph, | ||
attrs: py.None(), | ||
}); | ||
} | ||
let num_edges = node_len * (node_len - 1); | ||
let mut graph = StablePyGraph::<Directed>::with_capacity(node_len, num_edges); | ||
match weights { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same apllies here, I'd call directed_mesh_graph(py, num_nodes, weights, multigraph)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in af75626.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
This PR migrates the complete_graph generator to rustworkx-core. It's based on #758.