Skip to content
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

Change tomake #213

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/data-structures/word-graph/forest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Forest
======

This class represents the collection of spanning trees of a word graph.
See also :any:`to_forest`.
See also :any:`make_forest`.

Contents
--------
Expand Down Expand Up @@ -38,4 +38,4 @@ Full API
:show-inheritance:
:class-doc-from: class

.. autofunction:: to_forest
.. autofunction:: make_forest
4 changes: 2 additions & 2 deletions docs/source/data-structures/word-graph/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In ``libsemigroups_pybind11``:
.. autosummary::
:nosignatures:

to_word_graph
make_word_graph

In ``libsemigroups_pybind11.word_graph``:

Expand Down Expand Up @@ -54,7 +54,7 @@ Full API

.. currentmodule:: libsemigroups_pybind11

.. autofunction:: to_word_graph
.. autofunction:: make_word_graph

.. automodule:: libsemigroups_pybind11.word_graph
:members:
Expand Down
4 changes: 2 additions & 2 deletions libsemigroups_pybind11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
Bipartition,
Blocks,
freeband_equal_to,
to_forest,
make_forest,
Meeter,
to_word_graph,
make_word_graph,
Joiner,
Dot,
PBR,
Expand Down
6 changes: 3 additions & 3 deletions src/bipart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Copy a Blocks object.
// with them.

