Skip to content

Commit

Permalink
Merge pull request #26 from Mathics3/misc-fixes
Browse files Browse the repository at this point in the history
Doc and type corrections
  • Loading branch information
rocky authored Feb 23, 2023
2 parents 2681706 + 7f2e6d5 commit 59fa5e2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
10 changes: 5 additions & 5 deletions pymathics/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def graph_helper(
graph_generator_func: Callable,
options: dict,
can_digraph: bool,
graph_layout: str,
graph_layout: Optional[str],
evaluation,
root: Optional[int] = None,
*args,
Expand Down Expand Up @@ -124,7 +124,7 @@ def graph_helper(


def has_directed_option(options: dict) -> bool:
return options.get("System`DirectedEdges", False).to_python()
return options.get("System`DirectedEdges", False)


def _process_graph_options(g, options: dict) -> None:
Expand Down Expand Up @@ -173,15 +173,15 @@ def _process_graph_options(g, options: dict) -> None:


def _circular_layout(G):
return nx.drawing.circular_layout(G, scale=1.5)
return nx.drawing.circular_layout(G, scale=1)


def _spectral_layout(G):
return nx.drawing.spectral_layout(G, scale=2.0)
return nx.drawing.spectral_layout(G, scale=2)


def _shell_layout(G):
return nx.drawing.shell_layout(G, scale=2.0)
return nx.drawing.shell_layout(G, scale=2)


def _generic_layout(G, warn):
Expand Down
3 changes: 3 additions & 0 deletions pymathics/graph/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

from pymathics.graph.graphsymbols import SymbolDirectedEdge

# There is no user-facing documentation here.
no_doc = True


def _count_edges(counts, edges, sign):
n_directed, n_undirected = counts
Expand Down
17 changes: 13 additions & 4 deletions pymathics/graph/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
class ConnectedComponents(_NetworkXBuiltin):
"""
<url>
:WMA:https://reference.wolfram.com/language/ref/ConnectedComponents.html
</url>
:Strongly connected components:
https://en.wikipedia.org/wiki/Strongly_connected_component</url> (<url>
:NetworkX:
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/\
generated/networkx.algorithms.components.strongly_connected_components.html</url>, <url>
:WMA:https://reference.wolfram.com/language/ref/ConnectedComponents.html</url>)
<dl>
<dt>'ConnectedComponents'[$g$]
Expand Down Expand Up @@ -83,8 +87,13 @@ def eval(
class WeaklyConnectedComponents(_NetworkXBuiltin):
"""
<url>
:WMA:https://reference.wolfram.com/language/ref/WeaklyConnectedComponents.html
</url>
:Weak components:
https://en.wikipedia.org/wiki/Weak_component</url> (<url>
:NetworkX:
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/\
generated/networkx.algorithms.components.weakly_connected_components.html</url>, <url>
:WMA:
https://reference.wolfram.com/language/ref/WeaklyConnectedComponents.html</url>)
<dl>
<dt>'WeaklyConnectedComponents'[$g$]
Expand Down
15 changes: 9 additions & 6 deletions pymathics/graph/curated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import networkx as nx
from typing import Callable, Dict, Optional, Tuple
from mathics.core.evaluation import Evaluation

from pymathics.graph.base import Graph, _NetworkXBuiltin, graph_helper
Expand All @@ -11,8 +12,7 @@
class GraphData(_NetworkXBuiltin):
"""
<url>
:WMA:https://reference.wolfram.com/language/ref/GraphData.html
</url>
:WMA link:https://reference.wolfram.com/language/ref/GraphData.html</url>
<dl>
<dt>'GraphData[$name$]'
Expand All @@ -25,7 +25,9 @@ class GraphData(_NetworkXBuiltin):

summary_text = "create a graph by name"

def eval(self, name, expression, evaluation: Evaluation, options: dict) -> Graph:
def eval(
self, name, expression, evaluation: Evaluation, options: dict
) -> Optional[Graph]:
"GraphData[name_String, OptionsPattern[GraphData]]"
py_name = name.get_string_value()
fn, layout = WL_TO_NETWORKX_FN.get(py_name, (None, None))
Expand All @@ -42,12 +44,13 @@ def eval(self, name, expression, evaluation: Evaluation, options: dict) -> Graph
# if len([p for p in list(parameters) if p.kind in [inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD]]) != 0:
# return
if fn:
g = graph_helper(fn, options, False, evaluation, layout)
g.G.name = py_name
g = graph_helper(fn, options, False, layout, evaluation)
if g is not None:
g.G.name = py_name
return g


WL_TO_NETWORKX_FN = {
WL_TO_NETWORKX_FN: Dict[str, Tuple[Callable, Optional[str]]] = {
"DodecahedralGraph": (nx.dodecahedral_graph, None),
"DiamondGraph": (nx.diamond_graph, "spring"),
"PappusGraph": (nx.pappus_graph, "circular"),
Expand Down
4 changes: 3 additions & 1 deletion pymathics/graph/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ def eval(
class BinomialTree(_NetworkXBuiltin):
"""
<url>
:Binomial tree:
https://en.wikipedia.org/wiki/Binomial_heap</url> (<url>
:NetworkX:
https://networkx.org/documentation/networkx-2.8.8/reference/\
generated/networkx.generators.classic.binomial_tree.html</url>, <url>
:WMA:https://reference.wolfram.com/language/ref/BinomialTree.html</url>
:WMA:https://reference.wolfram.com/language/ref/BinomialTree.html</url>)
<dl>
<dt>'BinomialTree[$n$]'
Expand Down

0 comments on commit 59fa5e2

Please sign in to comment.