edsger 0.1.1__cp311-cp311-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ """
2
+ Path tracking module.
3
+
4
+ cpdef functions:
5
+
6
+ - compute_path
7
+ Compute path from predecessors or successors.
8
+
9
+ cdef functions:
10
+
11
+ - _compute_path_first_pass
12
+ Returns the path length.
13
+ - _compute_path_second_pass
14
+ Compute the sequence of vertices forming a path.
15
+ """
16
+
17
+ import numpy as np
18
+ cimport numpy as cnp
19
+
20
+
21
+ cpdef cnp.ndarray compute_path(cnp.uint32_t[::1] path_links, int vertex_idx):
22
+ """Compute path from predecessors or successors.
23
+
24
+ Parameters:
25
+ -----------
26
+
27
+ path_links : cnp.uint32_t[::1]
28
+ predecessors or successors.
29
+
30
+ vertex_idx : int
31
+ source or target vertex index.
32
+ """
33
+
34
+ cdef int path_length
35
+
36
+ path_length = _compute_path_first_pass(path_links, vertex_idx)
37
+ path_vertices = np.empty(path_length, dtype=np.uint32)
38
+ _compute_path_second_pass(path_links, path_vertices, vertex_idx)
39
+
40
+ return path_vertices
41
+
42
+
43
+ cdef int _compute_path_first_pass(
44
+ cnp.uint32_t[::1] path_links,
45
+ int vertex_idx
46
+ ) nogil noexcept:
47
+ """Returns the path length.
48
+ """
49
+
50
+ cdef:
51
+ size_t i, j
52
+ int k
53
+
54
+ # initialization
55
+ j = <size_t>vertex_idx
56
+ i = j + 1
57
+ k = 0
58
+
59
+ # loop
60
+ while i != j:
61
+ i = j
62
+ j = <size_t>path_links[j]
63
+ k += 1
64
+
65
+ return k
66
+
67
+
68
+ cdef void _compute_path_second_pass(
69
+ cnp.uint32_t[::1] path_links,
70
+ cnp.uint32_t[::1] path_vertices,
71
+ int vertex_idx
72
+ ) nogil noexcept:
73
+ """Compute the sequence of vertices forming a path.
74
+ """
75
+ cdef size_t i, j, k
76
+
77
+ # initialization
78
+ j = <size_t>vertex_idx
79
+ i = j + 1
80
+ k = 0
81
+
82
+ # loop
83
+ while i != j:
84
+ i = j
85
+ path_vertices[k] = j
86
+ j = <size_t>path_links[j]
87
+ k += 1
88
+
89
+
90
+ # author : Francois Pacull
91
+ # copyright : Architecture & Performance
92
+ # email: francois.pacull@architecture-performance.fr
93
+ # license : MIT