Skip to content

Commit fb89fb1

Browse files
authored
Merge branch 'master' into feat/hopcroft-karp-matching
2 parents c4e2faa + ae68a78 commit fb89fb1

23 files changed

+347
-54
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- run:
13-
sudo apt-get update && sudo apt-get install -y libtiff5-dev libjpeg8-dev libopenjp2-7-dev
14-
zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk
15-
libharfbuzz-dev libfribidi-dev libxcb1-dev
16-
libxml2-dev libxslt-dev
17-
libhdf5-dev
18-
libopenblas-dev
12+
- run: sudo apt-get update && sudo apt-get install -y libhdf5-dev
1913
- uses: actions/checkout@v5
20-
- uses: astral-sh/setup-uv@v6
14+
- uses: astral-sh/setup-uv@v7
2115
with:
2216
enable-cache: true
2317
cache-dependency-glob: uv.lock
@@ -28,10 +22,12 @@ jobs:
2822
- run: uv sync --group=test
2923
- name: Run tests
3024
# TODO: #8818 Re-enable quantum tests
31-
run: uv run pytest
25+
run: uv run --with=pytest-run-parallel pytest
26+
--iterations=8 --parallel-threads=auto
3227
--ignore=computer_vision/cnn_classification.py
3328
--ignore=docs/conf.py
3429
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
30+
--ignore=machine_learning/local_weighted_learning/local_weighted_learning.py
3531
--ignore=machine_learning/lstm/lstm_prediction.py
3632
--ignore=neural_network/input_data.py
3733
--ignore=project_euler/

.github/workflows/project_euler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
libhdf5-dev
2323
libopenblas-dev
2424
- uses: actions/checkout@v5
25-
- uses: astral-sh/setup-uv@v6
25+
- uses: astral-sh/setup-uv@v7
2626
- uses: actions/setup-python@v6
2727
with:
2828
python-version: 3.14
@@ -40,7 +40,7 @@ jobs:
4040
libhdf5-dev
4141
libopenblas-dev
4242
- uses: actions/checkout@v5
43-
- uses: astral-sh/setup-uv@v6
43+
- uses: astral-sh/setup-uv@v7
4444
- uses: actions/setup-python@v6
4545
with:
4646
python-version: 3.14

.github/workflows/ruff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v5
15-
- uses: astral-sh/setup-uv@v6
15+
- uses: astral-sh/setup-uv@v7
1616
- run: uvx ruff check --output-format=github .

.github/workflows/sphinx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
libhdf5-dev
3434
libopenblas-dev
3535
- uses: actions/checkout@v5
36-
- uses: astral-sh/setup-uv@v6
36+
- uses: astral-sh/setup-uv@v7
3737
- uses: actions/setup-python@v6
3838
with:
3939
python-version: 3.14

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
- id: auto-walrus
2020

2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.13.3
22+
rev: v0.14.3
2323
hooks:
2424
- id: ruff-check
2525
- id: ruff-format
@@ -32,7 +32,7 @@ repos:
3232
- tomli
3333

