memory-graph 0.3.11__tar.gz → 0.3.12__tar.gz

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.
Files changed (91) hide show
  1. {memory_graph-0.3.11/memory_graph.egg-info → memory_graph-0.3.12}/PKG-INFO +7 -7
  2. {memory_graph-0.3.11 → memory_graph-0.3.12}/README.md +6 -6
  3. memory_graph-0.3.12/TODO.txt +9 -0
  4. memory_graph-0.3.12/images/add_one.png +0 -0
  5. memory_graph-0.3.12/images/add_one.py +18 -0
  6. memory_graph-0.3.12/images/avltree.py +43 -0
  7. memory_graph-0.3.12/images/avltree_base.png +0 -0
  8. memory_graph-0.3.12/images/avltree_dir.png +0 -0
  9. memory_graph-0.3.12/images/avltree_fail.png +0 -0
  10. memory_graph-0.3.12/images/avltree_key_value.png +0 -0
  11. memory_graph-0.3.12/images/avltree_linear.png +0 -0
  12. memory_graph-0.3.12/images/avltree_table.png +0 -0
  13. memory_graph-0.3.12/images/bin_tree.png +0 -0
  14. memory_graph-0.3.12/images/bin_tree.py +47 -0
  15. memory_graph-0.3.12/images/copies.png +0 -0
  16. memory_graph-0.3.12/images/copies.py +15 -0
  17. memory_graph-0.3.12/images/copy_method.png +0 -0
  18. memory_graph-0.3.12/images/copy_method.py +22 -0
  19. memory_graph-0.3.12/images/create_gif.sh +19 -0
  20. memory_graph-0.3.12/images/create_images.sh +34 -0
  21. memory_graph-0.3.12/images/debug_vscode.png +0 -0
  22. memory_graph-0.3.12/images/debugging.gif +0 -0
  23. memory_graph-0.3.12/images/debugging.py +19 -0
  24. memory_graph-0.3.12/images/extension_numpy.png +0 -0
  25. memory_graph-0.3.12/images/extension_numpy.py +14 -0
  26. memory_graph-0.3.12/images/extension_pandas.png +0 -0
  27. memory_graph-0.3.12/images/extension_pandas.py +17 -0
  28. memory_graph-0.3.12/images/factorial.gif +0 -0
  29. memory_graph-0.3.12/images/factorial.py +24 -0
  30. memory_graph-0.3.12/images/hash_set.png +0 -0
  31. memory_graph-0.3.12/images/hash_set.py +39 -0
  32. memory_graph-0.3.12/images/highlight.png +0 -0
  33. memory_graph-0.3.12/images/highlight.py +15 -0
  34. memory_graph-0.3.12/images/immutable.py +11 -0
  35. memory_graph-0.3.12/images/immutable1.png +0 -0
  36. memory_graph-0.3.12/images/immutable2.png +0 -0
  37. memory_graph-0.3.12/images/ipython.png +0 -0
  38. memory_graph-0.3.12/images/jupyter_example.ipynb +85 -0
  39. memory_graph-0.3.12/images/jupyter_example.png +0 -0
  40. memory_graph-0.3.12/images/linked_list.png +0 -0
  41. memory_graph-0.3.12/images/linked_list.py +39 -0
  42. memory_graph-0.3.12/images/many_types.png +0 -0
  43. memory_graph-0.3.12/images/many_types.py +13 -0
  44. memory_graph-0.3.12/images/mutable.py +11 -0
  45. memory_graph-0.3.12/images/mutable1.png +0 -0
  46. memory_graph-0.3.12/images/mutable2.png +0 -0
  47. memory_graph-0.3.12/images/power_set.gif +0 -0
  48. memory_graph-0.3.12/images/power_set.py +28 -0
  49. memory_graph-0.3.12/images/pyodide.png +0 -0
  50. memory_graph-0.3.12/images/uva.png +0 -0
  51. memory_graph-0.3.12/install.txt +31 -0
  52. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/__init__.py +4 -2
  53. {memory_graph-0.3.11 → memory_graph-0.3.12/memory_graph.egg-info}/PKG-INFO +7 -7
  54. memory_graph-0.3.12/memory_graph.egg-info/SOURCES.txt +88 -0
  55. {memory_graph-0.3.11 → memory_graph-0.3.12}/setup.py +1 -1
  56. memory_graph-0.3.12/src/auto_memory_graph.py +21 -0
  57. memory_graph-0.3.12/src/pyodide.html +182 -0
  58. memory_graph-0.3.12/uml/memory_graph.uxf +322 -0
  59. memory_graph-0.3.11/memory_graph.egg-info/SOURCES.txt +0 -36
  60. {memory_graph-0.3.11 → memory_graph-0.3.12}/LICENSE.txt +0 -0
  61. {memory_graph-0.3.11 → memory_graph-0.3.12}/MANIFEST.in +0 -0
  62. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/config.py +0 -0
  63. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/config_default.py +0 -0
  64. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/config_helpers.py +0 -0
  65. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/extension_numpy.py +0 -0
  66. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/extension_pandas.py +0 -0
  67. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/html_table.py +0 -0
  68. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/list_view.py +0 -0
  69. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/memory_to_nodes.py +0 -0
  70. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/node_base.py +0 -0
  71. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/node_key_value.py +0 -0
  72. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/node_linear.py +0 -0
  73. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/node_table.py +0 -0
  74. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/sequence.py +0 -0
  75. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/slicer.py +0 -0
  76. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/slices.py +0 -0
  77. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/slices_iterator.py +0 -0
  78. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/slices_table_iterator.py +0 -0
  79. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/test.py +0 -0
  80. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/test_max_graph_depth.py +0 -0
  81. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/test_memory_graph.py +0 -0
  82. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/test_memory_to_nodes.py +0 -0
  83. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/test_sequence.py +0 -0
  84. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/test_slicer.py +0 -0
  85. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/test_slices.py +0 -0
  86. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/test_slices_iterator.py +0 -0
  87. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph/utils.py +0 -0
  88. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph.egg-info/dependency_links.txt +0 -0
  89. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph.egg-info/requires.txt +0 -0
  90. {memory_graph-0.3.11 → memory_graph-0.3.12}/memory_graph.egg-info/top_level.txt +0 -0
  91. {memory_graph-0.3.11 → memory_graph-0.3.12}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: memory_graph
