knit_graphs.artin_wale_braids.Wale module
Module containing the Wale Class.
This module defines the Wale class which represents a vertical column of stitches in a knitted structure, maintaining the sequence and relationships between loops in that column.
- class Wale(first_loop: LoopT, knit_graph: Knit_Graph[LoopT], end_loop: LoopT | None = None)[source]
Bases:
Directed_Loop_Graph[LoopT,Pull_Direction]A data structure representing stitch relationships between loops in a vertical column of a knitted structure.
A wale represents a vertical sequence of loops connected by stitch edges, forming a column in the knitted fabric. This class manages the sequential relationships between loops and tracks the pull directions of stitches within the wale.
- __init__(first_loop: LoopT, knit_graph: Knit_Graph[LoopT], end_loop: LoopT | None = None) None[source]
Initialize a wale optionally starting with a specified loop.
- Parameters:
first_loop (Loop) – The initial loop to start the wale with.
knit_graph (Knit_Graph) – The knit graph that owns this wale.
end_loop (Loop, optional) – The loop to terminate the wale with. If no loop is provided or this loop is not found, the wale will terminate at the first loop with no child.
- get_pull_direction(u: LoopT, v: LoopT) Pull_Direction[source]
Get the pull direction of the stitch edge between two loops in this wale.
- Parameters:
u (LoopT) – The parent loop in the stitch connection.
v (LoopT) – The child loop in the stitch connection.
- Returns:
The pull direction of the stitch between loops u and v.
- Return type:
- split_wale(split_loop: LoopT) tuple[Wale[LoopT], Wale[LoopT] | None][source]
Split this wale at the specified loop into two separate wales.
The split loop becomes the last loop of the first wale and the first loop of the second wale.
- Parameters:
split_loop (Loop) – The loop at which to split the wale. This loop will appear in both resulting wales.
- Returns:
A tuple containing: * The first wale (from start to split_loop). This will be the whole wale if the split_loop is not found. * The second wale (from split_loop to end). This will be None if the split_loop is not found.
- Return type:
- add_loop_to_end(loop: LoopT) None[source]
Add a loop to the end (top) of the wale. :param loop: The loop to add to the end of the wale. :type loop: T
- __getitem__(item: int) LoopT[source]
- __getitem__(item: tuple[LoopT | int, LoopT | int]) Pull_Direction
- __getitem__(item: slice) list[LoopT]
Get a loop by its ID from this yarn.
- Parameters:
item (int | tuple[LoopT | int, LoopT | int] | slice) – The loop ,loop ID, or float between two loops to retrieve from this yarn. If given a slice, it will retrieve the elements between the specified indices in the standard ordering of loops along the wale.
- Returns:
The loop on the yarn with the matching ID. Stitch_Edge: The edge data for the given pair of loops forming a stitch in the wale. list[LoopT]: The loops in the slice of the wale based on their ordering along the wale.
- Return type:
LoopT
- Raises:
KeyError – If the item is not found on this yarn.
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- __hash__() int[source]
Get the hash value of this wale based on its first loop.
- Returns:
Hash value based on the first loop in this wale.
- Return type:
- __iter__() Iterator[LoopT]
- Returns:
Iterator over all the loops in the graph.
- Return type:
Iterator[LoopT]
Notes
No guarantees about order of loops. Expected to be insertion order.
- add_edge(u: LoopT | int, v: LoopT | int, edge_data: EdgeT) None
Connect the given loop u to the loop v with the given edge data. :param u: The loop to connect to. :type u: LoopT | int :param v: The loop to connect to. :type v: LoopT | int :param edge_data: The edge data to associate with the connection. :type edge_data: EdgeT
- Raises:
KeyError – Either of the given loops does not exist in the graph.
- add_loop(loop: LoopT) None
Add the given loop to the loop graph. :param loop: The loop to add to the graph. :type loop: LoopT
- ancestors(loop: LoopT) set[LoopT]
- Parameters:
loop (LoopT) – The loop to get the ancestors of from the graph.
- Returns:
The ancestors of the given loop.
- Return type:
set[LoopT]
- property contains_loops: bool
Returns: bool: True if the graph has at least one loop, False otherwise.
- dfs_edges(loop: LoopT) Iterator[tuple[LoopT, LoopT]]
- Parameters:
loop (LoopT) – The loop to start iteration over edges from.
- Returns:
The depth-first-search ordering of edges starting from the given loop.
- dfs_preorder_loops(loop: LoopT) Iterator[LoopT]
- Parameters:
loop (LoopT) – The loop to start iteration from.
- Returns:
The depth-first-search ordering of loops in the graph starting from the given loop.
- Return type:
Iterator[LoopT]
- property edge_iter: Iterator[tuple[LoopT, LoopT, EdgeT]]
- Returns:
Iterator over the edges and edge-data in the graph.
- Return type:
Iterator[tuple[LoopT, LoopT, EdgeT]]
Notes
No guarantees about the order of the edges.
- get_child_loop(loop: LoopT) LoopT | None
- Parameters:
loop (LoopT) – The loop to look for a child loop from.
- Returns:
The child loop if one exists, or None if no child loop is found.
- Return type:
LoopT | None
- get_loop(loop_id: int) LoopT
- Parameters:
loop_id (int) – The loop id of the loop to get from the graph.
- Returns:
The loop node in the graph.
- Return type:
LoopT
- is_descendant(ancestor: LoopT, descendant: LoopT) bool
- Parameters:
ancestor (LoopT) – The loop to check if it is an ancestor of the other loop.
descendant (LoopT) – The loop to check if it is a descendant of the other loop.
- Returns:
True if there is a directed path from the ancestor to the descendant, False otherwise.
- Return type:
- is_terminal_loop(loop: LoopT) bool
- Parameters:
loop (LoopT) – The loop to check for terminal status.
- Returns:
True if the loop has no child loops, False otherwise.
- Return type:
- remove_edge(u: LoopT | int, v: LoopT | int) None
Removes the edge from loop u to the loop v from the graph. :param u: The loop to connect to. :type u: LoopT | int :param v: The loop to connect to. :type v: LoopT | int
- Raises:
KeyError – The given edge does not exist in the graph.
- remove_loop(loop: LoopT | int) None
Remove the given loop from the graph. :param loop: The loop or id of the loop to remove. :type loop: LoopT | int
- Raises:
KeyError – The given loop does not exist in the graph.
- property sorted_loops: list[LoopT]
Returns: list[Loop]: The list of loops in the graph sorted from the earliest formed loop to the latest formed loop.
- source_loops(loop: LoopT) set[LoopT]
- Parameters:
loop (LoopT) – The loop to get the sources of.
- Returns:
The source loops of the given loop. These are the loops that are the source of all ancestors to the given loop.
- Return type:
set[LoopT]