thing.def(py::init([](std::vector<std::vector<int32_t>> const& blocks) {
return to_blocks(blocks);
return make<Blocks>(blocks);
}),
py::arg("blocks"),
R"pbdoc(
Expand Down Expand Up @@ -264,7 +264,7 @@ Copy a Bipartition object.
// with them.

thing.def(py::init([](std::vector<std::vector<int32_t>> const& blocks) {
return to_bipartition(blocks);
return make<Bipartition>(blocks);
}),
py::arg("blocks"),
R"pbdoc(
Expand All @@ -283,7 +283,7 @@ The items in *blocks* should be:
:raises LibsemigroupsError: if any of the conditions above is not met.
)pbdoc");
thing.def(py::init([](std::vector<uint32_t> const& lookup) {
return to_bipartition(lookup);
return make<Bipartition>(lookup);
}),
py::arg("lookup"),
R"pbdoc(
Expand Down
4 changes: 2 additions & 2 deletions src/forest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ namespace py = pybind11;
namespace libsemigroups {
void init_forest(py::module& m) {
m.def(
"to_forest",
"make_forest",
[](std::vector<size_t> const& parents,
std::vector<size_t> const& labels) {
return to_forest(parents, labels);
return make<Forest>(parents, labels);
},
py::arg("parents"),
py::arg("labels"),
Expand Down
8 changes: 4 additions & 4 deletions src/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ above in :any:`MatrixKind`.
auto thing = bind_matrix_common<Mat>(m);

thing.def(py::init([](std::vector<std::vector<scalar_type>> const& rows) {
return to_matrix<Mat>(rows);
return make<Mat>(rows);
}),
py::arg("rows"),
R"pbdoc(
Expand Down Expand Up @@ -428,7 +428,7 @@ Construct a matrix from rows.
thing.def(
py::init([](size_t threshold,
std::vector<std::vector<scalar_type>> const& entries) {
return to_matrix<Mat>(semiring<semiring_type>(threshold), entries);
return make<Mat>(semiring<semiring_type>(threshold), entries);
}));
thing.def("one", [](Mat const& self, size_t n) {
return Mat::one(semiring<semiring_type>(matrix::threshold(self)), n);
Expand Down Expand Up @@ -469,8 +469,8 @@ that is a matrix whose kind is any of:
py::init([](size_t threshold,
size_t period,
std::vector<std::vector<scalar_type>> const& entries) {
return to_matrix<Mat>(semiring<semiring_type>(threshold, period),
entries);
return make<Mat>(semiring<semiring_type>(threshold, period),
entries);
}));
thing.def(
py::init([](size_t threshold, size_t period, size_t r, size_t c) {
Expand Down
9 changes: 5 additions & 4 deletions src/pbr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Construct empty PBR of given degree.
)pbdoc");
thing.def(py::init([](PBR::vector_type<int32_t> left,
PBR::vector_type<int32_t> right) {
return to_pbr(left, right);
return make<PBR>(left, right);
}),
py::arg("left"),
py::arg("right"),
Expand All @@ -79,9 +79,10 @@ A negative value ``i`` corresponds to ``n - i``.
* would not describe a binary relation on an even number of points; or
* would have a point related to a point that is greater than :any:`degree`;
)pbdoc");
thing.def(py::init([](PBR::vector_type<uint32_t> x) { return to_pbr(x); }),
py::arg("x"),
R"pbdoc(
thing.def(
py::init([](PBR::vector_type<uint32_t> x) { return make<PBR>(x); }),
py::arg("x"),
R"pbdoc(
Construct from adjacencies ``0`` to ``2n - 1``.

Construct from adjacencies ``0`` to ``2n - 1``. The parameter *x* must be a
Expand Down
4 changes: 2 additions & 2 deletions src/transf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Copy a {0}.
)pbdoc";
}
thing.def(py::init([](std::vector<Scalar> const& imgs) {
return to<PTransfSubclass>(imgs);
return make<PTransfSubclass>(imgs);
}),
py::arg("imgs"),
fmt::format(
Expand Down Expand Up @@ -432,7 +432,7 @@ among the points where :math:`f` is defined).

thing.def(py::init([](std::vector<Scalar> const& dom,
std::vector<Scalar> const& im,
size_t deg) { return to<PPerm_>(dom, im, deg); }),
size_t deg) { return make<PPerm_>(dom, im, deg); }),
py::arg("dom"),
py::arg("im"),
py::arg("M"),
Expand Down
14 changes: 7 additions & 7 deletions src/word-graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ the *out-degree* of the word graph, or any of its nodes.)pbdoc");
});

thing.def("__str__", [](WordGraph_ const& self) {
return to_input_string(self, "to_word_graph(", "[]", ")");
return to_input_string(self, "make_word_graph(", "[]", ")");
});

thing.def(py::self != py::self);
Expand Down Expand Up @@ -1027,8 +1027,8 @@ considered to be reachable from itself by default).

.. doctest::

>>> from libsemigroups_pybind11 import to_word_graph, word_graph
>>> wg = to_word_graph (5, [[0, 0], [1, 1], [2], [3, 3]])
>>> from libsemigroups_pybind11 import make_word_graph, word_graph
>>> wg = make_word_graph (5, [[0, 0], [1, 1], [2], [3, 3]])
>>> word_graph.is_strictly_cyclic(wg)
False)pbdoc");
m.def(
Expand Down Expand Up @@ -1770,9 +1770,9 @@ and *y*.
:raises LibsemigroupsError: if *y* has no nodes;
:raises LibsemigroupsError: if ``x.out_degree() != y.out_degree()``.)pbdoc");

m.def("to_word_graph",
m.def("make_word_graph",
py::overload_cast<size_t, std::vector<std::vector<node_type>> const&>(
&to_word_graph<node_type>),
&make<WordGraph<node_type>>),
py::arg("num_nodes"),
py::arg("targets"),
R"pbdoc(
Expand All @@ -1796,8 +1796,8 @@ out-degree is specified by the length of the first item in *targets*.

.. doctest::

>>> from libsemigroups_pybind11 import to_word_graph
>>> to_word_graph(5, [[0, 0], [1, 1], [2], [3, 3]])
>>> from libsemigroups_pybind11 import make_word_graph
>>> make_word_graph(5, [[0, 0], [1, 1], [2], [3, 3]])
<WordGraph with 5 nodes, 7 edges, & out-degree 2>)pbdoc");
}
} // namespace libsemigroups
10 changes: 5 additions & 5 deletions tests/test_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
Dot,
LibsemigroupsError,
word_graph,
to_word_graph,
make_word_graph,
)


def test_edge():
wg = to_word_graph(3, [[0, 1], [1, 0], [2, 2]])
wg = make_word_graph(3, [[0, 1], [1, 0], [2, 2]])
d = word_graph.dot(wg)
edges = d.edges()
assert len(edges) == 6
Expand All @@ -38,7 +38,7 @@ def test_edge():


def test_node():
wg = to_word_graph(3, [[0, 1], [1, 0], [2, 2]])
wg = make_word_graph(3, [[0, 1], [1, 0], [2, 2]])
d = word_graph.dot(wg)
nodes = d.nodes()
assert len(nodes) == 3
Expand All @@ -51,13 +51,13 @@ def test_node():


def test_dot_copy():
wg = to_word_graph(3, [[0, 1], [1, 0], [2, 2]])
wg = make_word_graph(3, [[0, 1], [1, 0], [2, 2]])
d = word_graph.dot(wg)
assert copy.copy(d) is not d


def test_dot_attrs():
wg = to_word_graph(3, [[0, 1], [1, 0], [2, 2]])
wg = make_word_graph(3, [[0, 1], [1, 0], [2, 2]])
d = word_graph.dot(wg)
d.add_attr("node [shape=circle]")
assert d.attrs() == {"node [shape=circle]": ""}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ToString,
ReversiblePaths,
POSITIVE_INFINITY,
to_word_graph,
make_word_graph,
)