3
- Version: 0.3.11
3
+ Version: 0.3.12
4
4
  Summary: Draws a graph of your data to analyze its structure.
5
5
  Home-page: https://github.com/bterwijn/memory_graph
6
6
  Author: Bas Terwijn
@@ -156,7 +156,7 @@ mg.render(locals(), 'immutable2.png')
156
156
 
157
157
 
158
158
  ### Mutable Type ###
159
- With mutable types the result is different. In the code below variable `a` and `b` both reference the same `list` value [4, 3, 2]. A `list` is a mutable type and therefore when we change variable `a` its value **can** be mutated in place and thus `a` and `b` both reference the same new value afterwards. Thus changing `a` also changes `b` and vice versa. Sometimes we want this but other times we don't and then we will have to make a copy so that `a` and `b` are independent.
159
+ With mutable types the result is different. In the code below variable `a` and `b` both reference the same `list` value [4, 3, 2]. A `list` is a mutable type and therefore when we change variable `a` its value **can** be mutated in place and thus `a` and `b` both reference the same new value afterwards. Thus changing `a` also changes `b` and vice versa. Sometimes we want this but other times we don't and then we will have to make a copy ourselfs so that `a` and `b` are independent.
160
160
 
161
161
  ```python
162
162
  import memory_graph as mg
@@ -264,7 +264,7 @@ This function:
264
264
  * then blocks execution until the <Enter> key is pressed
265
265
  * finally returns the value of the `fun()` call
266
266
 
267
- to change it's behavior:
267
+ to change its behavior:
268
268
  * Set `mg.block_prints_location = False` to skip printing the source location.
269
269
  * Set `mg.press_enter_message = None` to skip printing "Press <Enter> to continue...".
270
270
 
@@ -326,7 +326,7 @@ For the best debugging experience with memory_graph set for example expression:
326
326
  ```
327
327
  mg.render(locals(), "my_graph.pdf")