3434
- repo: https://github.com/tox-dev/pyproject-fmt
35-
rev: v2.7.0
35+
rev: v2.11.0
3636
hooks:
3737
- id: pyproject-fmt
3838

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ We want your work to be readable by others; therefore, we encourage you to note
9999
ruff check
100100
```
101101

102-
- Original code submission require docstrings or comments to describe your work.
102+
- Original code submissions require docstrings or comments to describe your work.
103103

104104
- More on docstrings and comments:
105105

DIRECTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
* [Permutations](data_structures/arrays/permutations.py)
196196
* [Prefix Sum](data_structures/arrays/prefix_sum.py)
197197
* [Product Sum](data_structures/arrays/product_sum.py)
198+
* [Rotate Array](data_structures/arrays/rotate_array.py)
198199
* [Sparse Table](data_structures/arrays/sparse_table.py)
199200
* [Sudoku Solver](data_structures/arrays/sudoku_solver.py)
200201
* Binary Tree
@@ -623,6 +624,7 @@
623624
* [Sequential Minimum Optimization](machine_learning/sequential_minimum_optimization.py)
624625
* [Similarity Search](machine_learning/similarity_search.py)
625626
* [Support Vector Machines](machine_learning/support_vector_machines.py)
627+
* [T Stochastic Neighbour Embedding](machine_learning/t_stochastic_neighbour_embedding.py)
626628
* [Word Frequency Functions](machine_learning/word_frequency_functions.py)
627629
* [Xgboost Classifier](machine_learning/xgboost_classifier.py)
628630
* [Xgboost Regressor](machine_learning/xgboost_regressor.py)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
def rotate_array(arr: list[int], steps: int) -> list[int]:
2+
"""
3+
Rotates a list to the right by steps positions.
4+
5+
Parameters:
6+
arr (List[int]): The list of integers to rotate.
7+
steps (int): Number of positions to rotate. Can be negative for left rotation.
8+
9+
Returns:
10+
List[int]: Rotated list.
11+
12+
Examples:
13+
>>> rotate_array([1, 2, 3, 4, 5], 2)
14+
[4, 5, 1, 2, 3]
15+
>>> rotate_array([1, 2, 3, 4, 5], -2)
16+
[3, 4, 5, 1, 2]
17+
>>> rotate_array([1, 2, 3, 4, 5], 7)
18+
[4, 5, 1, 2, 3]
19+
>>> rotate_array([], 3)
20+
[]
21+
"""
22+
23+
n = len(arr)
24+
if n == 0:
25+
return arr
26+
27+
steps = steps % n
28+
29+
if steps < 0:
30+
steps += n
31+
32+
def reverse(start: int, end: int) -> None:
33+
"""
34+
Reverses a portion of the list in place from index start to end.
35+
36+
Parameters:
37+
start (int): Starting index of the portion to reverse.
38+
end (int): Ending index of the portion to reverse.
39+
40+
Returns:
41+
None
42+
43+
Examples:
44+
>>> example = [1, 2, 3, 4, 5]
45+
>>> def reverse_test(arr, start, end):
46+
... while start < end:
47+
... arr[start], arr[end] = arr[end], arr[start]
48+
... start += 1
49+
... end -= 1
50+
>>> reverse_test(example, 0, 2)
51+
>>> example
52+
[3, 2, 1, 4, 5]
53+
>>> reverse_test(example, 2, 4)
54+
>>> example
55+
[3, 2, 5, 4, 1]
56+
"""
57+
58+
while start < end:
59+
arr[start], arr[end] = arr[end], arr[start]
60+
start += 1
61+
end -= 1
62+
63+
reverse(0, n - 1)
64+
reverse(0, steps - 1)
65+
reverse(steps, n - 1)
66+
67+
return arr
68+
69+
70+
if __name__ == "__main__":
71+
examples = [
72+
([1, 2, 3, 4, 5], 2),
73+
([1, 2, 3, 4, 5], -2),
74+
([1, 2, 3, 4, 5], 7),
75+
([], 3),
76+
]
77+
78+
for arr, steps in examples:
79+
rotated = rotate_array(arr.copy(), steps)
80+
print(f"Rotate {arr} by {steps}: {rotated}")

data_structures/queues/circular_queue.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __len__(self) -> int:
1717
>>> len(cq)
1818
0
1919
>>> cq.enqueue("A") # doctest: +ELLIPSIS
20-
<data_structures.queues.circular_queue.CircularQueue object at ...
20+
<data_structures.queues.circular_queue.CircularQueue object at ...>
2121
>>> cq.array
2222
['A', None, None, None, None]
2323
>>> len(cq)
@@ -51,17 +51,24 @@ def enqueue(self, data):
5151
"""
5252
This function inserts an element at the end of the queue using self.rear value
5353
as an index.
54+
5455
>>> cq = CircularQueue(5)
5556
>>> cq.enqueue("A") # doctest: +ELLIPSIS
56-
<data_structures.queues.circular_queue.CircularQueue object at ...
57+
<data_structures.queues.circular_queue.CircularQueue object at ...>
5758
>>> (cq.size, cq.first())
5859
(1, 'A')
5960
>>> cq.enqueue("B") # doctest: +ELLIPSIS
60-
<data_structures.queues.circular_queue.CircularQueue object at ...
61+
<data_structures.queues.circular_queue.CircularQueue object at ...>
6162
>>> cq.array
6263
['A', 'B', None, None, None]
6364
>>> (cq.size, cq.first())
6465
(2, 'A')
66+
>>> cq.enqueue("C").enqueue("D").enqueue("E") # doctest: +ELLIPSIS
67+
<data_structures.queues.circular_queue.CircularQueue object at ...>
68+
>>> cq.enqueue("F")
69+
Traceback (most recent call last):
70+
...
71+
Exception: QUEUE IS FULL
6572
"""
6673
if self.size >= self.n:
6774
raise Exception("QUEUE IS FULL")
@@ -75,6 +82,7 @@ def dequeue(self):
7582
"""
7683
This function removes an element from the queue using on self.front value as an
7784
index and returns it
85+
7886
>>> cq = CircularQueue(5)
7987
>>> cq.dequeue()
8088
Traceback (most recent call last):

graphs/graph_adjacency_list.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ def add_vertex(self, vertex: T) -> None:
6161
"""
6262
Adds a vertex to the graph. If the given vertex already exists,
6363
a ValueError will be thrown.
64+
65+
>>> g = GraphAdjacencyList(vertices=[], edges=[], directed=False)
66+
>>> g.add_vertex("A")
67+
>>> g.adj_list
68+
{'A': []}
69+
>>> g.add_vertex("A")
70+
Traceback (most recent call last):
71+
...
72+
ValueError: Incorrect input: A is already in the graph.
6473
"""
6574
if self.contains_vertex(vertex):
6675
msg = f"Incorrect input: {vertex} is already in the graph."

0 commit comments

Comments
 (0)