Expand Down Expand Up @@ -167,7 +167,7 @@ def test_ToString_reversed():


def test_paths_bug():
wg = to_word_graph(4, [[0, 1], [1, 0], [2, 2]])
wg = make_word_graph(4, [[0, 1], [1, 0], [2, 2]])
p = Paths(wg)
p.source(0).target(1)
assert p.source() == 0
Expand All @@ -176,7 +176,7 @@ def test_paths_bug():


def test_paths_bug2():
wg = to_word_graph(4, [[0, 1], [1, 0], [2, 2]])
wg = make_word_graph(4, [[0, 1], [1, 0], [2, 2]])
p = Paths(wg)
assert p.max() is POSITIVE_INFINITY

Expand Down
36 changes: 18 additions & 18 deletions tests/test_word_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
WordGraph,
word_graph,
LibsemigroupsError,
to_forest,
make_forest,
UNDEFINED,
Forest,
Order,
Meeter,
to_word_graph,
make_word_graph,
Joiner,
Matrix,
MatrixKind,
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_number_of_nodes_reachable_from(word_graph_fixture):
def test_spanning_tree(word_graph_fixture):
wg1, _ = word_graph_fixture

assert word_graph.spanning_tree(wg1, 0) == to_forest(
assert word_graph.spanning_tree(wg1, 0) == make_forest(
[int(UNDEFINED), 0, 1, 2, 3], [int(UNDEFINED), 0, 0, 0, 0]
)

Expand Down Expand Up @@ -273,44 +273,44 @@ def test_meeter(word_graph_fixture):
wg1.remove_target(4, 0)

meet = Meeter()
assert wg1 == to_word_graph(5, [[1], [2], [3], [4], [2**32 - 1]])
assert wg1 == make_word_graph(5, [[1], [2], [3], [4], [2**32 - 1]])
assert meet(wg1, wg1) == wg1

wg2 = to_word_graph(2, [[1, 0], [1, 0]])
wg3 = to_word_graph(2, [[1, 1], [1, 1]])
wg2 = make_word_graph(2, [[1, 0], [1, 0]])
wg3 = make_word_graph(2, [[1, 1], [1, 1]])

assert meet(wg3, wg2) == to_word_graph(3, [[1, 2], [1, 2], [1, 2]])
assert meet(wg3, wg2) == make_word_graph(3, [[1, 2], [1, 2], [1, 2]])
meet(wg1, wg3, wg2)
assert wg1 == to_word_graph(3, [[1, 2], [1, 2], [1, 2]])
assert wg1 == make_word_graph(3, [[1, 2], [1, 2], [1, 2]])
assert meet.is_subrelation(wg1, wg3)
assert meet.is_subrelation(wg1, wg2)


def test_joiner(word_graph_fixture):
wg1, _ = word_graph_fixture
wg1.remove_target(0, 0)
assert wg1 == to_word_graph(5, [[2**32 - 1], [2], [3], [4], [0]])
assert wg1 == make_word_graph(5, [[2**32 - 1], [2], [3], [4], [0]])

join = Joiner()
# TODO(later) use UNDEFINED here instead of 2**32 -1
assert join(wg1, wg1) == to_word_graph(1, [[2**32 - 1]])
assert join(wg1, wg1) == make_word_graph(1, [[2**32 - 1]])

wg3 = to_word_graph(2, [[1, 1], [1, 1]])
wg2 = to_word_graph(2, [[1, 0], [1, 0]])
wg3 = make_word_graph(2, [[1, 1], [1, 1]])
wg2 = make_word_graph(2, [[1, 0], [1, 0]])

assert join(wg3, wg2) == to_word_graph(1, [[0, 0]])
assert join(wg3, wg2) == make_word_graph(1, [[0, 0]])
join(wg1, wg3, wg2)
assert wg1 == to_word_graph(1, [[0, 0]])
assert wg1 == make_word_graph(1, [[0, 0]])
assert join.is_subrelation(wg3, wg1)
assert join.is_subrelation(wg2, wg1)


def test_str(word_graph_fixture):
wg1, wg2 = word_graph_fixture
assert str(wg1) == "to_word_graph(5, [[1], [2], [3], [4], [0]])"
assert str(wg1) == "make_word_graph(5, [[1], [2], [3], [4], [0]])"
assert (
str(wg2)
== "to_word_graph(10, [[1], [2], [3], [4], [0], [6], [7], [8], [9], [5]])"
== "make_word_graph(10, [[1], [2], [3], [4], [0], [6], [7], [8], [9], [5]])"
)


Expand Down Expand Up @@ -339,7 +339,7 @@ def test_random():
assert word_graph.is_acyclic(w)
assert word_graph.is_connected(w)

d = to_word_graph(3, [[0, 1], [1, 0], [2, 2]])
d = make_word_graph(3, [[0, 1], [1, 0], [2, 2]])
assert (
str(word_graph.dot(d))
== 'digraph WordGraph {\n\n 0 [shape="box"]\n 1 [shape="box"]\n 2'
Expand All @@ -349,7 +349,7 @@ def test_random():
' [color="#ff00ff"]\n}'
)

d = to_word_graph(4, list(12 * [i] for i in range(4)))
d = make_word_graph(4, list(12 * [i] for i in range(4)))
assert (
str(word_graph.dot(d))
== 'digraph WordGraph {\n\n 0 [shape="box"]\n 1 [shape="box"]\n 2 [shape="box"]\n 3 [shape="box"]\n 0 -> 0 [color="#00ff00"]\n 0 -> 0 [color="#ff00ff"]\n 0 -> 0 [color="#007fff"]\n 0 -> 0 [color="#ff7f00"]\n 0 -> 0 [color="#7fbf7f"]\n 0 -> 0 [color="#4604ac"]\n 0 -> 0 [color="#de0328"]\n 0 -> 0 [color="#19801d"]\n 0 -> 0 [color="#d881f5"]\n 0 -> 0 [color="#00ffff"]\n 0 -> 0 [color="#ffff00"]\n 0 -> 0 [color="#00ff7f"]\n 1 -> 1 [color="#00ff00"]\n 1 -> 1 [color="#ff00ff"]\n 1 -> 1 [color="#007fff"]\n 1 -> 1 [color="#ff7f00"]\n 1 -> 1 [color="#7fbf7f"]\n 1 -> 1 [color="#4604ac"]\n 1 -> 1 [color="#de0328"]\n 1 -> 1 [color="#19801d"]\n 1 -> 1 [color="#d881f5"]\n 1 -> 1 [color="#00ffff"]\n 1 -> 1 [color="#ffff00"]\n 1 -> 1 [color="#00ff7f"]\n 2 -> 2 [color="#00ff00"]\n 2 -> 2 [color="#ff00ff"]\n 2 -> 2 [color="#007fff"]\n 2 -> 2 [color="#ff7f00"]\n 2 -> 2 [color="#7fbf7f"]\n 2 -> 2 [color="#4604ac"]\n 2 -> 2 [color="#de0328"]\n 2 -> 2 [color="#19801d"]\n 2 -> 2 [color="#d881f5"]\n 2 -> 2 [color="#00ffff"]\n 2 -> 2 [color="#ffff00"]\n 2 -> 2 [color="#00ff7f"]\n 3 -> 3 [color="#00ff00"]\n 3 -> 3 [color="#ff00ff"]\n 3 -> 3 [color="#007fff"]\n 3 -> 3 [color="#ff7f00"]\n 3 -> 3 [color="#7fbf7f"]\n 3 -> 3 [color="#4604ac"]\n 3 -> 3 [color="#de0328"]\n 3 -> 3 [color="#19801d"]\n 3 -> 3 [color="#d881f5"]\n 3 -> 3 [color="#00ffff"]\n 3 -> 3 [color="#ffff00"]\n 3 -> 3 [color="#00ff7f"]\n}' # pylint: disable=line-too-long
Expand Down
Loading