328
328
  ```
329
- as a *watch* in a debugger tool such as the integrated debugger in Visual Studio Code. Then open the "my_graph.pdf" output file to continuously see all the local variables while debugging. This avoids having to add any memory_graph `show()`, `render()` calls to your code.
329
+ as a *watch* in a debugger tool such as the integrated debugger in Visual Studio Code. Then open the "my_graph.pdf" output file to continuously see all the local variables while debugging. This avoids having to add any memory_graph `show()` or `render()` calls to your code.
330
330
 
331
331
  ### Call Stack in Watch Context ###
332
332
  The ```mg.get_call_stack()``` doesn't work well in *watch* context in most debuggers because debuggers introduce additional stack frames that cause problems. Use these alternative functions for various debuggers to filter out these problematic stack frames:
@@ -511,7 +511,7 @@ for i in range(n):
511
511
  Different aspects of memory_graph can be configured. The default configuration is reset by importing 'memory_graph.config_default'.
512
512
 
513
513
  - ***mg.config.max_graph_depth*** : int
514
- - The maxium depth of the graph with default value 12. A `✂` (scissor) symbol indicates where the graph is cut short.
514
+ - The maxium depth of the graph with default value 12. A `✂` (scissor) symbol indicates where the graph is cut short. Dashed references indicate that there are more references to a node than are shown.
515
515
 
516
516
  - ***mg.config.max_string_length*** : int
517
517
  - The maximum length of strings shown in the graph. Longer strings will be truncated.
@@ -535,7 +535,7 @@ Different aspects of memory_graph can be configured. The default configuration i
535
535
  - Maps each type to a Slicer. A slicer determines how many elements of a data type are shown in the graph to prevent the graph from getting too big. 'Slicer()' does no slicing, 'Slicer(1,2,3)' shows just 1 element at the beginning, 2 in the middle, and 3 at the end.
536
536
 
537
537
  ### Temporary Configuration ###
538
- In addition to the global configuration, a temporary configuration can be set for a single `show()`, `render()`, `d()`, `ds()` call to change the colors, orientation, and slicer. This example highlights a particular list element in red, gives it a horizontal orientation, and overwrites the default slicer for lists:
538
+ In addition to the global configuration, a temporary configuration can be set for a single `show()` or `render()` call to change the colors, orientation, and slicer. This example highlights a particular list element in red, gives it a horizontal orientation, and overwrites the default slicer for lists:
539
539
 
540
540
  ```python
541
541
  import memory_graph as mg
@@ -750,7 +750,7 @@ Then after starting 'ipython' call function `mg_switch()` to turn on/off the aut
750
750
  ![ipyton.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/ipython.png)
751
751
 
752
752
  ## In the Browser ##
753
- We can run memory_graph in the browser: <a href="https://bterwijn.github.io/memory_graph/src/pyodide.html" target="_blank">Pyodide Example</a>
753
+ We can also run memory_graph in the browser: <a href="https://bterwijn.github.io/memory_graph/src/pyodide.html" target="_blank">Pyodide Example</a>
754
754
  ![pyodide.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/pyodide.png)
755
755
 
756
756
  ## Troubleshooting ##
@@ -137,7 +137,7 @@ mg.render(locals(), 'immutable2.png')
137
137
 
138
138
 
139
139
  ### Mutable Type ###
140
- With mutable types the result is different. In the code below variable `a` and `b` both reference the same `list` value [4, 3, 2]. A `list` is a mutable type and therefore when we change variable `a` its value **can** be mutated in place and thus `a` and `b` both reference the same new value afterwards. Thus changing `a` also changes `b` and vice versa. Sometimes we want this but other times we don't and then we will have to make a copy so that `a` and `b` are independent.
140
+ With mutable types the result is different. In the code below variable `a` and `b` both reference the same `list` value [4, 3, 2]. A `list` is a mutable type and therefore when we change variable `a` its value **can** be mutated in place and thus `a` and `b` both reference the same new value afterwards. Thus changing `a` also changes `b` and vice versa. Sometimes we want this but other times we don't and then we will have to make a copy ourselfs so that `a` and `b` are independent.
141
141
 
142
142
  ```python
143
143
  import memory_graph as mg
@@ -245,7 +245,7 @@ This function:
245
245
  * then blocks execution until the &lt;Enter&gt; key is pressed
246
246
  * finally returns the value of the `fun()` call
247
247
 
248
- to change it's behavior:
248
+ to change its behavior:
249
249
  * Set `mg.block_prints_location = False` to skip printing the source location.
250
250
  * Set `mg.press_enter_message = None` to skip printing "Press &lt;Enter&gt; to continue...".
251
251
 
@@ -307,7 +307,7 @@ For the best debugging experience with memory_graph set for example expression:
307
307
  ```
