Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
GauthierE committed Mar 27, 2024
1 parent 00fb5b0 commit 489217b
Show file tree
Hide file tree
Showing 5 changed files with 930 additions and 141 deletions.
144 changes: 144 additions & 0 deletions display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
from utils import Representation, Interval

def display_rep(rep):
"""
- Input: representation
Display the grid with vector space dimensions for each node,
and arrows between each pair of adjacent nodes iff there is a matrix between these two nodes.
"""
if len(rep.dimensions) > 2:
print(f"Error: The vizualization is only available for 1D or 2D grids, but the grid has dimension {len(rep.dimensions)}.")

elif len(rep.dimensions) == 2:
for i in range(rep.dimensions[0]):
for j in range(rep.dimensions[1]):
node = (i, j)
vecs_dim = rep.vecs.get(node, None)
edge = (node, (i, j+1))
if vecs_dim is not None:
if j != rep.dimensions[1] - 1:
if edge in rep.mats:
print(f"{vecs_dim} -------> ", end="")
else:
print(f"{vecs_dim} ", end="")
else:
print(f"{vecs_dim}", end="")
else:
if j != rep.dimensions[1] - 1:
if edge in rep.mats:
print(f". -------> ", end="")
else:
print(f". ", end="")
else:
print(".", end="")

print()

if i != rep.dimensions[0] - 1:
for j in range(rep.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in rep.mats:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(rep.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in rep.mats:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(rep.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in rep.mats:
print("v ", end="")
else:
print(" ", end="")
print()

elif len(rep.dimensions) == 1:
for j in range(rep.dimensions[0]):
node = (j,)
vecs_dim = rep.vecs.get(node, None)
edge = (node, (j+1,))
if vecs_dim is not None:
if j != rep.dimensions[0] - 1:
if edge in rep.mats:
print(f"{vecs_dim} -------> ", end="")
else:
print(f"{vecs_dim} ", end="")
else:
print(f"{vecs_dim}", end="")
else:
if j != rep.dimensions[0] - 1:
if edge in rep.mats:
print(f". -------> ", end="")
else:
print(f". ", end="")
else:
print(".", end="")
print()

def display_interval(rep, itv):
"""
Input:
- Representation rep
- Interval itv
Display the grid and arrows between each pair of adjacent nodes contained in the interval.
"""
if len(rep.dimensions) > 2:
print(f"Error: The vizualization is only available for 1D or 2D grids, but the grid has dimension {len(rep.dimensions)}.")

elif len(rep.dimensions) == 2:
hull = rep.int_hull(itv)
for i in range(rep.dimensions[0]):
for j in range(rep.dimensions[1]):
if j != rep.dimensions[1] - 1:
if (i,j) in hull and (i,j+1) in hull:
print(f"X -------> ", end="")
elif (i,j) in hull and (i,j+1) not in hull:
print(f"X ", end="")
else:
print(f". ", end="")
else:
if (i,j) in hull:
print("X", end="")
else:
print(".", end="")
print()
if i != rep.dimensions[0] - 1:
for j in range(rep.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(rep.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(rep.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("v ", end="")
else:
print(" ", end="")
print()

elif len(rep.dimensions) == 1:
hull = rep.int_hull(itv)
for j in range(rep.dimensions[0] - 1):
if (j,) in hull and ((j+1,)) in hull:
print("X -------> ", end="")
elif (j,) in hull and ((j+1,)) not in hull:
print("X ", end="")
else:
print(". ", end="")
else:
if (j,) in hull:
print("X", end="")
else:
print(".", end="")
print()
Binary file modified img/quiver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/representation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
785 changes: 785 additions & 0 deletions tutorial.ipynb

Large diffs are not rendered by default.

142 changes: 1 addition & 141 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,144 +520,4 @@ def elements(self):
print("Nodes:", self.nodes)
print("Edges:", self.edges)
print("Vector spaces:", self.vecs)
print("Matrices:", self.mats)


def display(self):
"""
Display the grid with vector space dimensions for each node,
and arrows between each pair of adjacent nodes iff there is a matrix between these two nodes.
"""
if len(self.dimensions) > 2:
print(f"Error: The vizualization is only available for 1D or 2D grids, but the grid has dimension {len(self.dimensions)}.")

elif len(self.dimensions) == 2:
for i in range(self.dimensions[0]):
for j in range(self.dimensions[1]):
node = (i, j)
vecs_dim = self.vecs.get(node, None)
edge = (node, (i, j+1))
if vecs_dim is not None:
if j != self.dimensions[1] - 1:
if edge in self.mats:
print(f"{vecs_dim} -------> ", end="")
else:
print(f"{vecs_dim} ", end="")
else:
print(f"{vecs_dim}", end="")
else:
if j != self.dimensions[1] - 1:
if edge in self.mats:
print(f". -------> ", end="")
else:
print(f". ", end="")
else:
print(".", end="")

print()

if i != self.dimensions[0] - 1:
for j in range(self.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in self.mats:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(self.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in self.mats:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(self.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in self.mats:
print("v ", end="")
else:
print(" ", end="")
print()

elif len(self.dimensions) == 1:
for j in range(self.dimensions[0]):
node = (j,)
vecs_dim = self.vecs.get(node, None)
edge = (node, (j+1,))
if vecs_dim is not None:
if j != self.dimensions[0] - 1:
if edge in self.mats:
print(f"{vecs_dim} -------> ", end="")
else:
print(f"{vecs_dim} ", end="")
else:
print(f"{vecs_dim}", end="")
else:
if j != self.dimensions[0] - 1:
if edge in self.mats:
print(f". -------> ", end="")
else:
print(f". ", end="")
else:
print(".", end="")
print()

def display_interval(self, interval):
"""
Display the grid and arrows between each pair of adjacent nodes contained in the interval.
"""
if len(self.dimensions) > 2:
print(f"Error: The vizualization is only available for 1D or 2D grids, but the grid has dimension {len(self.dimensions)}.")

elif len(self.dimensions) == 2:
hull = self.int_hull(interval)
for i in range(self.dimensions[0]):
for j in range(self.dimensions[1]):
if j != self.dimensions[1] - 1:
if (i,j) in hull and (i,j+1) in hull:
print(f"X -------> ", end="")
elif (i,j) in hull and (i,j+1) not in hull:
print(f"X ", end="")
else:
print(f". ", end="")
else:
if (i,j) in hull:
print("X", end="")
else:
print(".", end="")
print()
if i != self.dimensions[0] - 1:
for j in range(self.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(self.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(self.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("v ", end="")
else:
print(" ", end="")
print()

elif len(self.dimensions) == 1:
hull = self.int_hull(interval)
for j in range(self.dimensions[0] - 1):
if (j,) in hull and ((j+1,)) in hull:
print("X -------> ", end="")
elif (j,) in hull and ((j+1,)) not in hull:
print("X ", end="")
else:
print(". ", end="")
else:
if (j,) in hull:
print("X", end="")
else:
print(".", end="")
print()
print("Matrices:", self.mats)

0 comments on commit 489217b

Please sign in to comment.