Skip to content

Commit caec1ab

Browse files
petercorkeclaude
andcommitted
feat: coordinates(), build_kdtree(), subgraph mask, validate coordinates
coordinates() is the matrix of vertex coordinates, one column per vertex in insertion order (NaN for a vertex with none), a view of a row-per-vertex array. within() and near() are now computed on it with numpy, for the built-in metrics, instead of vertex by vertex. build_kdtree() builds an optional scipy cKDTree that closest() and near() use for the built-in L1, L2 and SE2 (with its weight, using a periodic dimension for the angle). scipy is imported only inside the method and is not added to pyproject.toml. The index is dropped when a vertex is added or removed or a coord is assigned (Vertex.__setattr__), so a stale index is never used; a coordinate edited in place is documented as not seen. It is not copied or pickled. subgraph() also takes a boolean mask of length n. An integer vector is refused, since it could be indices. validate() now checks that coordinates are finite 1-D numeric vectors and, when dim was not given, all of one length, and with embedded=True that every vertex has one. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 78ffdb7 commit caec1ab

4 files changed

Lines changed: 777 additions & 42 deletions

File tree

‎docs/source/analysis.rst‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,27 @@ Geometry and consistency
5050
^^^^^^^^^^^^^^^^^^^^^^^^^
5151

5252
For a graph whose vertices have coordinates,
53-
:meth:`~pgraph.PGraph.Graph.closest` finds the nearest vertex to a point,
54-
:meth:`~pgraph.PGraph.Graph.near` the vertices within a distance of a point and
55-
:meth:`~pgraph.PGraph.Graph.within` the vertices inside a box. Passing the
56-
result of the last to :meth:`~pgraph.PGraph.Graph.subgraph` gives the part of
57-
the graph in a region, without the edges that cross its border.
53+
:meth:`~pgraph.PGraph.Graph.coordinates` is the matrix of them, one column per
54+
vertex. :meth:`~pgraph.PGraph.Graph.closest` finds the nearest vertex to a
55+
point, :meth:`~pgraph.PGraph.Graph.near` the vertices within a distance of a
56+
point and :meth:`~pgraph.PGraph.Graph.within` the vertices inside a box. Passing
57+
the result of the last to :meth:`~pgraph.PGraph.Graph.subgraph` gives the part of
58+
the graph in a region, without the edges that cross its border, and a boolean
59+
mask computed from the coordinates selects in the same way.
60+
61+
These are a single pass over the vertices. For a large graph that is queried
62+
often, :meth:`~pgraph.PGraph.Graph.build_kdtree` builds an index that
63+
:meth:`~pgraph.PGraph.Graph.closest` and :meth:`~pgraph.PGraph.Graph.near` then
64+
use, which needs scipy and is for the built-in metrics.
5865

5966
.. autosummary::
6067
:nosignatures:
6168

69+
~pgraph.PGraph.Graph.coordinates
6270
~pgraph.PGraph.Graph.closest
6371
~pgraph.PGraph.Graph.near
6472
~pgraph.PGraph.Graph.within
73+
~pgraph.PGraph.Graph.build_kdtree
6574
~pgraph.PGraph.Graph.subgraph
6675
~pgraph.PGraph.Graph.validate
6776

@@ -163,9 +172,11 @@ Details
163172
.. automethod:: pgraph.PGraph.Graph.samecomponent
164173
.. automethod:: pgraph.PGraph.Graph.connectivity
165174
.. automethod:: pgraph.PGraph.Graph.average_degree
175+
.. automethod:: pgraph.PGraph.Graph.coordinates
166176
.. automethod:: pgraph.PGraph.Graph.closest
167177
.. automethod:: pgraph.PGraph.Graph.near
168178
.. automethod:: pgraph.PGraph.Graph.within
179+
.. automethod:: pgraph.PGraph.Graph.build_kdtree
169180
.. automethod:: pgraph.PGraph.Graph.subgraph
170181
.. automethod:: pgraph.PGraph.Graph.validate
171182

0 commit comments

Comments
 (0)