308
308
  mg.render(locals(), "my_graph.pdf")
309
309
  ```
310
- as a *watch* in a debugger tool such as the integrated debugger in Visual Studio Code. Then open the "my_graph.pdf" output file to continuously see all the local variables while debugging. This avoids having to add any memory_graph `show()`, `render()` calls to your code.
310
+ as a *watch* in a debugger tool such as the integrated debugger in Visual Studio Code. Then open the "my_graph.pdf" output file to continuously see all the local variables while debugging. This avoids having to add any memory_graph `show()` or `render()` calls to your code.
311
311
 
312
312
  ### Call Stack in Watch Context ###
313
313
  The ```mg.get_call_stack()``` doesn't work well in *watch* context in most debuggers because debuggers introduce additional stack frames that cause problems. Use these alternative functions for various debuggers to filter out these problematic stack frames:
@@ -492,7 +492,7 @@ for i in range(n):
492
492
  Different aspects of memory_graph can be configured. The default configuration is reset by importing 'memory_graph.config_default'.
493
493
 
494
494
  - ***mg.config.max_graph_depth*** : int
495
- - The maxium depth of the graph with default value 12. A `✂` (scissor) symbol indicates where the graph is cut short.
495
+ - The maxium depth of the graph with default value 12. A `✂` (scissor) symbol indicates where the graph is cut short. Dashed references indicate that there are more references to a node than are shown.
496
496
 
497
497
  - ***mg.config.max_string_length*** : int
498
498
  - The maximum length of strings shown in the graph. Longer strings will be truncated.
@@ -516,7 +516,7 @@ Different aspects of memory_graph can be configured. The default configuration i
516
516
  - Maps each type to a Slicer. A slicer determines how many elements of a data type are shown in the graph to prevent the graph from getting too big. 'Slicer()' does no slicing, 'Slicer(1,2,3)' shows just 1 element at the beginning, 2 in the middle, and 3 at the end.
517
517
 
518
518
  ### Temporary Configuration ###
519
- In addition to the global configuration, a temporary configuration can be set for a single `show()`, `render()`, `d()`, `ds()` call to change the colors, orientation, and slicer. This example highlights a particular list element in red, gives it a horizontal orientation, and overwrites the default slicer for lists:
519
+ In addition to the global configuration, a temporary configuration can be set for a single `show()` or `render()` call to change the colors, orientation, and slicer. This example highlights a particular list element in red, gives it a horizontal orientation, and overwrites the default slicer for lists:
520
520
 
521
521
  ```python
522
522
  import memory_graph as mg
@@ -731,7 +731,7 @@ Then after starting 'ipython' call function `mg_switch()` to turn on/off the aut
731
731
  ![ipyton.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/ipython.png)
732
732
 
733
733
  ## In the Browser ##
734
- We can run memory_graph in the browser: <a href="https://bterwijn.github.io/memory_graph/src/pyodide.html" target="_blank">Pyodide Example</a>
734
+ We can also run memory_graph in the browser: <a href="https://bterwijn.github.io/memory_graph/src/pyodide.html" target="_blank">Pyodide Example</a>
735
735
  ![pyodide.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/pyodide.png)
736
736
 
737
737
  ## Troubleshooting ##
@@ -0,0 +1,9 @@
1
+
2
+ mg.block(fun, print_loc=True), update docs, stack-overflow posts
3
+
4
+ Jupyter Notebook inline render using display()
5
+
6
+ webassembly inline render
7
+
8
+ optional max introspect depth for each type/id
9
+ https://discuss.python.org/t/request-for-feedback-memory-graph-a-python-visualization-tool-for-education/78347
Binary file
@@ -0,0 +1,18 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+
7
+ def add_one(a, b, c):
8
+ a += [1]
9
+ b += (1,)
10
+ c += [1]
11
+ mg.render( mg.get_call_stack(), "add_one.png")
12
+
13
+ a = [4, 3, 2]
14
+ b = (4, 3, 2)
15
+ c = [4, 3, 2]
16
+
17
+ add_one(a, b, c.copy())
18
+ print(f"a:{a} b:{b} c:{c}")
@@ -0,0 +1,43 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+ import bintrees
7
+
8
+ # Create an AVL tree
9
+ tree = bintrees.AVLTree()
10
+ tree.insert(10, "ten")
11
+ tree.insert(5, "five")
12
+ tree.insert(20, "twenty")
13
+ tree.insert(15, "fifteen")
14
+
15
+ # mg.render(locals(), 'avltree_fail.png') # id keeps changing
16
+
17
+ mg.config.type_to_color[bintrees.avltree.Node] = "sandybrown"
18
+ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.node_linear.Node_Linear(data, dir(data))
19
+ mg.config.type_to_slicer[bintrees.avltree.Node] = mg.slicer.Slicer()
20
+ mg.render(locals(), 'avltree_dir.png')
21
+
22
+ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.node_base.Node_Base(f"key:{data.key} value:{data.value}")
23
+ mg.render(locals(), 'avltree_base.png')
24
+
25
+ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.node_linear.Node_Linear(data,
26
+ ['left:', data.left,
27
+ 'key:', data.key,
28
+ 'value:', data.value,
29
+ 'right:', data.right])
30
+ mg.render(locals(), 'avltree_linear.png')
31
+
32
+ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.node_key_value.Node_Key_Value(data,
33
+ {'left': data.left,
34
+ 'key': data.key,
35
+ 'value': data.value,
36
+ 'right': data.right}.items())
37
+ mg.render(locals(), 'avltree_key_value.png')
38
+
39
+ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.node_table.Node_Table(data,
40
+ [[data.key, data.value],
41
+ [data.left, data.right]]
42
+ )
43
+ mg.render(locals(), 'avltree_table.png')
Binary file
@@ -0,0 +1,47 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+ import random
7
+ random.seed(0) # use same random numbers each run
8
+
9
+ class Node:
10
+
11
+ def __init__(self, value):
12
+ self.smaller = None
13
+ self.value = value
14
+ self.larger = None
15
+
16
+ class BinTree:
17
+
18
+ def __init__(self):
19
+ self.root = None
20
+
21
+ def add_recursive(self, new_value, node):
22
+ if new_value < node.value:
23
+ if node.smaller is None:
24
+ node.smaller = Node(new_value)
25
+ else:
26
+ self.add_recursive(new_value, node.smaller)
27
+ else:
28
+ if node.larger is None:
29
+ node.larger = Node(new_value)
30
+ else:
31
+ self.add_recursive(new_value, node.larger)
32
+ if new_value == 51:
33
+ mg.render(locals(), f"bin_tree.png")
34
+ exit(0)
35
+
36
+ def add(self, value):
37
+ if self.root is None:
38
+ self.root = Node(value)
39
+ else:
40
+ self.add_recursive(value, self.root)
41
+
42
+ tree = BinTree()
43
+ n = 100
44
+ for i in range(n):
45
+ new_value = random.randrange(n)
46
+ tree.add(new_value)
47
+
Binary file
@@ -0,0 +1,15 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+ import copy
7
+
8
+ a = [ [1, 2], ['x', 'y'] ] # a nested list (a list containing lists)
9
+
10
+ # three different ways to make a "copy" of 'a':
11
+ c1 = a
12
+ c2 = copy.copy(a) # equivalent to: a.copy() a[:] list(a)
13
+ c3 = copy.deepcopy(a)
14
+
15
+ mg.render(locals(), 'copies.png')
@@ -0,0 +1,22 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+ import copy
7
+
8
+ class My_Class:
9
+
10
+ def __init__(self):
11
+ self.digits = [1, 2]
12
+ self.letters = ['x', 'y']
13
+
14
+ def copy(self): # custom copy method copies the digits but shares the letters
15
+ c = copy.copy(self)
16
+ c.digits = copy.copy(self.digits)
17
+ return c
18
+
19
+ a = My_Class()
20
+ b = a.copy()
21
+
22
+ mg.render(locals(), 'copy_method.png')
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+ #
3
+ # install:
4
+ #
5
+ # sudo apt install imagemagick
6
+
7
+ name="$1"
8
+ files=$(ls -v $name*.png)
9
+ echo "creating gif with:"
10
+ echo "$files"
11
+
12
+ largest_size=$(identify -format "%Wx%H %f\n" $name*.png | sort -nr | head -n1)
13
+ echo "largest_size: $largest_size"
14
+
15
+ echo "resizing images"
16
+ mogrify -resize $largest_size -background white -gravity center -extent $largest_size $files
17
+ echo "creating file: $name.gif"
18
+ convert -delay 150 -loop 0 $files $name.gif
19
+ echo "done"
@@ -0,0 +1,34 @@
1
+ # intro
2
+ python many_types.py
3
+
4
+ # debugging
5
+ python debugging.py
6
+ bash create_gif.sh debugging
7
+
8
+ # data model
9
+ python immutable.py
10
+ python mutable.py
11
+ python copies.py
12
+ python copy_method.py
13
+
14
+ # call stack
15
+ python add_one.py
16
+ python factorial.py
17
+ bash create_gif.sh factorial
18
+ python power_set.py
19
+ bash create_gif.sh power_set
20
+
21
+ # datastructures
22
+ python linked_list.py
23
+ python bin_tree.py
24
+ python hash_set.py
25
+
26
+ # configuration
27
+ python highlight.py
28
+
29
+ # extensions
30
+ python extension_numpy.py
31
+ python extension_pandas.py
32
+
33
+ # introspection
34
+ python avltree.py
Binary file
@@ -0,0 +1,19 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+
7
+ image=0
8
+ def get_fac_name():
9
+ global image
10
+ image+=1
11
+ return f"debugging{image:02d}.png"
12
+
13
+ squares = []
14
+ squares_collector = []
15
+ for i in range(1,6):
16
+ squares.append(i**2)
17
+ squares_collector.append(squares.copy())
18
+ mg.render(locals(), get_fac_name())
19
+ mg.render(locals(), get_fac_name())
@@ -0,0 +1,14 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+ import numpy as np
7
+ import memory_graph.extension_numpy
8
+ np.random.seed(0) # use same random numbers each run
9
+
10
+ array = np.array([1.1, 2, 3, 4, 5])
11
+ matrix = np.matrix([[i*20+j for j in range(20)] for i in range(20)])
12
+ ndarray = np.random.rand(20,20)
13
+
14
+ mg.render( locals(), "extension_numpy.png")
@@ -0,0 +1,17 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+ import pandas as pd
7
+ import memory_graph.extension_pandas
8
+
9
+ series = pd.Series( [i for i in range(20)] )
10
+ dataframe1 = pd.DataFrame({ "calories": [420, 380, 390],
11
+ "duration": [50, 40, 45] })
12
+ dataframe2 = pd.DataFrame({ 'Name' : [ 'Tom', 'Anna', 'Steve', 'Lisa'],
13
+ 'Age' : [ 28, 34, 29, 42],
14
+ 'Length' : [ 1.70, 1.66, 1.82, 1.73] },
15
+ index=['one', 'two', 'three', 'four']) # with row names
16
+
17
+ mg.render( locals(), "extension_pandas.png")
Binary file
@@ -0,0 +1,24 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+
7
+ image=0
8
+ def get_fac_name():
9
+ global image
10
+ image+=1
11
+ return f"factorial{image:02d}.png"
12
+
13
+ def factorial(n):
14
+ if n==0:
15
+ return 1
16
+ #mg.show( mg.get_call_stack(), block=True ) # draw graph
17
+ mg.render( mg.get_call_stack(), get_fac_name())
18
+ result = n*factorial(n-1)
19
+ #mg.show( mg.get_call_stack(), block=True ) # draw graph
20
+ mg.render( mg.get_call_stack(), get_fac_name())
21
+ return result
22
+
23
+ mg.render( mg.get_call_stack(), get_fac_name())
24
+ factorial(3)
Binary file
@@ -0,0 +1,39 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+ import random
7
+ random.seed(0) # use same random numbers each run
8
+
9
+ class HashSet:
10
+
11
+ def __init__(self, capacity=15):
12
+ self.buckets = [None] * capacity
13
+
14
+ def add(self, value):
15
+ index = hash(value) % len(self.buckets)
16
+ if self.buckets[index] is None:
17
+ self.buckets[index] = []
18
+ bucket = self.buckets[index]
19
+ bucket.append(value)
20
+ if value == 36:
21
+ mg.render(locals(), "hash_set.png")
22
+ exit()
23
+
24
+ def contains(self, value):
25
+ index = hash(value) % len(self.buckets)
26
+ if self.buckets[index] is None:
27
+ return False
28
+ return value in self.buckets[index]
29
+
30
+ def remove(self, value):
31
+ index = hash(value) % len(self.buckets)
32
+ if self.buckets[index] is not None:
33
+ self.buckets[index].remove(value)
34
+
35
+ hash_set = HashSet()
36
+ n = 100
37
+ for i in range(n):
38
+ new_value = random.randrange(n)
39
+ hash_set.add(new_value)
Binary file
@@ -0,0 +1,15 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+ from memory_graph.slicer import Slicer
7
+
8
+ data = [ list(range(20)) for i in range(1,5)]
9
+ highlight = data[2]
10
+
11
+ mg.render( locals(), "highlight.png",
12
+ colors = {id(highlight): "red" }, # set color to "red"
13
+ vertical_orientations = {id(highlight): False }, # set horizontal orientation
14
+ slicers = {id(highlight): Slicer()} # set no slicing
15
+ )
@@ -0,0 +1,11 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+
7
+ a = (4, 3, 2)
8
+ b = a
9
+ mg.render(locals(), 'immutable1.png')
10
+ a += (1,)
11
+ mg.render(locals(), 'immutable2.png')
Binary file
@@ -0,0 +1,85 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "23f6d43f-dd17-4020-971e-5bb8a5b1e30b",
6
+ "metadata": {},
7
+ "source": [
8
+ "# test: locals_jupyter()\n",
9
+ "Show a graph build with the filtered Jupyter locals using function `mg.locals_jupyter()`. Just adding integers to a list:"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": null,
15
+ "id": "e8913787-bbef-4adb-b027-ac0f28500233",
16
+ "metadata": {},
17
+ "outputs": [],
18
+ "source": [
19
+ "import memory_graph as mg\n",
20
+ "\n",
21
+ "data = []\n",
22
+ "for i in range(5):\n",
23
+ " data.append(i)\n",
24
+ " display(mg.create_graph(mg.locals_jupyter())) # display in jupyter notebook\n",
25
+ " mg.block(mg.show, mg.locals_jupyter()) # display in PDF reader\n",
26
+ " "
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "markdown",
31
+ "id": "f66d9b8d-0937-4ad0-97b4-a7459e84c4f2",
32
+ "metadata": {},
33
+ "source": [
34
+ "# test: get_call_stack_jupyter()\n",
35
+ "Show a graph build the filterd Jupyter call stack from function `mg.get_call_stack_jupyter()`. Recursively filling a list with all permutation of elements with resampling:"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": null,
41
+ "id": "15d0c443-7cc6-4b4f-a9db-598aaf261364",
42
+ "metadata": {},
43
+ "outputs": [],
44
+ "source": [
45
+ "import memory_graph as mg\n",
46
+ "\n",
47
+ "def get_all_permutations(permutations, elements, data, max_length):\n",
48
+ " if len(data) == max_length: # recursive stop condition\n",
49
+ " permutations.append(data.copy())\n",
50
+ " else:\n",
51
+ " for i in elements:\n",
52
+ " data.append(i)\n",
53
+ " mg.block(mg.show, mg.get_call_stack_jupyter())\n",
54
+ " get_all_permutations(permutations, elements, data, max_length)\n",
55
+ " data.pop()\n",
56
+ " mg.block(mg.show, mg.get_call_stack_jupyter())\n",
57
+ "\n",
58
+ "permutations = []\n",
59
+ "get_all_permutations(permutations, ['L','R'], [], 3)\n",
60
+ "print(permutations)"
61
+ ]
62
+ }
63
+ ],
64
+ "metadata": {
65
+ "kernelspec": {
66
+ "display_name": "Python 3 (ipykernel)",
67
+ "language": "python",
68
+ "name": "python3"
69
+ },
70
+ "language_info": {
71
+ "codemirror_mode": {
72
+ "name": "ipython",
73
+ "version": 3
74
+ },
75
+ "file_extension": ".py",
76
+ "mimetype": "text/x-python",
77
+ "name": "python",
78
+ "nbconvert_exporter": "python",
79
+ "pygments_lexer": "ipython3",
80
+ "version": "3.12.3"
81
+ }
82
+ },
83
+ "nbformat": 4,
84
+ "nbformat_minor": 5
85
+ }